From 89c5e49ba2fd6ea5ef30b766d1c0af36f72bfef0 Mon Sep 17 00:00:00 2001 From: Yumin Qi Date: Thu, 24 Sep 2020 15:28:10 +0000 Subject: [PATCH 01/79] 8253500: [REDO] JDK-8253208 Move CDS related code to a separate class Reviewed-by: mchung, iklam --- make/hotspot/symbols/symbols-unix | 6 +- src/hotspot/share/include/jvm.h | 6 +- src/hotspot/share/prims/jvm.cpp | 14 ++--- .../share/classes/java/lang/Byte.java | 4 +- .../share/classes/java/lang/Character.java | 4 +- .../share/classes/java/lang/Integer.java | 3 +- .../share/classes/java/lang/Long.java | 4 +- .../share/classes/java/lang/Module.java | 3 +- .../share/classes/java/lang/Short.java | 4 +- .../lang/invoke/LambdaProxyClassArchive.java | 6 +- .../java/lang/module/Configuration.java | 4 +- .../java/util/ImmutableCollections.java | 6 +- .../classes/java/util/jar/Attributes.java | 4 +- .../internal/loader/ArchivedClassLoaders.java | 4 +- .../jdk/internal/math/FDBigInteger.java | 6 +- .../share/classes/jdk/internal/misc/VM.java | 25 --------- .../internal/module/ArchivedBootLayer.java | 4 +- .../internal/module/ArchivedModuleGraph.java | 4 +- .../jdk/internal/module/ModuleBootstrap.java | 4 +- .../classes/sun/util/locale/BaseLocale.java | 4 +- src/java.base/share/native/libjava/CDS.c | 55 +++++++++++++++++++ src/java.base/share/native/libjava/VM.c | 28 ---------- 22 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 src/java.base/share/native/libjava/CDS.c diff --git a/make/hotspot/symbols/symbols-unix b/make/hotspot/symbols/symbols-unix index de444eae41c91..97aa40b970be8 100644 --- a/make/hotspot/symbols/symbols-unix +++ b/make/hotspot/symbols/symbols-unix @@ -123,7 +123,7 @@ JVM_GetPermittedSubclasses JVM_GetPrimitiveArrayElement JVM_GetProperties JVM_GetProtectionDomain -JVM_GetRandomSeedForCDSDump +JVM_GetRandomSeedForDumping JVM_GetRecordComponents JVM_GetSimpleBinaryName JVM_GetStackAccessControlContext @@ -143,8 +143,8 @@ JVM_InternString JVM_Interrupt JVM_InvokeMethod JVM_IsArrayClass -JVM_IsCDSDumpingEnabled -JVM_IsCDSSharingEnabled +JVM_IsDynamicDumpingEnabled +JVM_IsSharingEnabled JVM_IsConstructorIx JVM_IsHiddenClass JVM_IsInterface diff --git a/src/hotspot/share/include/jvm.h b/src/hotspot/share/include/jvm.h index 15b064dcb7db8..fb9dfba430136 100644 --- a/src/hotspot/share/include/jvm.h +++ b/src/hotspot/share/include/jvm.h @@ -198,13 +198,13 @@ JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env, jclass caller, jboolean initialize); JNIEXPORT jboolean JNICALL -JVM_IsCDSDumpingEnabled(JNIEnv* env); +JVM_IsDynamicDumpingEnabled(JNIEnv* env); JNIEXPORT jboolean JNICALL -JVM_IsCDSSharingEnabled(JNIEnv* env); +JVM_IsSharingEnabled(JNIEnv* env); JNIEXPORT jlong JNICALL -JVM_GetRandomSeedForCDSDump(); +JVM_GetRandomSeedForDumping(); /* * java.lang.Throwable diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index e6313ba37f2c6..2ff1c5e8a799e 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -3833,18 +3833,18 @@ JVM_ENTRY(jclass, JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env, #endif // INCLUDE_CDS JVM_END -JVM_ENTRY(jboolean, JVM_IsCDSDumpingEnabled(JNIEnv* env)) - JVMWrapper("JVM_IsCDSDumpingEnable"); +JVM_ENTRY(jboolean, JVM_IsDynamicDumpingEnabled(JNIEnv* env)) + JVMWrapper("JVM_IsDynamicDumpingEnable"); return DynamicDumpSharedSpaces; JVM_END -JVM_ENTRY(jboolean, JVM_IsCDSSharingEnabled(JNIEnv* env)) - JVMWrapper("JVM_IsCDSSharingEnable"); +JVM_ENTRY(jboolean, JVM_IsSharingEnabled(JNIEnv* env)) + JVMWrapper("JVM_IsSharingEnable"); return UseSharedSpaces; JVM_END -JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForCDSDump()) - JVMWrapper("JVM_GetRandomSeedForCDSDump"); +JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForDumping()) + JVMWrapper("JVM_GetRandomSeedForDumping"); if (DumpSharedSpaces) { const char* release = Abstract_VM_Version::vm_release(); const char* dbg_level = Abstract_VM_Version::jdk_debug_level(); @@ -3859,7 +3859,7 @@ JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForCDSDump()) if (seed == 0) { // don't let this ever be zero. seed = 0x87654321; } - log_debug(cds)("JVM_GetRandomSeedForCDSDump() = " JLONG_FORMAT, seed); + log_debug(cds)("JVM_GetRandomSeedForDumping() = " JLONG_FORMAT, seed); return seed; } else { return 0; diff --git a/src/java.base/share/classes/java/lang/Byte.java b/src/java.base/share/classes/java/lang/Byte.java index e71eba7b2d558..4aeb73bbe8afc 100644 --- a/src/java.base/share/classes/java/lang/Byte.java +++ b/src/java.base/share/classes/java/lang/Byte.java @@ -26,7 +26,7 @@ package java.lang; import jdk.internal.HotSpotIntrinsicCandidate; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import java.lang.constant.Constable; import java.lang.constant.DynamicConstantDesc; @@ -108,7 +108,7 @@ private ByteCache() {} final int size = -(-128) + 127 + 1; // Load and use the archived cache if it exists - VM.initializeFromArchive(ByteCache.class); + CDS.initializeFromArchive(ByteCache.class); if (archivedCache == null || archivedCache.length != size) { Byte[] c = new Byte[size]; byte value = (byte)-128; diff --git a/src/java.base/share/classes/java/lang/Character.java b/src/java.base/share/classes/java/lang/Character.java index dd69413f1b8f1..d50d7fdb11875 100644 --- a/src/java.base/share/classes/java/lang/Character.java +++ b/src/java.base/share/classes/java/lang/Character.java @@ -26,7 +26,7 @@ package java.lang; import jdk.internal.HotSpotIntrinsicCandidate; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import java.lang.constant.Constable; import java.lang.constant.DynamicConstantDesc; @@ -8516,7 +8516,7 @@ private CharacterCache(){} int size = 127 + 1; // Load and use the archived cache if it exists - VM.initializeFromArchive(CharacterCache.class); + CDS.initializeFromArchive(CharacterCache.class); if (archivedCache == null || archivedCache.length != size) { Character[] c = new Character[size]; for (int i = 0; i < size; i++) { diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java index cf67cc42d741c..735d194fbde68 100644 --- a/src/java.base/share/classes/java/lang/Integer.java +++ b/src/java.base/share/classes/java/lang/Integer.java @@ -33,6 +33,7 @@ import java.util.Optional; import jdk.internal.HotSpotIntrinsicCandidate; +import jdk.internal.misc.CDS; import jdk.internal.misc.VM; import static java.lang.String.COMPACT_STRINGS; @@ -1023,7 +1024,7 @@ private static class IntegerCache { high = h; // Load IntegerCache.archivedCache from archive, if possible - VM.initializeFromArchive(IntegerCache.class); + CDS.initializeFromArchive(IntegerCache.class); int size = (high - low) + 1; // Use the archived cache if it exists and is large enough diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java index 953f352a873c3..808a87b1c470b 100644 --- a/src/java.base/share/classes/java/lang/Long.java +++ b/src/java.base/share/classes/java/lang/Long.java @@ -34,7 +34,7 @@ import java.util.Optional; import jdk.internal.HotSpotIntrinsicCandidate; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import static java.lang.String.COMPACT_STRINGS; import static java.lang.String.LATIN1; @@ -1169,7 +1169,7 @@ private LongCache() {} int size = -(-128) + 127 + 1; // Load and use the archived cache if it exists - VM.initializeFromArchive(LongCache.class); + CDS.initializeFromArchive(LongCache.class); if (archivedCache == null || archivedCache.length != size) { Long[] c = new Long[size]; long value = -128; diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index 3d5734f7a91cd..7d0a0d088884c 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -55,6 +55,7 @@ import jdk.internal.loader.BuiltinClassLoader; import jdk.internal.loader.BootLoader; import jdk.internal.loader.ClassLoaders; +import jdk.internal.misc.CDS; import jdk.internal.misc.VM; import jdk.internal.module.IllegalAccessLogger; import jdk.internal.module.ModuleLoaderMap; @@ -277,7 +278,7 @@ static ArchivedData get() { } static { - VM.initializeFromArchive(ArchivedData.class); + CDS.initializeFromArchive(ArchivedData.class); } } diff --git a/src/java.base/share/classes/java/lang/Short.java b/src/java.base/share/classes/java/lang/Short.java index 53ca694291d17..c0651847466ec 100644 --- a/src/java.base/share/classes/java/lang/Short.java +++ b/src/java.base/share/classes/java/lang/Short.java @@ -26,7 +26,7 @@ package java.lang; import jdk.internal.HotSpotIntrinsicCandidate; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import java.lang.constant.Constable; import java.lang.constant.DynamicConstantDesc; @@ -234,7 +234,7 @@ private ShortCache() {} int size = -(-128) + 127 + 1; // Load and use the archived cache if it exists - VM.initializeFromArchive(ShortCache.class); + CDS.initializeFromArchive(ShortCache.class); if (archivedCache == null || archivedCache.length != size) { Short[] c = new Short[size]; short value = -128; diff --git a/src/java.base/share/classes/java/lang/invoke/LambdaProxyClassArchive.java b/src/java.base/share/classes/java/lang/invoke/LambdaProxyClassArchive.java index bad015a5624d8..9ad06751108cc 100644 --- a/src/java.base/share/classes/java/lang/invoke/LambdaProxyClassArchive.java +++ b/src/java.base/share/classes/java/lang/invoke/LambdaProxyClassArchive.java @@ -26,15 +26,15 @@ package java.lang.invoke; import jdk.internal.loader.BuiltinClassLoader; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; final class LambdaProxyClassArchive { private static final boolean dumpArchive; private static final boolean sharingEnabled; static { - dumpArchive = VM.isCDSDumpingEnabled(); - sharingEnabled = VM.isCDSSharingEnabled(); + dumpArchive = CDS.isDynamicDumpingEnabled(); + sharingEnabled = CDS.isSharingEnabled(); } /** diff --git a/src/java.base/share/classes/java/lang/module/Configuration.java b/src/java.base/share/classes/java/lang/module/Configuration.java index 9a9cb533eeed6..e1b1f39cc327b 100644 --- a/src/java.base/share/classes/java/lang/module/Configuration.java +++ b/src/java.base/share/classes/java/lang/module/Configuration.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.module.ModuleReferenceImpl; import jdk.internal.module.ModuleTarget; import jdk.internal.vm.annotation.Stable; @@ -110,7 +110,7 @@ public final class Configuration { static { // Initialize EMPTY_CONFIGURATION from the archive. - VM.initializeFromArchive(Configuration.class); + CDS.initializeFromArchive(Configuration.class); // Create a new empty Configuration if there is no archived version. if (EMPTY_CONFIGURATION == null) { EMPTY_CONFIGURATION = new Configuration(); diff --git a/src/java.base/share/classes/java/util/ImmutableCollections.java b/src/java.base/share/classes/java/util/ImmutableCollections.java index ccf92e2f42106..716986b0efdd6 100644 --- a/src/java.base/share/classes/java/util/ImmutableCollections.java +++ b/src/java.base/share/classes/java/util/ImmutableCollections.java @@ -37,7 +37,7 @@ import java.util.function.Predicate; import java.util.function.UnaryOperator; import jdk.internal.access.SharedSecrets; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.vm.annotation.Stable; /** @@ -76,7 +76,7 @@ class ImmutableCollections { // derived from the JVM build/version, so can we generate the exact same // CDS archive for the same JDK build. This makes it possible to verify the // consistency of the JDK build. - long seed = VM.getRandomSeedForCDSDump(); + long seed = CDS.getRandomSeedForDumping(); if (seed == 0) { seed = System.nanoTime(); } @@ -100,7 +100,7 @@ class ImmutableCollections { static final MapN EMPTY_MAP; static { - VM.initializeFromArchive(ImmutableCollections.class); + CDS.initializeFromArchive(ImmutableCollections.class); if (archivedObjects == null) { EMPTY = new Object(); EMPTY_LIST = new ListN<>(); diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 79cb2fe1c47b9..d2cd77d5a3b33 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -34,7 +34,7 @@ import java.util.Objects; import java.util.Set; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.vm.annotation.Stable; import sun.nio.cs.UTF_8; @@ -672,7 +672,7 @@ private static void addName(Map names, Name name) { static { - VM.initializeFromArchive(Attributes.Name.class); + CDS.initializeFromArchive(Attributes.Name.class); if (KNOWN_NAMES == null) { MANIFEST_VERSION = new Name("Manifest-Version"); diff --git a/src/java.base/share/classes/jdk/internal/loader/ArchivedClassLoaders.java b/src/java.base/share/classes/jdk/internal/loader/ArchivedClassLoaders.java index 48cd4e2e6dc43..7113b521f4db7 100644 --- a/src/java.base/share/classes/jdk/internal/loader/ArchivedClassLoaders.java +++ b/src/java.base/share/classes/jdk/internal/loader/ArchivedClassLoaders.java @@ -25,7 +25,7 @@ package jdk.internal.loader; import java.util.Map; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.module.ServicesCatalog; /** @@ -91,6 +91,6 @@ static ArchivedClassLoaders get() { } static { - VM.initializeFromArchive(ArchivedClassLoaders.class); + CDS.initializeFromArchive(ArchivedClassLoaders.class); } } diff --git a/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java b/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java index b522d3121a0f7..f6d868dfcc281 100644 --- a/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java +++ b/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2020, 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 @@ -24,7 +24,7 @@ */ package jdk.internal.math; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import java.math.BigInteger; import java.util.Arrays; @@ -84,7 +84,7 @@ // Initialize FDBigInteger cache of powers of 5. static { - VM.initializeFromArchive(FDBigInteger.class); + CDS.initializeFromArchive(FDBigInteger.class); Object[] caches = archivedCaches; if (caches == null) { long[] long5pow = { diff --git a/src/java.base/share/classes/jdk/internal/misc/VM.java b/src/java.base/share/classes/jdk/internal/misc/VM.java index 5681a79558f8f..f0b32c30f6e0f 100644 --- a/src/java.base/share/classes/jdk/internal/misc/VM.java +++ b/src/java.base/share/classes/jdk/internal/misc/VM.java @@ -457,31 +457,6 @@ public static boolean isSetUID() { } private static native void initialize(); - /** - * Initialize archived static fields in the given Class using archived - * values from CDS dump time. Also initialize the classes of objects in - * the archived graph referenced by those fields. - * - * Those static fields remain as uninitialized if there is no mapped CDS - * java heap data or there is any error during initialization of the - * object class in the archived graph. - */ - public static native void initializeFromArchive(Class c); - - public static native void defineArchivedModules(ClassLoader platformLoader, ClassLoader systemLoader); - - public static native long getRandomSeedForCDSDump(); - - /** - * Check if CDS dynamic dumping is enabled via the DynamicDumpSharedSpaces flag. - */ - public static native boolean isCDSDumpingEnabled(); - - /** - * Check if CDS sharing is enabled by via the UseSharedSpaces flag. - */ - public static native boolean isCDSSharingEnabled(); - /** * Provides access to information on buffer usage. */ diff --git a/src/java.base/share/classes/jdk/internal/module/ArchivedBootLayer.java b/src/java.base/share/classes/jdk/internal/module/ArchivedBootLayer.java index 90bd5eaa51e8c..decf27e8cb7ce 100644 --- a/src/java.base/share/classes/jdk/internal/module/ArchivedBootLayer.java +++ b/src/java.base/share/classes/jdk/internal/module/ArchivedBootLayer.java @@ -24,7 +24,7 @@ */ package jdk.internal.module; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; /** * Used by ModuleBootstrap for archiving the boot layer and the builder needed to @@ -59,6 +59,6 @@ static void archive(ModuleLayer layer, IllegalAccessLogger.Builder builder) { } static { - VM.initializeFromArchive(ArchivedBootLayer.class); + CDS.initializeFromArchive(ArchivedBootLayer.class); } } diff --git a/src/java.base/share/classes/jdk/internal/module/ArchivedModuleGraph.java b/src/java.base/share/classes/jdk/internal/module/ArchivedModuleGraph.java index 6b038238eb1f8..4d9f5eb7f62f5 100644 --- a/src/java.base/share/classes/jdk/internal/module/ArchivedModuleGraph.java +++ b/src/java.base/share/classes/jdk/internal/module/ArchivedModuleGraph.java @@ -29,7 +29,7 @@ import java.util.function.Function; import java.lang.module.Configuration; import java.lang.module.ModuleFinder; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; /** * Used by ModuleBootstrap for archiving the configuration for the boot layer, @@ -123,6 +123,6 @@ static void archive(boolean hasSplitPackages, } static { - VM.initializeFromArchive(ArchivedModuleGraph.class); + CDS.initializeFromArchive(ArchivedModuleGraph.class); } } diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java index bc872c44917e2..9d999a80e9bcd 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java @@ -54,7 +54,7 @@ import jdk.internal.loader.BootLoader; import jdk.internal.loader.BuiltinClassLoader; import jdk.internal.loader.ClassLoaders; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.perf.PerfCounter; /** @@ -167,7 +167,7 @@ public static ModuleLayer boot() { assert canUseArchivedBootLayer(); bootLayer = archivedBootLayer.bootLayer(); BootLoader.getUnnamedModule(); // trigger of BootLoader. - VM.defineArchivedModules(ClassLoaders.platformClassLoader(), ClassLoaders.appClassLoader()); + CDS.defineArchivedModules(ClassLoaders.platformClassLoader(), ClassLoaders.appClassLoader()); // assume boot layer has at least one module providing a service // that is mapped to the application class loader. diff --git a/src/java.base/share/classes/sun/util/locale/BaseLocale.java b/src/java.base/share/classes/sun/util/locale/BaseLocale.java index 27ad70001a13c..b520771f20a86 100644 --- a/src/java.base/share/classes/sun/util/locale/BaseLocale.java +++ b/src/java.base/share/classes/sun/util/locale/BaseLocale.java @@ -32,7 +32,7 @@ package sun.util.locale; -import jdk.internal.misc.VM; +import jdk.internal.misc.CDS; import jdk.internal.vm.annotation.Stable; import java.lang.ref.SoftReference; @@ -62,7 +62,7 @@ public final class BaseLocale { ROOT = 18, NUM_CONSTANTS = 19; static { - VM.initializeFromArchive(BaseLocale.class); + CDS.initializeFromArchive(BaseLocale.class); BaseLocale[] baseLocales = constantBaseLocales; if (baseLocales == null) { baseLocales = new BaseLocale[NUM_CONSTANTS]; diff --git a/src/java.base/share/native/libjava/CDS.c b/src/java.base/share/native/libjava/CDS.c new file mode 100644 index 0000000000000..9cad87ead443d --- /dev/null +++ b/src/java.base/share/native/libjava/CDS.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "jvm.h" +#include "jdk_internal_misc_CDS.h" + +JNIEXPORT void JNICALL +Java_jdk_internal_misc_CDS_initializeFromArchive(JNIEnv *env, jclass ignore, + jclass c) { + JVM_InitializeFromArchive(env, c); +} + +JNIEXPORT void JNICALL +Java_jdk_internal_misc_CDS_defineArchivedModules(JNIEnv *env, jclass ignore, + jobject platform_loader, + jobject system_loader) { + JVM_DefineArchivedModules(env, platform_loader, system_loader); +} + +JNIEXPORT jlong JNICALL +Java_jdk_internal_misc_CDS_getRandomSeedForDumping(JNIEnv *env, jclass ignore) { + return JVM_GetRandomSeedForDumping(); +} + +JNIEXPORT jboolean JNICALL +Java_jdk_internal_misc_CDS_isDynamicDumpingEnabled(JNIEnv *env, jclass jcls) { + return JVM_IsDynamicDumpingEnabled(env); +} + +JNIEXPORT jboolean JNICALL +Java_jdk_internal_misc_CDS_isSharingEnabled(JNIEnv *env, jclass jcls) { + return JVM_IsSharingEnabled(env); +} diff --git a/src/java.base/share/native/libjava/VM.c b/src/java.base/share/native/libjava/VM.c index ffc7e68001443..099ad46fff15d 100644 --- a/src/java.base/share/native/libjava/VM.c +++ b/src/java.base/share/native/libjava/VM.c @@ -55,31 +55,3 @@ JNIEXPORT jobjectArray JNICALL Java_jdk_internal_misc_VM_getRuntimeArguments(JNIEnv *env, jclass cls) { return JVM_GetVmArguments(env); } - -JNIEXPORT void JNICALL -Java_jdk_internal_misc_VM_initializeFromArchive(JNIEnv *env, jclass ignore, - jclass c) { - JVM_InitializeFromArchive(env, c); -} - -JNIEXPORT void JNICALL -Java_jdk_internal_misc_VM_defineArchivedModules(JNIEnv *env, jclass ignore, - jobject platform_loader, - jobject system_loader) { - JVM_DefineArchivedModules(env, platform_loader, system_loader); -} - -JNIEXPORT jlong JNICALL -Java_jdk_internal_misc_VM_getRandomSeedForCDSDump(JNIEnv *env, jclass ignore) { - return JVM_GetRandomSeedForCDSDump(); -} - -JNIEXPORT jboolean JNICALL -Java_jdk_internal_misc_VM_isCDSDumpingEnabled(JNIEnv *env, jclass jcls) { - return JVM_IsCDSDumpingEnabled(env); -} - -JNIEXPORT jboolean JNICALL -Java_jdk_internal_misc_VM_isCDSSharingEnabled(JNIEnv *env, jclass jcls) { - return JVM_IsCDSSharingEnabled(env); -} From a9d04408b3417a3da4d571d65bd804f89170f70f Mon Sep 17 00:00:00 2001 From: Conor Cleary Date: Thu, 24 Sep 2020 16:06:37 +0000 Subject: [PATCH 02/79] 8250859: Address reliance on default constructors in the Accessibility APIs Reviewed-by: prr --- .../classes/javax/accessibility/AccessibleContext.java | 7 ++++++- .../classes/javax/accessibility/AccessibleHyperlink.java | 7 ++++++- .../javax/accessibility/AccessibleResourceBundle.java | 7 ++++++- .../com/sun/java/accessibility/util/AWTEventMonitor.java | 7 ++++++- .../java/accessibility/util/AccessibilityEventMonitor.java | 7 ++++++- .../java/accessibility/util/AccessibilityListenerList.java | 7 ++++++- .../classes/com/sun/java/accessibility/util/EventID.java | 7 ++++++- .../com/sun/java/accessibility/util/SwingEventMonitor.java | 6 +++++- 8 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java b/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java index 9c0d4b50c1584..cff4dd05d2661 100644 --- a/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java +++ b/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -79,6 +79,11 @@ @JavaBean(description = "Minimal information that all accessible objects return") public abstract class AccessibleContext { + /** + * Constructor for subclasses to call. + */ + protected AccessibleContext() {} + /** * The {@code AppContext} that should be used to dispatch events for this * {@code AccessibleContext}. diff --git a/src/java.desktop/share/classes/javax/accessibility/AccessibleHyperlink.java b/src/java.desktop/share/classes/javax/accessibility/AccessibleHyperlink.java index 2df088b13d466..0d6cf2532c12b 100644 --- a/src/java.desktop/share/classes/javax/accessibility/AccessibleHyperlink.java +++ b/src/java.desktop/share/classes/javax/accessibility/AccessibleHyperlink.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,6 +38,11 @@ */ public abstract class AccessibleHyperlink implements AccessibleAction { + /** + * Constructor for subclasses to call. + */ + protected AccessibleHyperlink() {} + /** * Since the document a link is associated with may have changed, this * method returns whether or not this Link is still valid (with respect to diff --git a/src/java.desktop/share/classes/javax/accessibility/AccessibleResourceBundle.java b/src/java.desktop/share/classes/javax/accessibility/AccessibleResourceBundle.java index 80a78967dd320..3da4a46f465e3 100644 --- a/src/java.desktop/share/classes/javax/accessibility/AccessibleResourceBundle.java +++ b/src/java.desktop/share/classes/javax/accessibility/AccessibleResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,6 +38,11 @@ @Deprecated public class AccessibleResourceBundle extends ListResourceBundle { + /** + * Constructs an {@code AccessibleResourceBundle}. + */ + public AccessibleResourceBundle() {} + /** * Returns the mapping between the programmatic keys and the localized * display strings. diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java index 28f2a97b6db81..5dc686f31dffb 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AWTEventMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -45,6 +45,11 @@ public class AWTEventMonitor { + /** + * Constructs an {@code AWTEventMonitor}. + */ + public AWTEventMonitor() {} + /** * The current component with keyboard focus. * diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityEventMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityEventMonitor.java index 78375e72b5c6c..e9a90e9e45c7a 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityEventMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityEventMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -45,6 +45,11 @@ public class AccessibilityEventMonitor { + /** + * Constructs an {@code AccessibilityEventMonitor}. + */ + public AccessibilityEventMonitor() {} + // listeners /** * The current list of registered {@link java.beans.PropertyChangeListener diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityListenerList.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityListenerList.java index 0de59f9524468..62133dc6773a5 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityListenerList.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/AccessibilityListenerList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, 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 @@ -46,6 +46,11 @@ public class AccessibilityListenerList { */ protected transient Object[] listenerList = NULL_ARRAY; + /** + * Constructs an {@code AccessibilityListenerList}. + */ + public AccessibilityListenerList() {} + /** * Passes back the event listener list as an array of listener type, listener pairs. * Note that for performance reasons, this implementation passes back the actual diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventID.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventID.java index f984034b49f62..4fbf8ee508ae8 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventID.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/EventID.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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,6 +37,11 @@ */ public class EventID { + /** + * Constructs an {@code EventID}. + */ + public EventID() {} + /** * Maps to AWT Action support (i.e., ActionListener and ActionEvent) */ diff --git a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java index c5dcda4df3ed1..f8493eec53475 100644 --- a/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java +++ b/src/jdk.accessibility/share/classes/com/sun/java/accessibility/util/SwingEventMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -58,6 +58,10 @@ */ public class SwingEventMonitor extends AWTEventMonitor { + /** + * Constructs a {@code SwingEventMonitor}. + */ + /** * The master list of all listeners registered by other classes. * This can only be publicly modified by calling the add or From 3495c19d1a8e134ef0e28a0fdd38e877da7cdaea Mon Sep 17 00:00:00 2001 From: Conor Cleary Date: Thu, 24 Sep 2020 16:07:24 +0000 Subject: [PATCH 03/79] 8250855: Address reliance on default constructors in the Java 2D APIs Reviewed-by: prr, serb --- src/java.desktop/share/classes/java/awt/Image.java | 7 ++++++- src/java.desktop/share/classes/java/awt/PrintJob.java | 7 ++++++- .../share/classes/java/awt/font/GlyphVector.java | 7 ++++++- .../share/classes/java/awt/font/LayoutPath.java | 8 +++++++- .../share/classes/java/awt/font/LineMetrics.java | 6 +++++- .../java/awt/image/AbstractMultiResolutionImage.java | 7 ++++++- .../share/classes/java/awt/image/BufferStrategy.java | 7 ++++++- .../share/classes/java/awt/image/ImageFilter.java | 8 +++++++- .../share/classes/java/awt/image/RGBImageFilter.java | 7 ++++++- .../share/classes/java/awt/image/VolatileImage.java | 7 ++++++- .../share/classes/javax/print/PrintServiceLookup.java | 7 ++++++- src/java.desktop/share/classes/javax/print/ServiceUI.java | 7 ++++++- .../share/classes/javax/print/ServiceUIFactory.java | 7 ++++++- .../share/classes/javax/print/event/PrintJobAdapter.java | 7 ++++++- 14 files changed, 85 insertions(+), 14 deletions(-) diff --git a/src/java.desktop/share/classes/java/awt/Image.java b/src/java.desktop/share/classes/java/awt/Image.java index b2ab082aa2cb8..7e6273232694a 100644 --- a/src/java.desktop/share/classes/java/awt/Image.java +++ b/src/java.desktop/share/classes/java/awt/Image.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -45,6 +45,11 @@ */ public abstract class Image { + /** + * Constructor for subclasses to call. + */ + protected Image() {} + /** * convenience object; we can use this single static object for * all images that do not create their own image caps; it holds the diff --git a/src/java.desktop/share/classes/java/awt/PrintJob.java b/src/java.desktop/share/classes/java/awt/PrintJob.java index 9012608584fdf..a9e2bd8bea29a 100644 --- a/src/java.desktop/share/classes/java/awt/PrintJob.java +++ b/src/java.desktop/share/classes/java/awt/PrintJob.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,11 @@ */ public abstract class PrintJob { + /** + * Constructor for subclasses to call. + */ + protected PrintJob() {} + /** * Gets a Graphics object that will draw to the next page. * The page is sent to the printer when the graphics diff --git a/src/java.desktop/share/classes/java/awt/font/GlyphVector.java b/src/java.desktop/share/classes/java/awt/font/GlyphVector.java index c507766cee70d..1db1168ed1e75 100644 --- a/src/java.desktop/share/classes/java/awt/font/GlyphVector.java +++ b/src/java.desktop/share/classes/java/awt/font/GlyphVector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, 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 @@ -108,6 +108,11 @@ public abstract class GlyphVector implements Cloneable { + /** + * Constructor for subclasses to call. + */ + protected GlyphVector() {} + // // methods associated with creation-time state // diff --git a/src/java.desktop/share/classes/java/awt/font/LayoutPath.java b/src/java.desktop/share/classes/java/awt/font/LayoutPath.java index 60bc6f2896a43..820dcce24acbf 100644 --- a/src/java.desktop/share/classes/java/awt/font/LayoutPath.java +++ b/src/java.desktop/share/classes/java/awt/font/LayoutPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2020, 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 @@ -41,6 +41,12 @@ * @since 1.6 */ public abstract class LayoutPath { + + /** + * Constructor for subclasses to call. + */ + protected LayoutPath() {} + /** * Convert a point in user space to a location relative to the * path. The location is chosen so as to minimize the distance diff --git a/src/java.desktop/share/classes/java/awt/font/LineMetrics.java b/src/java.desktop/share/classes/java/awt/font/LineMetrics.java index f56655914009b..0002699148af8 100644 --- a/src/java.desktop/share/classes/java/awt/font/LineMetrics.java +++ b/src/java.desktop/share/classes/java/awt/font/LineMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,6 +43,10 @@ public abstract class LineMetrics { + /** + * Constructor for subclasses to call. + */ + protected LineMetrics() {} /** * Returns the number of characters ({@code char} values) in the text whose diff --git a/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java b/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java index aa105ccea75c7..15f3ef61b0fd5 100644 --- a/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java +++ b/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, 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 @@ -65,6 +65,11 @@ public abstract class AbstractMultiResolutionImage extends java.awt.Image implements MultiResolutionImage { + /** + * Constructor for subclasses to call. + */ + protected AbstractMultiResolutionImage() {} + /** * This method simply delegates to the same method on the base image and * it is equivalent to: {@code getBaseImage().getWidth(observer)}. diff --git a/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java b/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java index 587e19e0102e9..1403bc046366d 100644 --- a/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java +++ b/src/java.desktop/share/classes/java/awt/image/BufferStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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 @@ -134,6 +134,11 @@ */ public abstract class BufferStrategy { + /** + * Constructor for subclasses to call. + */ + protected BufferStrategy() {} + /** * Returns the {@code BufferCapabilities} for this * {@code BufferStrategy}. diff --git a/src/java.desktop/share/classes/java/awt/image/ImageFilter.java b/src/java.desktop/share/classes/java/awt/image/ImageFilter.java index b1f87e75d16ee..d136e16fc6b8c 100644 --- a/src/java.desktop/share/classes/java/awt/image/ImageFilter.java +++ b/src/java.desktop/share/classes/java/awt/image/ImageFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,6 +43,12 @@ * @author Jim Graham */ public class ImageFilter implements ImageConsumer, Cloneable { + + /** + * Constructs an {@code ImageFilter}. + */ + public ImageFilter() {} + /** * The consumer of the particular image data stream for which this * instance of the ImageFilter is filtering data. It is not diff --git a/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java b/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java index a368a36d21799..44302923d1779 100644 --- a/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java +++ b/src/java.desktop/share/classes/java/awt/image/RGBImageFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -66,6 +66,11 @@ */ public abstract class RGBImageFilter extends ImageFilter { + /** + * Constructor for subclasses to call. + */ + protected RGBImageFilter() {} + /** * The {@code ColorModel} to be replaced by * {@code newmodel} when the user calls diff --git a/src/java.desktop/share/classes/java/awt/image/VolatileImage.java b/src/java.desktop/share/classes/java/awt/image/VolatileImage.java index f88c5d00bd692..0d838c8ff256c 100644 --- a/src/java.desktop/share/classes/java/awt/image/VolatileImage.java +++ b/src/java.desktop/share/classes/java/awt/image/VolatileImage.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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 @@ -133,6 +133,11 @@ public abstract class VolatileImage extends Image implements Transparency { + /** + * Constructor for subclasses to call. + */ + protected VolatileImage() {} + // Return codes for validate() method /** diff --git a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java index 52b3fd507fe04..90d80622b1da5 100644 --- a/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java +++ b/src/java.desktop/share/classes/javax/print/PrintServiceLookup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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 @@ -65,6 +65,11 @@ */ public abstract class PrintServiceLookup { + /** + * Constructor for subclasses to call. + */ + protected PrintServiceLookup() {} + /** * Contains a lists of services. */ diff --git a/src/java.desktop/share/classes/javax/print/ServiceUI.java b/src/java.desktop/share/classes/javax/print/ServiceUI.java index 3990ba6c942b5..873d4448ffcaa 100644 --- a/src/java.desktop/share/classes/javax/print/ServiceUI.java +++ b/src/java.desktop/share/classes/javax/print/ServiceUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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 @@ -65,6 +65,11 @@ */ public class ServiceUI { + /** + * Constructs a {@code ServiceUI}. + */ + public ServiceUI() {} + /** * Presents a dialog to the user for selecting a print service (printer). It * is displayed at the location specified by the application and is modal. diff --git a/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java b/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java index 918cf0155ff3b..87d81017322be 100644 --- a/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java +++ b/src/java.desktop/share/classes/javax/print/ServiceUIFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, 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 @@ -56,6 +56,11 @@ */ public abstract class ServiceUIFactory { + /** + * Constructor for subclasses to call. + */ + protected ServiceUIFactory() {} + /** * Denotes a UI implemented as a Swing component. The value of the string is * the fully qualified classname : "javax.swing.JComponent". diff --git a/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java b/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java index 989f275b3832b..f063fb7a8e06e 100644 --- a/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java +++ b/src/java.desktop/share/classes/javax/print/event/PrintJobAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,11 @@ */ public abstract class PrintJobAdapter implements PrintJobListener { + /** + * Constructor for subclasses to call. + */ + protected PrintJobAdapter() {} + /** * Called to notify the client that data has been successfully transferred * to the print service, and the client may free local resources allocated From 527a30930e86531c53ba82483e9098a690b132ed Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Thu, 24 Sep 2020 16:19:20 +0000 Subject: [PATCH 04/79] 8252722: More Swing plaf APIs that rely on default constructors Reviewed-by: prr --- .../javax/swing/plaf/basic/BasicBorders.java | 10 ++++ .../javax/swing/plaf/basic/BasicButtonUI.java | 5 ++ .../plaf/basic/BasicCheckBoxMenuItemUI.java | 5 ++ .../swing/plaf/basic/BasicCheckBoxUI.java | 5 ++ .../swing/plaf/basic/BasicColorChooserUI.java | 10 ++++ .../swing/plaf/basic/BasicComboBoxEditor.java | 4 ++ .../plaf/basic/BasicComboBoxRenderer.java | 4 ++ .../swing/plaf/basic/BasicComboBoxUI.java | 35 ++++++++++++ .../swing/plaf/basic/BasicComboPopup.java | 39 +++++++++++++ .../swing/plaf/basic/BasicDesktopIconUI.java | 5 ++ .../swing/plaf/basic/BasicDesktopPaneUI.java | 20 +++++++ .../swing/plaf/basic/BasicFileChooserUI.java | 16 ++++++ .../plaf/basic/BasicFormattedTextFieldUI.java | 5 ++ .../swing/plaf/basic/BasicGraphicsUtils.java | 5 ++ .../javax/swing/plaf/basic/BasicHTML.java | 5 ++ .../swing/plaf/basic/BasicIconFactory.java | 5 ++ .../basic/BasicInternalFrameTitlePane.java | 14 +++++ .../plaf/basic/BasicInternalFrameUI.java | 29 ++++++++++ .../swing/plaf/basic/BasicMenuItemUI.java | 5 ++ .../javax/swing/plaf/basic/BasicMenuUI.java | 5 ++ .../swing/plaf/basic/BasicScrollBarUI.java | 15 +++++ .../swing/plaf/basic/BasicScrollPaneUI.java | 5 ++ .../plaf/basic/BasicSplitPaneDivider.java | 10 ++++ .../swing/plaf/basic/BasicSplitPaneUI.java | 15 +++++ .../swing/plaf/basic/BasicTabbedPaneUI.java | 29 ++++++++++ .../swing/plaf/basic/BasicTableHeaderUI.java | 10 ++++ .../javax/swing/plaf/basic/BasicTableUI.java | 20 +++++++ .../javax/swing/plaf/basic/BasicTextUI.java | 14 ++++- .../swing/plaf/basic/BasicToggleButtonUI.java | 5 ++ .../plaf/basic/BasicToolBarSeparatorUI.java | 5 ++ .../swing/plaf/basic/BasicToolBarUI.java | 25 +++++++++ .../javax/swing/plaf/basic/BasicTreeUI.java | 55 +++++++++++++++++++ .../swing/plaf/basic/BasicViewportUI.java | 5 ++ .../swing/plaf/metal/MetalFileChooserUI.java | 4 ++ .../javax/swing/plaf/metal/MetalSliderUI.java | 5 ++ .../swing/plaf/metal/MetalToolBarUI.java | 19 ++++++- 36 files changed, 468 insertions(+), 4 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java index 949c3e35f4a29..4bb0bf9e0d1af 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicBorders.java @@ -47,6 +47,11 @@ public class BasicBorders { + /** + * Constructs a {@code BasicBorders}. + */ + public BasicBorders() {} + /** * Returns a border instance for a {@code JButton}. * @@ -473,6 +478,11 @@ public Insets getBorderInsets(Component c, Insets insets) { */ @SuppressWarnings("serial") // Superclass is not serializable across versions public static class MarginBorder extends AbstractBorder implements UIResource { + /** + * Constructs a {@code MarginBorder}. + */ + public MarginBorder() {} + public Insets getBorderInsets(Component c, Insets insets) { Insets margin = null; // diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java index 9347298350d1b..4d73309869f10 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonUI.java @@ -76,6 +76,11 @@ public class BasicButtonUI extends ButtonUI{ // ******************************** // Create PLAF // ******************************** + /** + * Constructs a {@code BasicButtonUI}. + */ + public BasicButtonUI() {} + /** * Returns an instance of {@code BasicButtonUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java index aa816d431b063..ccf7d2f5d3466 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java @@ -39,6 +39,11 @@ */ public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI { + /** + * Constructs a {@code BasicCheckBoxMenuItemUI}. + */ + public BasicCheckBoxMenuItemUI() {} + /** * Constructs a new instance of {@code BasicCheckBoxMenuItemUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxUI.java index 11b94fddab526..a1bd07282c1ef 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicCheckBoxUI.java @@ -60,6 +60,11 @@ public class BasicCheckBoxUI extends BasicRadioButtonUI { // Create PLAF // ******************************** + /** + * Constructs a {@code BasicCheckBoxUI}. + */ + public BasicCheckBoxUI() {} + /** * Returns an instance of {@code BasicCheckBoxUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicColorChooserUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicColorChooserUI.java index 7ad582a079285..2259281dd8cfd 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicColorChooserUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicColorChooserUI.java @@ -77,6 +77,11 @@ public class BasicColorChooserUI extends ColorChooserUI protected PropertyChangeListener propertyChangeListener; private Handler handler; + /** + * Constructs a {@code BasicColorChooserUI}. + */ + public BasicColorChooserUI() {} + /** * Returns a new instance of {@code BasicColorChooserUI}. * @@ -383,6 +388,11 @@ else if (prop == "componentOrientation") { * Instantiate it only within subclasses of {@code BasicColorChooserUI}. */ public class PropertyHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyHandler}. + */ + public PropertyHandler() {} + public void propertyChange(PropertyChangeEvent e) { getHandler().propertyChange(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java index 157c1dde4f758..0e5eab8285b91 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java @@ -176,5 +176,9 @@ public void setBorder(Border b) { @SuppressWarnings("serial") // Same-version serialization only public static class UIResource extends BasicComboBoxEditor implements javax.swing.plaf.UIResource { + /** + * Constructs a {@code UIResource}. + */ + public UIResource() {} } } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxRenderer.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxRenderer.java index 23899e72bc4b6..7b47386946c5c 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxRenderer.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxRenderer.java @@ -145,5 +145,9 @@ public Component getListCellRendererComponent(JList list, */ @SuppressWarnings("serial") // Same-version serialization only public static class UIResource extends BasicComboBoxRenderer implements javax.swing.plaf.UIResource { + /** + * Constructs a {@code UIResource}. + */ + public UIResource() {} } } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java index 4041f9793cbef..ff3a1596fbdaf 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java @@ -232,6 +232,11 @@ public class BasicComboBoxUI extends ComboBoxUI { */ protected Insets padding; + /** + * Constructs a {@code BasicComboBoxUI}. + */ + public BasicComboBoxUI() {} + // Used for calculating the default size. private static ListCellRenderer getDefaultListCellRenderer() { @SuppressWarnings("unchecked") @@ -592,6 +597,11 @@ private Handler getHandler() { * BasicComboBoxUI. */ public class KeyHandler extends KeyAdapter { + /** + * Constructs a {@code KeyHandler}. + */ + public KeyHandler() {} + @Override public void keyPressed( KeyEvent e ) { getHandler().keyPressed(e); @@ -607,6 +617,11 @@ public void keyPressed( KeyEvent e ) { * BasicComboBoxUI. */ public class FocusHandler implements FocusListener { + /** + * Constructs a {@code FocusHandler}. + */ + public FocusHandler() {} + public void focusGained( FocusEvent e ) { getHandler().focusGained(e); } @@ -627,6 +642,11 @@ public void focusLost( FocusEvent e ) { * @see #createListDataListener */ public class ListDataHandler implements ListDataListener { + /** + * Constructs a {@code ListDataHandler}. + */ + public ListDataHandler() {} + public void contentsChanged( ListDataEvent e ) { getHandler().contentsChanged(e); } @@ -651,6 +671,11 @@ public void intervalRemoved( ListDataEvent e ) { * @see #createItemListener */ public class ItemHandler implements ItemListener { + /** + * Constructs a {@code ItemHandler}. + */ + public ItemHandler() {} + // This class used to implement behavior which is now redundant. public void itemStateChanged(ItemEvent e) {} } @@ -670,6 +695,11 @@ public void itemStateChanged(ItemEvent e) {} * @see #createPropertyChangeListener */ public class PropertyChangeHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyChangeHandler}. + */ + public PropertyChangeHandler() {} + public void propertyChange(PropertyChangeEvent e) { getHandler().propertyChange(e); } @@ -697,6 +727,11 @@ private void updateToolTipTextForChildren() { * BasicComboBoxUI. */ public class ComboBoxLayoutManager implements LayoutManager { + /** + * Constructs a {@code ComboBoxLayoutManager}. + */ + public ComboBoxLayoutManager() {} + public void addLayoutComponent(String name, Component comp) {} public void removeLayoutComponent(Component comp) {} diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java index ef779a7642e2c..050f27e72b4d4 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java @@ -733,6 +733,11 @@ public void actionPerformed(ActionEvent e){ * @see BasicComboPopup#createMouseListener */ protected class InvocationMouseHandler extends MouseAdapter { + /** + * Constructs an {@code InvocationMouseHandler}. + */ + protected InvocationMouseHandler() {} + /** * Responds to mouse-pressed events on the combo box. * @@ -758,6 +763,11 @@ public void mouseReleased( MouseEvent e ) { * list if it is dragging over the list. */ protected class InvocationMouseMotionHandler extends MouseMotionAdapter { + /** + * Constructs an {@code InvocationMouseMotionHandler}. + */ + protected InvocationMouseMotionHandler() {} + public void mouseDragged( MouseEvent e ) { getHandler().mouseDragged(e); } @@ -771,6 +781,10 @@ public void mouseDragged( MouseEvent e ) { * BasicComboBoxUI ActionMap/InputMap methods. */ public class InvocationKeyHandler extends KeyAdapter { + /** + * Constructs an {@code InvocationKeyHandler}. + */ + public InvocationKeyHandler() {} public void keyReleased( KeyEvent e ) {} } @@ -780,6 +794,10 @@ public void keyReleased( KeyEvent e ) {} * override. */ protected class ListSelectionHandler implements ListSelectionListener { + /** + * Constructs a {@code ListSelectionHandler}. + */ + protected ListSelectionHandler() {} public void valueChanged( ListSelectionEvent e ) {} } @@ -793,6 +811,10 @@ public void valueChanged( ListSelectionEvent e ) {} * @see #createItemListener */ public class ListDataHandler implements ListDataListener { + /** + * Constructs a {@code ListDataHandler}. + */ + public ListDataHandler() {} public void contentsChanged( ListDataEvent e ) {} public void intervalAdded( ListDataEvent e ) { @@ -806,6 +828,10 @@ public void intervalRemoved( ListDataEvent e ) { * This listener hides the popup when the mouse is released in the list. */ protected class ListMouseHandler extends MouseAdapter { + /** + * Constructs a {@code ListMouseHandler}. + */ + protected ListMouseHandler() {} public void mousePressed( MouseEvent e ) { } public void mouseReleased(MouseEvent anEvent) { @@ -818,6 +844,11 @@ public void mouseReleased(MouseEvent anEvent) { * The selection change is not committed to the model, this is for user feedback only. */ protected class ListMouseMotionHandler extends MouseMotionAdapter { + /** + * Constructs a {@code ListMouseMotionHandler}. + */ + protected ListMouseMotionHandler() {} + public void mouseMoved( MouseEvent anEvent ) { getHandler().mouseMoved(anEvent); } @@ -828,6 +859,10 @@ public void mouseMoved( MouseEvent anEvent ) { * combo box. */ protected class ItemHandler implements ItemListener { + /** + * Constructs an {@code ItemHandler}. + */ + protected ItemHandler() {} public void itemStateChanged( ItemEvent e ) { getHandler().itemStateChanged(e); } @@ -844,6 +879,10 @@ public void itemStateChanged( ItemEvent e ) { * @see #createPropertyChangeListener */ protected class PropertyChangeHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyChangeHandler}. + */ + protected PropertyChangeHandler() {} public void propertyChange( PropertyChangeEvent e ) { getHandler().propertyChange(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java index 262f36ee7d8d8..681ec227ccc01 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java @@ -243,6 +243,11 @@ public class MouseInputHandler extends MouseInputAdapter int __x, __y; Rectangle startingBounds; + /** + * Constructs a {@code MouseInputHandler}. + */ + public MouseInputHandler() {} + public void mouseReleased(MouseEvent e) { _x = 0; _y = 0; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java index e784d2d4b2ae5..894e2b07d1a39 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java @@ -678,6 +678,10 @@ public boolean accept(Object sender) { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class OpenAction extends AbstractAction { + /** + * Constructs an {@code OpenAction}. + */ + protected OpenAction() {} public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.RESTORE); @@ -693,6 +697,10 @@ public boolean isEnabled() { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class CloseAction extends AbstractAction { + /** + * Constructs a {@code CloseAction}. + */ + protected CloseAction() {} public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.CLOSE); @@ -712,6 +720,10 @@ public boolean isEnabled() { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class MinimizeAction extends AbstractAction { + /** + * Constructs a {@code MinimizeAction}. + */ + protected MinimizeAction() {} public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.MINIMIZE); @@ -731,6 +743,10 @@ public boolean isEnabled() { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class MaximizeAction extends AbstractAction { + /** + * Constructs a {@code MaximizeAction}. + */ + protected MaximizeAction() {} public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); SHARED_ACTION.setState(dp, Actions.MAXIMIZE); @@ -750,6 +766,10 @@ public boolean isEnabled() { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class NavigateAction extends AbstractAction { + /** + * Constructs a {@code NavigateAction}. + */ + protected NavigateAction() {} public void actionPerformed(ActionEvent evt) { JDesktopPane dp = (JDesktopPane)evt.getSource(); dp.selectFrame(true); diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java index 8ed05e0786167..18f94db30406c 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -757,6 +757,12 @@ protected class SelectionListener implements ListSelectionListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + + /** + * Constructs a {@code SelectionListener}. + */ + protected SelectionListener() {} + /** {@inheritDoc} */ public void valueChanged(ListSelectionEvent e) { getHandler().valueChanged(e); @@ -1325,6 +1331,11 @@ public String getDescription() { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class CancelSelectionAction extends AbstractAction { + /** + * Constructs a {@code CancelSelectionAction}. + */ + protected CancelSelectionAction() {} + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { getFileChooser().cancelSelection(); @@ -1336,6 +1347,11 @@ public void actionPerformed(ActionEvent e) { */ @SuppressWarnings("serial") // Superclass is not serializable across versions protected class UpdateAction extends AbstractAction { + /** + * Constructs an {@code UpdateAction}. + */ + protected UpdateAction() {} + /** {@inheritDoc} */ public void actionPerformed(ActionEvent e) { JFileChooser fc = getFileChooser(); diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java index 690a700169281..35560bf558cad 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java @@ -34,6 +34,11 @@ * @since 1.4 */ public class BasicFormattedTextFieldUI extends BasicTextFieldUI { + /** + * Constructs a {@code BasicFormattedTextFieldUI}. + */ + public BasicFormattedTextFieldUI() {} + /** * Creates a UI for a JFormattedTextField. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java index 26c4b6f73fe4e..e7febd97f09c6 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java @@ -51,6 +51,11 @@ public class BasicGraphicsUtils private static final Insets GROOVE_INSETS = new Insets(2, 2, 2, 2); private static final Insets ETCHED_INSETS = new Insets(2, 2, 2, 2); + /** + * Constructs a {@code BasicGraphicsUtils}. + */ + public BasicGraphicsUtils() {} + /** * Draws an etched rectangle. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java index 85304d92e34ef..3e1108fb25bd2 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java @@ -46,6 +46,11 @@ */ public class BasicHTML { + /** + * Constructs a {@code BasicHTML}. + */ + public BasicHTML() {} + /** * Create an html renderer for the given component and * string of html. diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicIconFactory.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicIconFactory.java index b8c0465b3290a..8b38a29e1ed87 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicIconFactory.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicIconFactory.java @@ -61,6 +61,11 @@ public class BasicIconFactory implements Serializable private static Icon menuItemArrowIcon; private static Icon menuArrowIcon; + /** + * Constructs a {@code BasicIconFactory}. + */ + public BasicIconFactory() {} + /** * Returns a menu item check icon. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java index 72b2d8be53684..1a21268d74c00 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -723,6 +723,11 @@ public void layoutContainer(Container c) { * Instantiate it only within subclasses of Foo. */ public class PropertyChangeHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyChangeHandler}. + */ + public PropertyChangeHandler() {} + // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this @@ -741,6 +746,11 @@ public class TitlePaneLayout implements LayoutManager { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code TitlePaneLayout}. + */ + public TitlePaneLayout() {} + public void addLayoutComponent(String name, Component c) { getHandler().addLayoutComponent(name, c); } @@ -930,6 +940,10 @@ public void actionPerformed(ActionEvent e) { */ @SuppressWarnings("deprecation") public class SystemMenuBar extends JMenuBar { + /** + * Constructs a {@code SystemMenuBar}. + */ + public SystemMenuBar() {} public boolean isFocusTraversable() { return false; } public void requestFocus() {} public void paint(Graphics g) { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java index 86d6686e41a03..603dd896fde66 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -646,6 +646,10 @@ public class InternalFramePropertyChangeListener implements // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs an {@code InternalFramePropertyChangeListener}. + */ + public InternalFramePropertyChangeListener() {} /** * Detects changes in state from the JInternalFrame and handles * actions. @@ -663,6 +667,11 @@ public class InternalFrameLayout implements LayoutManager { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs an {@code InternalFrameLayout}. + */ + public InternalFrameLayout() {} + /** * {@inheritDoc} */ @@ -842,6 +851,11 @@ protected class BorderListener extends MouseInputAdapter implements SwingConstan int resizeCornerSize = 16; + /** + * Constructs a {@code BorderListener}. + */ + protected BorderListener() {} + public void mouseClicked(MouseEvent e) { if(e.getClickCount() > 1 && e.getSource() == getNorthPane()) { if(frame.isIconifiable() && frame.isIcon()) { @@ -1305,6 +1319,11 @@ protected class ComponentHandler implements ComponentListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code ComponentHandler}. + */ + protected ComponentHandler() {} + /** Invoked when a JInternalFrame's parent's size changes. */ public void componentResized(ComponentEvent e) { getHandler().componentResized(e); @@ -1347,6 +1366,11 @@ protected class GlassPaneDispatcher implements MouseInputListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code GlassPaneDispatcher}. + */ + protected GlassPaneDispatcher() {} + /** * {@inheritDoc} */ @@ -1414,6 +1438,11 @@ protected class BasicInternalFrameListener implements InternalFrameListener // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code BasicInternalFrameListener}. + */ + protected BasicInternalFrameListener() {} + /** * {@inheritDoc} */ diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java index 3d036358e6d4e..be0487d38933f 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -928,6 +928,11 @@ protected class MouseInputHandler implements MouseInputListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code MouseInputHandler}. + */ + protected MouseInputHandler() {} + /** {@inheritDoc} */ public void mouseClicked(MouseEvent e) { getHandler().mouseClicked(e); diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java index ba60b557d82ac..33699871a18c8 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java @@ -370,6 +370,11 @@ protected class MouseInputHandler implements MouseInputListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code MouseInputHandler}. + */ + protected MouseInputHandler() {} + public void mouseClicked(MouseEvent e) { getHandler().mouseClicked(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java index b63274d483624..afb2d58b88519 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -1176,6 +1176,11 @@ public boolean getSupportsAbsolutePositioning() { * A listener to listen for model changes. */ protected class ModelListener implements ChangeListener { + /** + * Constructs a {@code ModelListener}. + */ + protected ModelListener() {} + public void stateChanged(ChangeEvent e) { if (!useCachedValue) { scrollBarValue = scrollbar.getValue(); @@ -1200,6 +1205,11 @@ protected class TrackListener protected transient int currentMouseY; private transient int direction = +1; + /** + * Constructs a {@code TrackListener}. + */ + protected TrackListener() {} + /** {@inheritDoc} */ public void mouseReleased(MouseEvent e) { @@ -1498,6 +1508,11 @@ protected class ArrowButtonListener extends MouseAdapter // (keyfocus on scrollbars causes action without mousePress boolean handledEvent; + /** + * Constructs an {@code ArrowButtonListener}. + */ + protected ArrowButtonListener() {} + public void mousePressed(MouseEvent e) { if(!scrollbar.isEnabled()) { return; } // not an unmodified left mouse button diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java index 7f80f4e51faf5..f99afb35282df 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollPaneUI.java @@ -623,6 +623,11 @@ protected class MouseWheelHandler implements MouseWheelListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code MouseWheelHandler}. + */ + protected MouseWheelHandler() {} + /** * Called when the mouse wheel is rotated while over a * JScrollPane. diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java index b8054b750fd58..c5ce2a64f9cf0 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java @@ -552,6 +552,11 @@ protected void finishDraggingTo(int location) { protected class MouseHandler extends MouseAdapter implements MouseMotionListener { + /** + * Constructs a {@code MouseHandler}. + */ + protected MouseHandler() {} + /** * Starts the dragging session by creating the appropriate instance * of DragController. @@ -955,6 +960,11 @@ protected int positionForMouseEvent(MouseEvent e) { */ protected class DividerLayout implements LayoutManager { + /** + * Constructs a {@code DividerLayout}. + */ + protected DividerLayout() {} + public void layoutContainer(Container c) { if (leftButton != null && rightButton != null && c == BasicSplitPaneDivider.this) { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java index 643c5419f742d..24b2fa873f1c9 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java @@ -714,6 +714,11 @@ int getKeyboardMoveIncrement() { */ public class PropertyHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyHandler}. + */ + public PropertyHandler() {} + // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this @@ -766,6 +771,11 @@ public void focusLost(FocusEvent ev) { */ public class KeyboardUpLeftHandler implements ActionListener { + /** + * Constructs a {@code KeyboardUpLeftHandler}. + */ + public KeyboardUpLeftHandler() {} + public void actionPerformed(ActionEvent ev) { if (dividerKeyboardResize) { splitPane.setDividerLocation(Math.max(0,getDividerLocation @@ -861,6 +871,11 @@ public void actionPerformed(ActionEvent ev) { */ public class KeyboardResizeToggleHandler implements ActionListener { + /** + * Constructs a {@code KeyboardResizeToggleHandler}. + */ + public KeyboardResizeToggleHandler() {} + public void actionPerformed(ActionEvent ev) { if (!dividerKeyboardResize) { splitPane.requestFocus(); diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java index a81e3f06a83b7..8446354fe1426 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -210,6 +210,11 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { // UI creation + /** + * Constructs a {@code BasicTabbedPaneUI}. + */ + public BasicTabbedPaneUI() {} + /** * Create a UI. * @param c a component @@ -2657,6 +2662,10 @@ else if (key == SCROLL_BACKWARD) { * Instantiate it only within subclasses of BasicTabbedPaneUI. */ public class TabbedPaneLayout implements LayoutManager { + /** + * Constructs a {@code TabbedPaneLayout}. + */ + public TabbedPaneLayout() {} public void addLayoutComponent(String name, Component comp) {} @@ -4195,6 +4204,11 @@ public void componentRemoved(ContainerEvent e) { * Instantiate it only within subclasses of BasicTabbedPaneUI. */ public class PropertyChangeHandler implements PropertyChangeListener { + /** + * Constructs a {@code PropertyChangeHandler}. + */ + public PropertyChangeHandler() {} + // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this @@ -4209,6 +4223,11 @@ public void propertyChange(PropertyChangeEvent e) { * Instantiate it only within subclasses of BasicTabbedPaneUI. */ public class TabSelectionHandler implements ChangeListener { + /** + * Constructs a {@code TabSelectionHandler}. + */ + public TabSelectionHandler() {} + // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this @@ -4223,6 +4242,11 @@ public void stateChanged(ChangeEvent e) { * Instantiate it only within subclasses of BasicTabbedPaneUI. */ public class MouseHandler extends MouseAdapter { + /** + * Constructs a {@code MouseHandler}. + */ + public MouseHandler() {} + // NOTE: This class exists only for backward compatibility. All // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this @@ -4241,6 +4265,11 @@ public class FocusHandler extends FocusAdapter { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code FocusHandler}. + */ + public FocusHandler() {} + public void focusGained(FocusEvent e) { getHandler().focusGained(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java index a02d25f293b8e..721fcbda9b705 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -70,6 +70,11 @@ public class BasicTableHeaderUI extends TableHeaderUI { // The column that should be highlighted when the table header has the focus. private int selectedColumnIndex = 0; // Read ONLY via getSelectedColumnIndex! + /** + * Constructs a {@code BasicTableHeaderUI}. + */ + public BasicTableHeaderUI() {} + private static FocusListener focusListener = new FocusListener() { public void focusGained(FocusEvent e) { repaintHeader(e.getSource()); @@ -104,6 +109,11 @@ public class MouseInputHandler implements MouseInputListener { private int mouseXOffset; private Cursor otherCursor = resizeCursor; + /** + * Constructs a {@code MouseInputHandler}. + */ + public MouseInputHandler() {} + public void mouseClicked(MouseEvent e) { if (!header.isEnabled()) { return; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java index d38de7e51c033..2ee4f1fa26d91 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java @@ -96,6 +96,11 @@ public class BasicTableUI extends TableUI */ private boolean isFileList = false; + /** + * Constructs a {@code BasicTableUI}. + */ + public BasicTableUI() {} + // // Helper class for keyboard actions // @@ -760,6 +765,11 @@ public class KeyHandler implements KeyListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code KeyHandler}. + */ + public KeyHandler() {} + public void keyPressed(KeyEvent e) { getHandler().keyPressed(e); } @@ -786,6 +796,11 @@ public class FocusHandler implements FocusListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code FocusHandler}. + */ + public FocusHandler() {} + public void focusGained(FocusEvent e) { getHandler().focusGained(e); } @@ -808,6 +823,11 @@ public class MouseInputHandler implements MouseInputListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code MouseInputHandler}. + */ + public MouseInputHandler() {} + public void mouseClicked(MouseEvent e) { getHandler().mouseClicked(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java index b52d365dd7641..88decfc241a9d 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTextUI.java @@ -1371,12 +1371,22 @@ public View create(Element elem, int p0, int p1) { /** * Default implementation of the interface {@code Caret}. */ - public static class BasicCaret extends DefaultCaret implements UIResource {} + public static class BasicCaret extends DefaultCaret implements UIResource { + /** + * Constructs a {@code BasicCaret}. + */ + public BasicCaret() {} + } /** * Default implementation of the interface {@code Highlighter}. */ - public static class BasicHighlighter extends DefaultHighlighter implements UIResource {} + public static class BasicHighlighter extends DefaultHighlighter implements UIResource { + /** + * Constructs a {@code BasicHighlighter}. + */ + public BasicHighlighter() {} + } static class BasicCursor extends Cursor implements UIResource { BasicCursor(int type) { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java index 605a86ed0882c..bbe35ec526d41 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java @@ -52,6 +52,11 @@ public class BasicToggleButtonUI extends BasicButtonUI { // Create PLAF // ******************************** + /** + * Constructs a {@code BasicToggleButtonUI}. + */ + public BasicToggleButtonUI() {} + /** * Returns an instance of {@code BasicToggleButtonUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java index 4a5dd209df059..d26cec557aaf7 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java @@ -45,6 +45,11 @@ public class BasicToolBarSeparatorUI extends BasicSeparatorUI { + /** + * Constructs a {@code BasicToolBarSeparatorUI}. + */ + public BasicToolBarSeparatorUI() {} + /** * Returns a new instance of {@code BasicToolBarSeparatorUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java index 3f5dad6dba97e..480588eba2d0a 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java @@ -166,6 +166,11 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants private static String FOCUSED_COMP_INDEX = "JToolBar.focusedCompIndex"; + /** + * Constructs a {@code BasicToolBarUI}. + */ + public BasicToolBarUI() {} + /** * Constructs a new instance of {@code BasicToolBarUI}. * @@ -1408,6 +1413,11 @@ public void propertyChange(PropertyChangeEvent evt) { * The class listens for window events. */ protected class FrameListener extends WindowAdapter { + /** + * Constructs a {@code FrameListener}. + */ + protected FrameListener() {} + public void windowClosing(WindowEvent w) { if (toolBar.isFloatable()) { if (dragWindow != null) @@ -1450,6 +1460,11 @@ protected class ToolBarContListener implements ContainerListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code ToolBarContListener}. + */ + protected ToolBarContListener() {} + public void componentAdded( ContainerEvent e ) { getHandler().componentAdded(e); } @@ -1468,6 +1483,11 @@ protected class ToolBarFocusListener implements FocusListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code ToolBarFocusListener}. + */ + protected ToolBarFocusListener() {} + public void focusGained( FocusEvent e ) { getHandler().focusGained(e); } @@ -1485,6 +1505,11 @@ protected class PropertyListener implements PropertyChangeListener { // its functionality has been moved into Handler. If you need to add // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code PropertyListener}. + */ + protected PropertyListener() {} + public void propertyChange( PropertyChangeEvent e ) { getHandler().propertyChange(e); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java index 3ff0fa34bc25f..6d1d85df64395 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java @@ -2904,6 +2904,11 @@ public class TreeExpansionHandler implements TreeExpansionListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code TreeExpansionHandler}. + */ + public TreeExpansionHandler() {} + /** * Called whenever an item in the tree has been expanded. */ @@ -2931,6 +2936,11 @@ public class ComponentHandler extends ComponentAdapter implements /** ScrollBar that is being adjusted. */ protected JScrollBar scrollBar; + /** + * Constructs a {@code ComponentHandler}. + */ + public ComponentHandler() {} + public void componentMoved(ComponentEvent e) { if(timer == null) { JScrollPane scrollPane = getScrollPane(); @@ -3008,6 +3018,11 @@ public class TreeModelHandler implements TreeModelListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code TreeModelHandler}. + */ + public TreeModelHandler() {} + public void treeNodesChanged(TreeModelEvent e) { getHandler().treeNodesChanged(e); } @@ -3037,6 +3052,11 @@ public class TreeSelectionHandler implements TreeSelectionListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code TreeSelectionHandler}. + */ + public TreeSelectionHandler() {} + /** * Messaged when the selection changes in the tree we're displaying * for. Stops editing, messages super and displays the changed paths. @@ -3058,6 +3078,11 @@ public class CellEditorHandler implements CellEditorListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code CellEditorHandler}. + */ + public CellEditorHandler() {} + /** Messaged when editing has stopped in the tree. */ public void editingStopped(ChangeEvent e) { getHandler().editingStopped(e); @@ -3091,6 +3116,11 @@ public class KeyHandler extends KeyAdapter { /** Set to true while keyPressed is active. */ protected boolean isKeyDown; + /** + * Constructs a {@code KeyHandler}. + */ + public KeyHandler() {} + /** * Invoked when a key has been typed. * @@ -3123,6 +3153,11 @@ public class FocusHandler implements FocusListener { // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code FocusHandler}. + */ + public FocusHandler() {} + /** * Invoked when focus is activated on the tree we're in, redraws the * lead row. @@ -3149,6 +3184,11 @@ public void focusLost(FocusEvent e) { // This returns locations that don't include any Insets. public class NodeDimensionsHandler extends AbstractLayoutCache.NodeDimensions { + /** + * Constructs a {@code NodeDimensionsHandler}. + */ + public NodeDimensionsHandler() {} + /** * Responsible for getting the size of a particular node. */ @@ -3229,6 +3269,11 @@ public class MouseHandler extends MouseAdapter implements MouseMotionListener // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code MouseHandler}. + */ + public MouseHandler() {} + /** * Invoked when a mouse button has been pressed on a component. */ @@ -3267,6 +3312,11 @@ public class PropertyChangeHandler implements // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code PropertyChangeHandler}. + */ + public PropertyChangeHandler() {} + public void propertyChange(PropertyChangeEvent event) { getHandler().propertyChange(event); } @@ -3285,6 +3335,11 @@ public class SelectionModelPropertyChangeHandler implements // new functionality add it to the Handler, but make sure this // class calls into the Handler. + /** + * Constructs a {@code SelectionModelPropertyChangeHandler}. + */ + public SelectionModelPropertyChangeHandler() {} + public void propertyChange(PropertyChangeEvent event) { getHandler().propertyChange(event); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicViewportUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicViewportUI.java index 3620bdbcff834..6326d2ea95743 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicViewportUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicViewportUI.java @@ -43,6 +43,11 @@ public class BasicViewportUI extends ViewportUI { // Shared UI object private static ViewportUI viewportUI; + /** + * Constructs a {@code BasicViewportUI}. + */ + public BasicViewportUI() {} + /** * Returns an instance of {@code BasicViewportUI}. * diff --git a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index f4c418fa948f1..895379c18643e 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -586,6 +586,10 @@ public SingleClickListener(JList list) { @Deprecated(since = "9") @SuppressWarnings("serial") // Superclass is not serializable across versions protected class FileRenderer extends DefaultListCellRenderer { + /** + * Constructs a {@code FileRenderer}. + */ + protected FileRenderer() {} } public void uninstallUI(JComponent c) { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalSliderUI.java b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalSliderUI.java index bd1d2e6b41b3d..d79bfee81b7dd 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalSliderUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalSliderUI.java @@ -180,6 +180,11 @@ protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) * {@code PropertyListener} for {@code JSlider.isFilled}. */ protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { + /** + * Constructs a {@code MetalPropertyListener}. + */ + protected MetalPropertyListener() {} + public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill super.propertyChange( e ); diff --git a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java index 15c9fd8eb134d..1f89cd88ec029 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java @@ -85,6 +85,11 @@ public class MetalToolBarUI extends BasicToolBarUI */ private JMenuBar lastMenuBar; + /** + * Constructs a {@code MetalToolBarUI}. + */ + public MetalToolBarUI() {} + /** * Registers the specified component. */ @@ -361,13 +366,23 @@ private void setLastMenuBar(JMenuBar lastMenuBar) { * No longer used. The class cannot be removed for compatibility reasons. */ protected class MetalContainerListener - extends BasicToolBarUI.ToolBarContListener {} + extends BasicToolBarUI.ToolBarContListener { + /** + * Constructs a {@code MetalContainerListener}. + */ + protected MetalContainerListener() {} + } /** * No longer used. The class cannot be removed for compatibility reasons. */ protected class MetalRolloverListener - extends BasicToolBarUI.PropertyListener {} + extends BasicToolBarUI.PropertyListener { + /** + * Constructs a {@code MetalRolloverListener}. + */ + protected MetalRolloverListener() {} + } /** * {@code DockingListener} for {@code MetalToolBarUI}. From 9ac162e896dcb07071c7a2146e8eecbd75115edb Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Thu, 24 Sep 2020 16:32:05 +0000 Subject: [PATCH 05/79] 8251999: remove usage of PropertyResolvingWrapper in vmTestbase/nsk/aod Reviewed-by: shade, sspitsyn --- .../AttachProvider01/AttachProvider01.java | 18 ++-- .../AttachProvider02/AttachProvider02.java | 26 +++--- .../jtreg/vmTestbase/nsk/aod/TEST.properties | 2 - .../VirtualMachine01/VirtualMachine01.java | 16 ++-- .../VirtualMachine02/VirtualMachine02.java | 20 ++--- .../VirtualMachine03/VirtualMachine03.java | 42 +++++----- .../VirtualMachine04/VM04Target.java | 25 +++--- .../VirtualMachine04/VirtualMachine04.java | 31 ++++--- .../VirtualMachine05/VirtualMachine05.java | 22 ++--- .../VirtualMachine06/VM06Agent00.java | 5 +- .../VirtualMachine06/VM06Agent01.java | 7 +- .../VirtualMachine06/VM06Agent02.java | 5 +- .../VirtualMachine06/VM06Agent03.java | 5 +- .../VirtualMachine06/VirtualMachine06.java | 34 ++++---- .../VirtualMachine07/VirtualMachine07.java | 60 +++++++------- .../VirtualMachine08/TestDescription.java | 8 +- .../VirtualMachine09/VirtualMachine09.java | 22 ++--- .../VirtualMachine10/TestDescription.java | 8 +- .../VirtualMachineDescriptor01.java | 16 ++-- .../nsk/share/aod/AODRunnerArgParser.java | 82 ++++++++++--------- 20 files changed, 232 insertions(+), 222 deletions(-) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/aod/TEST.properties diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider01/AttachProvider01.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider01/AttachProvider01.java index e68fb16def2b2..7e3f7a9687ddb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider01/AttachProvider01.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider01/AttachProvider01.java @@ -35,23 +35,25 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.AttachProvider.AttachProvider01.AttachProvider01 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.AttachProvider.AttachProvider01.AttachProvider01 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.AttachProvider.AttachProvider01; -import java.util.List; -import com.sun.tools.attach.*; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.spi.AttachProvider; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; +import java.util.List; + /* * Test checks method AttachProvider.listVirtualMachines() * (test checks that collection returned by AttachProvider.listVirtualMachines() contains current VM @@ -63,7 +65,7 @@ public AttachProvider01(String[] args) { super(args); } - public void doTestActions(String targetVMId) throws Throwable { + public void doTestActions(String targetVMId) { String currentVMId = getCurrentVMId(); for (AttachProvider provider : AttachProvider.providers()) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider02/AttachProvider02.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider02/AttachProvider02.java index 45a0642b3be07..9c9ba30aad589 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider02/AttachProvider02.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/AttachProvider/AttachProvider02/AttachProvider02.java @@ -37,24 +37,26 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.AttachProvider.AttachProvider02.AttachProvider02 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData - * PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -Djdk.attach.allowAttachSelf + * -XX:+UsePerfData * nsk.aod.AttachProvider.AttachProvider02.AttachProvider02 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.AttachProvider.AttachProvider02; -import java.util.Properties; -import com.sun.tools.attach.*; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.spi.AttachProvider; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; +import java.util.Properties; + /* * Test checks following methods: * - AttachProvider.attachVirtualMachine(String id) @@ -80,11 +82,9 @@ public void doTestActions(String targetVMId) throws Throwable { TestUtils.assertNotNull(provider.type(), "Provider.type() returns null"); tryAttach(provider, currentVMId, false); - tryAttach(provider, currentVMId, true); tryAttach(provider, targetVMId, false); - tryAttach(provider, targetVMId, true); } } @@ -95,17 +95,17 @@ void tryAttach(AttachProvider provider, String vmId, boolean useVMDescriptor) th VirtualMachine vm; - if (useVMDescriptor) + if (useVMDescriptor) { vm = provider.attachVirtualMachine(new VirtualMachineDescriptor(provider, vmId)); - else + } else { vm = provider.attachVirtualMachine(vmId); + } try { log.display("Attached to vm: " + vm); TestUtils.assertEquals(vm.id(), vmId, "VirtualMachine.id() returns unexpected value for attached vm: " + vm.id()); // try to use created VirtualMachine - log.display("Trying to call VirtualMachine.getSystemProperties()"); Properties properties = vm.getSystemProperties(); TestUtils.assertNotNull(properties, "VirtualMachine.getSystemProperties() returns null"); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/TEST.properties b/test/hotspot/jtreg/vmTestbase/nsk/aod/TEST.properties deleted file mode 100644 index d63be96485226..0000000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/TEST.properties +++ /dev/null @@ -1,2 +0,0 @@ -# disabled till JDK-8251999 is fixed -allowSmartActionArgs=false diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.java index dc98240584d98..257d4022d2b6f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine01/VirtualMachine01.java @@ -39,21 +39,23 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine01 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine01 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.VirtualMachine.VirtualMachine01; -import nsk.share.aod.*; -import nsk.share.test.TestUtils; -import com.sun.tools.attach.*; +import com.sun.tools.attach.AttachNotSupportedException; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.spi.AttachProvider; +import nsk.share.aod.AODTestRunner; +import nsk.share.test.TestUtils; /* * Test provokes exception which should be thrown by VirtualMachine methods: diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine02/VirtualMachine02.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine02/VirtualMachine02.java index 8116ef96eed88..a562b939b2502 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine02/VirtualMachine02.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine02/VirtualMachine02.java @@ -39,30 +39,30 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine02.VirtualMachine02 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData - * PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -Djdk.attach.allowAttachSelf + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine02.VirtualMachine02 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.VirtualMachine.VirtualMachine02; -import java.io.IOException; -import com.sun.tools.attach.*; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.spi.AttachProvider; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; +import java.io.IOException; + /* * Test checks following methods: * - VirtualMachine.attach(String) (test tries to attach to current and to another VM) - * * - VirtualMachine.attach(VirtualMachineDescriptor) (test tries to attach to current and to another VM) - * * - VirtualMachine.detach() (test checks that after detaching operations on VirtualMachine * throw IOException) */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine03/VirtualMachine03.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine03/VirtualMachine03.java index 7c9414613a315..3a1905faed54c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine03/VirtualMachine03.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine03/VirtualMachine03.java @@ -34,20 +34,20 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine03.VirtualMachine03 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData - * PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -Djdk.attach.allowAttachSelf + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine03.VirtualMachine03 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.VirtualMachine.VirtualMachine03; import com.sun.tools.attach.VirtualMachine; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; /* @@ -63,23 +63,21 @@ public void doTestActions(String targetVMId) throws Throwable { String currentVMId = getCurrentVMId(); VirtualMachine vm1 = VirtualMachine.attach(currentVMId); - - VirtualMachine vm2 = VirtualMachine.attach(targetVMId); - try { - TestUtils.assertEquals(vm1.id(), currentVMId, "vm.id() returns unexpected value: " + vm1.id()); - - TestUtils.assertEquals(vm2.id(), targetVMId, "vm.id() returns unexpected value: " + vm2.id()); - - TestUtils.assertTrue(!vm1.equals(vm2), vm1 + ".equals(" + vm2 + ") returns 'true'"); - - checkVM(vm1); - - checkVM(vm2); + VirtualMachine vm2 = VirtualMachine.attach(targetVMId); + try { + TestUtils.assertEquals(vm1.id(), currentVMId, "vm.id() returns unexpected value: " + vm1.id()); + TestUtils.assertEquals(vm2.id(), targetVMId, "vm.id() returns unexpected value: " + vm2.id()); + + TestUtils.assertTrue(!vm1.equals(vm2), vm1 + ".equals(" + vm2 + ") returns 'true'"); + + checkVM(vm1); + checkVM(vm2); + } finally { + vm2.detach(); + } } finally { vm1.detach(); - - vm2.detach(); } } @@ -90,15 +88,13 @@ void checkVM(VirtualMachine vm1) throws Throwable { VirtualMachine vm2 = VirtualMachine.attach(vm1.id()); try { TestUtils.assertEquals(vm1, vm2, vm1 + ".equals(" + vm2 + ") returns 'false'"); - TestUtils.assertTrue(vm1.hashCode() == vm2.hashCode(), "vm.hashCode() returns different values for " + vm1 + " and " + vm2); - TestUtils.assertEquals(vm1.provider(), vm2.provider(), "vm.provider() returns non-equals objects for " + vm1 + " and " + vm2); } finally { vm2.detach(); } - TestUtils.assertTrue(!vm1.equals(new String()), "vm.equals(String) returns 'true'"); + TestUtils.assertTrue(!vm1.equals(""), "vm.equals(String) returns 'true'"); TestUtils.assertTrue(!vm1.equals(null), "vm.equals(null) returns 'true'"); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VM04Target.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VM04Target.java index 005deb881161e..0dcf9e2518c21 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VM04Target.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VM04Target.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2020, 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 @@ -20,6 +20,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ + package nsk.aod.VirtualMachine.VirtualMachine04; import nsk.share.TestBug; @@ -30,28 +31,26 @@ * main test application tries to get this property using VirtualMachine.getSystemProperties() */ public class VM04Target extends DummyTargetApplication { - - static String testPropertyKey = "VirtualMachine04_testPropertyKey"; - - static String testPropertyValue = "VirtualMachine04_testPropertyValue"; - - static String changedTestPropertyValue = "VirtualMachine04_testPropertyValue_changed"; + static final String TEST_PROPERTY_KEY = "VirtualMachine04_testPropertyKey"; + static final String TEST_PROPERTY_VALUE = "VirtualMachine04_testPropertyValue"; + static final String CHANGED_TEST_PROPERTY_VALUE = "VirtualMachine04_testPropertyValue_changed"; VM04Target(String[] args) { super(args); - log.display("Setting property " + testPropertyKey + " = " + testPropertyValue); - System.setProperty(testPropertyKey, testPropertyValue); + log.display("Setting property " + TEST_PROPERTY_KEY + " = " + TEST_PROPERTY_VALUE); + System.setProperty(TEST_PROPERTY_KEY, TEST_PROPERTY_VALUE); } protected void targetApplicationActions() { String signal = pipe.readln(); - log.display("Received signal: " + signal); - if (!signal.equals(VirtualMachine04.SIGNAL_CHANGE_PROPERTY)) + log.display("Received signal: " + signal); + if (!signal.equals(VirtualMachine04.SIGNAL_CHANGE_PROPERTY)) { throw new TestBug("Received unexpected signal: " + signal); + } - log.display("Setting property " + testPropertyKey + " = " + changedTestPropertyValue); - System.setProperty(testPropertyKey, changedTestPropertyValue); + log.display("Setting property " + TEST_PROPERTY_KEY + " = " + CHANGED_TEST_PROPERTY_VALUE); + System.setProperty(TEST_PROPERTY_KEY, CHANGED_TEST_PROPERTY_VALUE); log.display("Sending signal " + VirtualMachine04.SIGNAL_PROPERTY_CHANGED); pipe.println(VirtualMachine04.SIGNAL_PROPERTY_CHANGED); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.java index 7fe22a069d0a2..3bd98cd5043a8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.java @@ -38,33 +38,31 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine04 - * nsk.aod.VirtualMachine.VirtualMachine04.VM04Target - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.aod.VirtualMachine.VirtualMachine04.VM04Target + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine04 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.aod.VirtualMachine.VirtualMachine04.VM04Target */ package nsk.aod.VirtualMachine.VirtualMachine04; -import java.util.Properties; import com.sun.tools.attach.VirtualMachine; +import nsk.share.TestBug; import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; -import nsk.share.*; + +import java.util.Properties; /* * Test checks following methods: * - VirtualMachine.getSystemProperties() - * * - VirtualMachine.getAgentProperties() */ public class VirtualMachine04 extends AODTestRunner { - static final String SIGNAL_CHANGE_PROPERTY = "change_property"; - static final String SIGNAL_PROPERTY_CHANGED = "property_changed"; public VirtualMachine04(String[] args) { @@ -75,16 +73,16 @@ public void doTestActions(String targetVMId) throws Throwable { VirtualMachine vm = VirtualMachine.attach(targetVMId); try { - checkSystemProperties(vm, VM04Target.testPropertyKey, VM04Target.testPropertyValue); + checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.TEST_PROPERTY_VALUE); log.display("Sending signal " + SIGNAL_CHANGE_PROPERTY); pipe.println(SIGNAL_CHANGE_PROPERTY); String signal = pipe.readln(); log.display("Received signal " + signal); - if (!signal.equals(SIGNAL_PROPERTY_CHANGED)) + if (!signal.equals(SIGNAL_PROPERTY_CHANGED)) { throw new TestBug("Unexpected signal received: " + signal); - - checkSystemProperties(vm, VM04Target.testPropertyKey, VM04Target.changedTestPropertyValue); + } + checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.CHANGED_TEST_PROPERTY_VALUE); Properties properties = vm.getAgentProperties(); System.out.println("VirtualMachine.getAgentProperties(): " + properties); @@ -95,14 +93,14 @@ public void doTestActions(String targetVMId) throws Throwable { } void checkSystemProperties(VirtualMachine vm, - String propertyToCheck, - String expectedPropertyValue) throws Throwable { + String propertyToCheck, + String expectedPropertyValue) throws Throwable { Properties properties = vm.getSystemProperties(); System.out.println("VirtualMachine.getSystemProperties(): " + properties); checkProperties(properties); - String checkedPropertyValue = properties.getProperty(propertyToCheck); + String checkedPropertyValue = properties.getProperty(propertyToCheck); TestUtils.assertNotNull(checkedPropertyValue, "Properties doesn't contain property '" + propertyToCheck + "'"); TestUtils.assertEquals(checkedPropertyValue, expectedPropertyValue, "Unexpected value of the property '" + propertyToCheck + "': " + checkedPropertyValue + ", expected value is '" + expectedPropertyValue + "'"); @@ -120,7 +118,6 @@ void checkProperties(Properties properties) { log.display("Value of '" + key + "' = " + value); TestUtils.assertTrue(key instanceof String, "Property key isn't String: " + key.getClass().getName()); - TestUtils.assertTrue(value instanceof String, "Property value isn't String: " + value.getClass().getName()); } } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine05/VirtualMachine05.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine05/VirtualMachine05.java index ae516c3f8b755..3c7e90a7ffab7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine05/VirtualMachine05.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine05/VirtualMachine05.java @@ -35,22 +35,24 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine05.VirtualMachine05 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine05.VirtualMachine05 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.VirtualMachine.VirtualMachine05; -import java.util.List; -import com.sun.tools.attach.*; -import nsk.share.aod.*; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; +import java.util.List; + /* * Test checks method VirtualMachine.list() * (test checks that collection returned by VirtualMachine.list() contains current VM @@ -62,14 +64,14 @@ public VirtualMachine05(String[] args) { super(args); } - public void doTestActions(String targetVMId) throws Throwable { + public void doTestActions(String targetVMId) { String currentVMId = getCurrentVMId(); log.display("Checking VirtualMachine.list()"); - checkList(VirtualMachine.list(), currentVMId, targetVMId); + checkList(currentVMId, targetVMId); } - private void checkList(List vmDescriptors, String currentVMId, String targetVMId) { + private void checkList(String currentVMId, String targetVMId) { VirtualMachineDescriptor currentVM = null; VirtualMachineDescriptor targetVM = null; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.java index 7f3f24affcffc..0b961dc1e719b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.java @@ -20,12 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package nsk.aod.VirtualMachine.VirtualMachine06; -import java.lang.instrument.Instrumentation; +package nsk.aod.VirtualMachine.VirtualMachine06; import nsk.share.aod.TargetApplicationWaitingAgents; +import java.lang.instrument.Instrumentation; + public class VM06Agent00 { public static void agentmain(String options, Instrumentation inst) { boolean success = true; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.java index e468e1f1d1772..f863c196219cb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2020, 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 @@ -20,12 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package nsk.aod.VirtualMachine.VirtualMachine06; -import java.lang.instrument.Instrumentation; +package nsk.aod.VirtualMachine.VirtualMachine06; import nsk.share.aod.TargetApplicationWaitingAgents; +import java.lang.instrument.Instrumentation; + public class VM06Agent01 { public static void agentmain(String options, Instrumentation inst) { boolean success = true; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.java index 04ae20a38ac26..786f3f6d31877 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.java @@ -20,12 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package nsk.aod.VirtualMachine.VirtualMachine06; -import java.lang.instrument.Instrumentation; +package nsk.aod.VirtualMachine.VirtualMachine06; import nsk.share.aod.TargetApplicationWaitingAgents; +import java.lang.instrument.Instrumentation; + public class VM06Agent02 { public static void agentmain(String options, Instrumentation inst) { boolean success = true; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.java index 87558ec9e3a5b..a4053c73b5963 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.java @@ -20,12 +20,13 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package nsk.aod.VirtualMachine.VirtualMachine06; -import java.lang.instrument.Instrumentation; +package nsk.aod.VirtualMachine.VirtualMachine06; import nsk.share.aod.TargetApplicationWaitingAgents; +import java.lang.instrument.Instrumentation; + public class VM06Agent03 { public static void agentmain(String options, Instrumentation inst) { TargetApplicationWaitingAgents.agentLoaded(VM06Agent03.class.getName()); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VirtualMachine06.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VirtualMachine06.java index d839fbe852452..58b9ac3fb98d7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VirtualMachine06.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine06/VirtualMachine06.java @@ -53,51 +53,52 @@ * nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent03 * * @comment create VM06Agent0[0-3].jar in current directory - * @build ExecDriver - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver ExecDriver --cmd * ${test.jdk}/bin/jar * -cmf ${test.src}/VM06Agent00.mf * VM06Agent00.jar * nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.class - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver ExecDriver --cmd * ${test.jdk}/bin/jar * -cmf ${test.src}/VM06Agent01.mf * VM06Agent01.jar * nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.class - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver ExecDriver --cmd * ${test.jdk}/bin/jar * -cmf ${test.src}/VM06Agent02.mf * VM06Agent02.jar * nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.class - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver ExecDriver --cmd * ${test.jdk}/bin/jar * -cmf ${test.src}/VM06Agent03.mf * VM06Agent03.jar * nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.class * * - * @build nsk.aod.VirtualMachine.VirtualMachine06.VirtualMachine06 - * nsk.share.aod.TargetApplicationWaitingAgents - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.TargetApplicationWaitingAgents + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine06.VirtualMachine06 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.TargetApplicationWaitingAgents * -ja VM06Agent00.jar,VM06Agent01.jar,VM06Agent02.jar,VM06Agent03.jar */ package nsk.aod.VirtualMachine.VirtualMachine06; +import com.sun.tools.attach.AgentInitializationException; +import com.sun.tools.attach.VirtualMachine; import nsk.share.TestBug; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; +import nsk.share.aod.AgentInformation; import nsk.share.test.TestUtils; -import java.util.*; -import com.sun.tools.attach.*; + +import java.util.List; /* * Test checks following methods: * - VirtualMachine.loadAgent(String) - * * - VirtualMachine.loadAgent(String, String) */ public class VirtualMachine06 extends AODTestRunner { @@ -109,12 +110,13 @@ public VirtualMachine06(String[] args) { public void doTestActions(String targetVMId) throws Throwable { // check that all required parameters were passed to the test List agents = argParser.getAgents(); - if (agents.size() != 4) + if (agents.size() != 4) { throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified"); - + } for (AgentInformation agent : agents) { - if (!agent.jarAgent) + if (!agent.jarAgent) { throw new TestBug("Non JAR agent was specified"); + } } VirtualMachine vm = VirtualMachine.attach(targetVMId); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/VirtualMachine07.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/VirtualMachine07.java index bb2084760e1e3..73b4522ae6eae 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/VirtualMachine07.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine07/VirtualMachine07.java @@ -40,12 +40,12 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07 - * nsk.share.aod.TargetApplicationWaitingAgents - * @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.TargetApplicationWaitingAgents + * @run main/othervm/native + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.TargetApplicationWaitingAgents * -na VirtualMachine07agent00,VirtualMachine07agent01,VirtualMachine07agent02,VirtualMachine07agent03 * -testedMethod loadAgentLibrary @@ -53,27 +53,26 @@ package nsk.aod.VirtualMachine.VirtualMachine07; -import nsk.share.*; -import nsk.share.aod.*; +import com.sun.tools.attach.AgentInitializationException; +import com.sun.tools.attach.VirtualMachine; +import nsk.share.TestBug; +import nsk.share.aod.AODRunnerArgParser; +import nsk.share.aod.AODTestRunner; +import nsk.share.aod.AgentInformation; import nsk.share.test.TestUtils; -import java.util.*; - -import com.sun.tools.attach.*; +import java.util.List; /* * Test is written to test following methods: * - VirtualMachine.loadAgentLibrary - * * - VirtualMachine.loadAgentPath * *(method to test is specified via command line parameter 'testedMethod') */ public class VirtualMachine07 extends AODTestRunner { - - static class ArgParser extends AODRunnerArgParser { - - final String testedMethodOpt = "testedMethod"; + private static class ArgParser extends AODRunnerArgParser { + private static final String TESTED_METHOD_OPT = "testedMethod"; ArgParser(String[] args) { super(args); @@ -83,11 +82,12 @@ protected boolean checkOption(String option, String value) { if (super.checkOption(option, value)) return true; - if (option.equals(testedMethodOpt)) { - if (value.equals("loadAgentLibrary") || value.equals("loadAgentPath")) + if (option.equals(TESTED_METHOD_OPT)) { + if ("loadAgentLibrary".equals(value) || "loadAgentPath".equals(value)) { return true; - else - throw new TestBug("Unexpected value of '" + testedMethodOpt + "': " + value); + } else { + throw new TestBug("Unexpected value of '" + TESTED_METHOD_OPT + "': " + value); + } } return false; @@ -98,13 +98,14 @@ protected void checkOptions() { // if test loadAgentPath parameter arch is needed if (!testLoadAgentLibrary()) { - if (!options.containsKey("arch")) + if (!options.containsKey("arch")) { throw new TestBug("Option 'arch' wasn't specified"); + } } } boolean testLoadAgentLibrary() { - return options.getProperty(testedMethodOpt).equals("loadAgentLibrary"); + return options.getProperty(TESTED_METHOD_OPT).equals("loadAgentLibrary"); } } @@ -141,10 +142,11 @@ protected AODRunnerArgParser createArgParser(String[] args) { protected void loadAgent(VirtualMachine vm, String agent) throws Throwable { boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary(); - if (testLoadAgentLibrary) + if (testLoadAgentLibrary) { log.display("Test method VirtualMachine.loadAgentLibrary"); - else + } else { log.display("Test method VirtualMachine.loadAgentPath"); + } if (testLoadAgentLibrary) { log.display("Loading '" + agent + "'"); @@ -159,10 +161,11 @@ protected void loadAgent(VirtualMachine vm, String agent) throws Throwable { protected void loadAgent(VirtualMachine vm, String agent, String options) throws Throwable { boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary(); - if (testLoadAgentLibrary) + if (testLoadAgentLibrary) { log.display("Test method VirtualMachine.loadAgentLibrary"); - else + } else { log.display("Test method VirtualMachine.loadAgentPath"); + } if (testLoadAgentLibrary) { log.display("Loading '" + agent + "'"); @@ -177,12 +180,13 @@ protected void loadAgent(VirtualMachine vm, String agent, String options) throws public void doTestActions(String targetVMId) throws Throwable { // check that all required parameters were passed to the test List agents = argParser.getAgents(); - if (agents.size() != 4) + if (agents.size() != 4) { throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified"); - + } for (AgentInformation agent : agents) { - if (agent.jarAgent) + if (agent.jarAgent) { throw new TestBug("Non native agent was specified"); + } } VirtualMachine vm = VirtualMachine.attach(targetVMId); @@ -209,7 +213,7 @@ public void doTestActions(String targetVMId) throws Throwable { log.display("Expected AgentInitializationException was caught"); log.display("AgentInitializationException.returnValue(): " + e.returnValue()); TestUtils.assertEquals(e.returnValue(), 10, - "AgentInitializationException.returnValue() returns unexpected value: " + e.returnValue()+ ", expected value is 10"); + "AgentInitializationException.returnValue() returns unexpected value: " + e.returnValue() + ", expected value is 10"); } } finally { vm.detach(); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine08/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine08/TestDescription.java index d0c629b316363..e484641dd2af6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine08/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine08/TestDescription.java @@ -41,12 +41,12 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07 - * nsk.share.aod.TargetApplicationWaitingAgents - * @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.TargetApplicationWaitingAgents + * @run main/othervm/native + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.TargetApplicationWaitingAgents * -na ${test.nativepath}/VirtualMachine07agent00,${test.nativepath}/VirtualMachine07agent01,${test.nativepath}/VirtualMachine07agent02,${test.nativepath}/VirtualMachine07agent03 * -testedMethod loadAgentPath diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/VirtualMachine09.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/VirtualMachine09.java index 5488e4c79d1ed..47d1a718e8802 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/VirtualMachine09.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/VirtualMachine09.java @@ -37,12 +37,12 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09 - * nsk.aod.VirtualMachine.VirtualMachine09.VM09Target - * @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.aod.VirtualMachine.VirtualMachine09.VM09Target + * @run main/othervm/native + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09 * -jdk ${test.jdk} - * "-javaOpts=-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.aod.VirtualMachine.VirtualMachine09.VM09Target * -na VirtualMachine09agent00 * -testedMethod loadAgentLibrary @@ -50,13 +50,12 @@ package nsk.aod.VirtualMachine.VirtualMachine09; +import com.sun.tools.attach.VirtualMachine; import nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07; import nsk.share.TestBug; -import nsk.share.aod.*; +import nsk.share.aod.AgentInformation; -import java.util.*; - -import com.sun.tools.attach.*; +import java.util.List; /* * Test checks methods VirtualMachine.loadAgentLib and VirtualMachineloadAgentPath. @@ -73,12 +72,13 @@ public VirtualMachine09(String[] args) { public void doTestActions(String targetVMId) throws Throwable { // check that all required parameters were passed to the test List agents = argParser.getAgents(); - if (agents.size() != 1) + if (agents.size() != 1) { throw new TestBug("Test requires 1 agent, actually " + agents.size() + " were specified"); - + } for (AgentInformation agent : agents) { - if (agent.jarAgent) + if (agent.jarAgent) { throw new TestBug("Non native agent was specified"); + } } VirtualMachine vm = VirtualMachine.attach(targetVMId); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine10/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine10/TestDescription.java index e07fed3dd6cb8..c9c5b1ee64f0d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine10/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine10/TestDescription.java @@ -38,12 +38,12 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09 - * nsk.aod.VirtualMachine.VirtualMachine09.VM09Target - * @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.aod.VirtualMachine.VirtualMachine09.VM09Target + * @run main/othervm/native + * -XX:+UsePerfData * nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09 * -jdk ${test.jdk} - * "-javaOpts=-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.aod.VirtualMachine.VirtualMachine09.VM09Target * -na ${test.nativepath}/VirtualMachine09agent00 * -testedMethod loadAgentPath diff --git a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachineDescriptor/VirtualMachineDescriptor01/VirtualMachineDescriptor01.java b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachineDescriptor/VirtualMachineDescriptor01/VirtualMachineDescriptor01.java index 8ab53fa931b99..47f837a110ffb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachineDescriptor/VirtualMachineDescriptor01/VirtualMachineDescriptor01.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachineDescriptor/VirtualMachineDescriptor01/VirtualMachineDescriptor01.java @@ -37,20 +37,21 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01.VirtualMachineDescriptor01 - * nsk.share.aod.DummyTargetApplication - * @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper + * @build nsk.share.aod.DummyTargetApplication + * @run main/othervm + * -XX:+UsePerfData * nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01.VirtualMachineDescriptor01 * -jdk ${test.jdk} - * "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" + * -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}" * -target nsk.share.aod.DummyTargetApplication */ package nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01; -import com.sun.tools.attach.*; +import com.sun.tools.attach.VirtualMachine; +import com.sun.tools.attach.VirtualMachineDescriptor; import com.sun.tools.attach.spi.AttachProvider; -import nsk.share.aod.*; +import nsk.share.aod.AODTestRunner; import nsk.share.test.TestUtils; /* @@ -108,8 +109,7 @@ public void doTestActions(String targetVMId) throws Throwable { "VirtualMachineDescriptor.equals() returns 'false' for '" + targetVMDesc + "' and '" + targetVMDesc2 + "'"); TestUtils.assertEquals(targetVMDesc.hashCode(), targetVMDesc2.hashCode(), - "VirtualMachineDescriptor.hashCode() returns different values " + "(" + targetVMDesc.hashCode() + " and " + targetVMDesc2.hashCode() + ")" + - " for '" + targetVMDesc + "' and '" + targetVMDesc2 + "'"); + "VirtualMachineDescriptor.hashCode() returns different values for '" + targetVMDesc + "' and '" + targetVMDesc2 + "'"); } finally { targetVM.detach(); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java index e6a961dc08dd8..b5cc96055d6d2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODRunnerArgParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2020, 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 @@ -20,33 +20,28 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package nsk.share.aod; - -import nsk.share.*; -import java.util.*; - -public class AODRunnerArgParser extends ArgumentParser { - public static final String jarAgentParam = "ja"; - - public static final String nativeAgentParam = "na"; - - public static final String targetAppParam = "target"; - - public static final String javaOptsParam = "javaOpts"; +package nsk.share.aod; - public static final String testedJdkParam = "jdk"; +import nsk.share.ArgumentParser; +import nsk.share.TestBug; - private static List supportedOptions; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; - static { - supportedOptions = new ArrayList(); - supportedOptions.add(jarAgentParam); - supportedOptions.add(nativeAgentParam); - supportedOptions.add(targetAppParam); - supportedOptions.add(javaOptsParam); - supportedOptions.add(testedJdkParam); - } +public class AODRunnerArgParser extends ArgumentParser { + private static final String JAR_AGENT_PARAM = "ja"; + private static final String NATIVE_AGENT_PARAM = "na"; + private static final String TARGET_APP_PARAM = "target"; + private static final String JAVA_OPTS_PARAM = "javaOpts"; + private static final String TESTED_JDK_PARAM = "jdk"; + private static final Set SUPPORTED_OPTIONS = Set.of( + JAR_AGENT_PARAM, + NATIVE_AGENT_PARAM, + TARGET_APP_PARAM, + JAVA_OPTS_PARAM, + TESTED_JDK_PARAM); private List agents; @@ -55,17 +50,19 @@ public AODRunnerArgParser(String[] args) { } protected boolean checkOption(String option, String value) { - if (super.checkOption(option, value)) + if (super.checkOption(option, value)) { return true; + } - if (!supportedOptions.contains(option)) + if (!SUPPORTED_OPTIONS.contains(option)) { return false; + } - if (option.equals(jarAgentParam)) { + if (option.equals(JAR_AGENT_PARAM)) { addAgentInfo(true, value); } - if (option.equals(nativeAgentParam)) { + if (option.equals(NATIVE_AGENT_PARAM)) { addAgentInfo(false, value); } @@ -74,21 +71,22 @@ protected boolean checkOption(String option, String value) { protected void checkOptions() { if (agents == null) { - agents = new ArrayList(); + agents = new ArrayList<>(); } } private void addAgentInfo(boolean jarAgent, String unsplittedAgentsString) { if (agents == null) { - agents = new ArrayList(); + agents = new ArrayList<>(); } - String agentStrings[]; + String[] agentStrings; - if (unsplittedAgentsString.contains(",")) + if (unsplittedAgentsString.contains(",")) { agentStrings = unsplittedAgentsString.split(","); - else - agentStrings = new String[]{unsplittedAgentsString}; + } else { + agentStrings = new String[]{ unsplittedAgentsString }; + } for (String agentString : agentStrings) { int index = agentString.indexOf('='); @@ -104,21 +102,27 @@ private void addAgentInfo(boolean jarAgent, String unsplittedAgentsString) { } public String getTargetApp() { - if (!options.containsKey(targetAppParam)) + if (!options.containsKey(TARGET_APP_PARAM)) { throw new TestBug("Target application isn't specified"); + } - return options.getProperty(targetAppParam); + return options.getProperty(TARGET_APP_PARAM); } public String getTestedJDK() { - if (!options.containsKey(testedJdkParam)) + if (!options.containsKey(TESTED_JDK_PARAM)) { throw new TestBug("Tested JDK isn't specified"); + } - return options.getProperty(testedJdkParam); + return options.getProperty(TESTED_JDK_PARAM); } public String getJavaOpts() { - return options.getProperty(javaOptsParam, ""); + var value = options.getProperty(JAVA_OPTS_PARAM, ""); + if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { + value = value.substring(1, value.length() - 1); + } + return value.trim(); } public List getAgents() { From 8b85c3a6d7fc2d710a704b306cafce88f7006d32 Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Thu, 24 Sep 2020 19:19:53 +0000 Subject: [PATCH 06/79] 8251261: CDS dumping should not clear states in live classes Reviewed-by: minqi, ccheung --- src/hotspot/share/classfile/javaClasses.cpp | 3 +- src/hotspot/share/memory/archiveBuilder.cpp | 29 ++++++++ src/hotspot/share/memory/archiveBuilder.hpp | 34 +++++++++- src/hotspot/share/memory/dynamicArchive.cpp | 59 ++--------------- src/hotspot/share/memory/heapShared.cpp | 3 +- src/hotspot/share/memory/metaspaceShared.cpp | 70 ++++---------------- src/hotspot/share/memory/universe.cpp | 15 ++--- src/hotspot/share/memory/universe.hpp | 1 - src/hotspot/share/oops/constantPool.cpp | 12 +--- 9 files changed, 88 insertions(+), 138 deletions(-) diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 0aed2e9e2ef34..de63869507312 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -1179,8 +1179,7 @@ oop java_lang_Class::archive_mirror(Klass* k, TRAPS) { if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() || ik->is_shared_app_class())) { // Archiving mirror for classes from non-builtin loaders is not - // supported. Clear the _java_mirror within the archived class. - k->clear_java_mirror_handle(); + // supported. return NULL; } } diff --git a/src/hotspot/share/memory/archiveBuilder.cpp b/src/hotspot/share/memory/archiveBuilder.cpp index adf3b63b08c9e..2aab63d8151eb 100644 --- a/src/hotspot/share/memory/archiveBuilder.cpp +++ b/src/hotspot/share/memory/archiveBuilder.cpp @@ -41,6 +41,7 @@ #include "utilities/hashtable.inline.hpp" ArchiveBuilder* ArchiveBuilder::_singleton = NULL; +intx ArchiveBuilder::_buffer_to_target_delta = 0; ArchiveBuilder::OtherROAllocMark::~OtherROAllocMark() { char* newtop = ArchiveBuilder::singleton()->_ro_region->top(); @@ -564,6 +565,34 @@ void ArchiveBuilder::relocate_well_known_klasses() { SystemDictionary::well_known_klasses_do(&doit); } +void ArchiveBuilder::make_klasses_shareable() { + for (int i = 0; i < klasses()->length(); i++) { + Klass* k = klasses()->at(i); + k->remove_java_mirror(); + if (k->is_objArray_klass()) { + // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info + // on their array classes. + } else if (k->is_typeArray_klass()) { + k->remove_unshareable_info(); + } else { + assert(k->is_instance_klass(), " must be"); + InstanceKlass* ik = InstanceKlass::cast(k); + if (DynamicDumpSharedSpaces) { + // For static dump, class loader type are already set. + ik->assign_class_loader_type(); + } + + MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread::current(), ik); + ik->remove_unshareable_info(); + + if (log_is_enabled(Debug, cds, class)) { + ResourceMark rm; + log_debug(cds, class)("klasses[%4d] = " PTR_FORMAT " %s", i, p2i(to_target(ik)), ik->external_name()); + } + } + } +} + void ArchiveBuilder::print_stats(int ro_all, int rw_all, int mc_all) { _alloc_stats->print_stats(ro_all, rw_all, mc_all); } diff --git a/src/hotspot/share/memory/archiveBuilder.hpp b/src/hotspot/share/memory/archiveBuilder.hpp index 36478db314762..c00b85375bbe9 100644 --- a/src/hotspot/share/memory/archiveBuilder.hpp +++ b/src/hotspot/share/memory/archiveBuilder.hpp @@ -193,6 +193,37 @@ class ArchiveBuilder : public StackObj { _ro_region = ro_region; } +protected: + DumpRegion* _current_dump_space; + address _alloc_bottom; + + DumpRegion* current_dump_space() const { return _current_dump_space; } + +public: + void set_current_dump_space(DumpRegion* r) { _current_dump_space = r; } + + bool is_in_buffer_space(address p) const { + return (_alloc_bottom <= p && p < (address)current_dump_space()->top()); + } + + template bool is_in_target_space(T target_obj) const { + address buff_obj = address(target_obj) - _buffer_to_target_delta; + return is_in_buffer_space(buff_obj); + } + + template bool is_in_buffer_space(T obj) const { + return is_in_buffer_space(address(obj)); + } + + template T to_target_no_check(T obj) const { + return (T)(address(obj) + _buffer_to_target_delta); + } + + template T to_target(T obj) const { + assert(is_in_buffer_space(obj), "must be"); + return (T)(address(obj) + _buffer_to_target_delta); + } + public: ArchiveBuilder(DumpRegion* rw_region, DumpRegion* ro_region); ~ArchiveBuilder(); @@ -208,7 +239,7 @@ class ArchiveBuilder : public StackObj { void dump_ro_region(); void relocate_pointers(); void relocate_well_known_klasses(); - + void make_klasses_shareable(); address get_dumped_addr(address src_obj) const; // All klasses and symbols that will be copied into the archive @@ -235,6 +266,7 @@ class ArchiveBuilder : public StackObj { } void print_stats(int ro_all, int rw_all, int mc_all); + static intx _buffer_to_target_delta; }; #endif // SHARE_MEMORY_ARCHIVEBUILDER_HPP diff --git a/src/hotspot/share/memory/dynamicArchive.cpp b/src/hotspot/share/memory/dynamicArchive.cpp index 5703e6e52981b..737a663f7817e 100644 --- a/src/hotspot/share/memory/dynamicArchive.cpp +++ b/src/hotspot/share/memory/dynamicArchive.cpp @@ -44,8 +44,6 @@ class DynamicArchiveBuilder : public ArchiveBuilder { public: - static intx _buffer_to_target_delta; - DumpRegion* _current_dump_space; static size_t reserve_alignment() { return os::vm_allocation_granularity(); @@ -59,32 +57,6 @@ class DynamicArchiveBuilder : public ArchiveBuilder { ArchivePtrMarker::mark_pointer(ptr_loc); } - DumpRegion* current_dump_space() const { - return _current_dump_space; - } - - bool is_in_buffer_space(address p) const { - return (_alloc_bottom <= p && p < (address)current_dump_space()->top()); - } - - template bool is_in_target_space(T target_obj) const { - address buff_obj = address(target_obj) - _buffer_to_target_delta; - return is_in_buffer_space(buff_obj); - } - - template bool is_in_buffer_space(T obj) const { - return is_in_buffer_space(address(obj)); - } - - template T to_target_no_check(T obj) const { - return (T)(address(obj) + _buffer_to_target_delta); - } - - template T to_target(T obj) const { - assert(is_in_buffer_space(obj), "must be"); - return (T)(address(obj) + _buffer_to_target_delta); - } - template T get_dumped_addr(T obj) { return (T)ArchiveBuilder::get_dumped_addr((address)obj); } @@ -113,7 +85,6 @@ class DynamicArchiveBuilder : public ArchiveBuilder { public: DynamicArchiveHeader *_header; - address _alloc_bottom; address _last_verified_top; size_t _other_region_used_bytes; @@ -128,7 +99,7 @@ class DynamicArchiveBuilder : public ArchiveBuilder { void init_header(address addr); void release_header(); void make_trampolines(); - void make_klasses_shareable(); + void sort_methods(); void sort_methods(InstanceKlass* ik) const; void remark_pointers_for_instance_klass(InstanceKlass* k, bool should_mark) const; void relocate_buffer_to_target(); @@ -250,6 +221,7 @@ class DynamicArchiveBuilder : public ArchiveBuilder { verify_estimate_size(_estimated_hashtable_bytes, "Hashtables"); make_trampolines(); + sort_methods(); log_info(cds)("Make classes shareable"); make_klasses_shareable(); @@ -275,8 +247,6 @@ class DynamicArchiveBuilder : public ArchiveBuilder { } }; -intx DynamicArchiveBuilder::_buffer_to_target_delta; - size_t DynamicArchiveBuilder::estimate_archive_size() { // size of the symbol table and two dictionaries, plus the RunTimeSharedClassInfo's _estimated_hashtable_bytes = 0; @@ -408,35 +378,14 @@ void DynamicArchiveBuilder::make_trampolines() { guarantee(p <= mc_space->top(), "Estimate of trampoline size is insufficient"); } -void DynamicArchiveBuilder::make_klasses_shareable() { - int i, count = klasses()->length(); - +void DynamicArchiveBuilder::sort_methods() { InstanceKlass::disable_method_binary_search(); - for (i = 0; i < count; i++) { + for (int i = 0; i < klasses()->length(); i++) { Klass* k = klasses()->at(i); if (k->is_instance_klass()) { sort_methods(InstanceKlass::cast(k)); } } - - for (i = 0; i < count; i++) { - Klass* k = klasses()->at(i); - if (!k->is_instance_klass()) { - continue; - } - InstanceKlass* ik = InstanceKlass::cast(k); - ik->assign_class_loader_type(); - - MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread::current(), ik); - ik->remove_unshareable_info(); - - assert(ik->array_klasses() == NULL, "sanity"); - - if (log_is_enabled(Debug, cds, dynamic)) { - ResourceMark rm; - log_debug(cds, dynamic)("klasses[%4i] = " PTR_FORMAT " %s", i, p2i(to_target(ik)), ik->external_name()); - } - } } // The address order of the copied Symbols may be different than when the original diff --git a/src/hotspot/share/memory/heapShared.cpp b/src/hotspot/share/memory/heapShared.cpp index dfd398db1388f..905d1aef56c92 100644 --- a/src/hotspot/share/memory/heapShared.cpp +++ b/src/hotspot/share/memory/heapShared.cpp @@ -36,6 +36,7 @@ #include "logging/log.hpp" #include "logging/logMessage.hpp" #include "logging/logStream.hpp" +#include "memory/archiveBuilder.hpp" #include "memory/archiveUtils.hpp" #include "memory/filemap.hpp" #include "memory/heapShared.inline.hpp" @@ -398,7 +399,7 @@ void KlassSubGraphInfo::add_subgraph_object_klass(Klass* orig_k, Klass *relocate new(ResourceObj::C_HEAP, mtClass) GrowableArray(50, mtClass); } - assert(relocated_k->is_shared(), "must be a shared class"); + assert(ArchiveBuilder::singleton()->is_in_buffer_space(relocated_k), "must be a shared class"); if (_k == relocated_k) { // Don't add the Klass containing the sub-graph to it's own klass diff --git a/src/hotspot/share/memory/metaspaceShared.cpp b/src/hotspot/share/memory/metaspaceShared.cpp index c80e1b108b9c9..9fa221a921c87 100644 --- a/src/hotspot/share/memory/metaspaceShared.cpp +++ b/src/hotspot/share/memory/metaspaceShared.cpp @@ -544,30 +544,6 @@ GrowableArray* MetaspaceShared::collected_klasses() { return _global_klass_objects; } -static void remove_unshareable_in_classes() { - for (int i = 0; i < _global_klass_objects->length(); i++) { - Klass* k = _global_klass_objects->at(i); - if (!k->is_objArray_klass()) { - // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info - // on their array classes. - assert(k->is_instance_klass() || k->is_typeArray_klass(), "must be"); - k->remove_unshareable_info(); - } - } -} - -static void remove_java_mirror_in_classes() { - for (int i = 0; i < _global_klass_objects->length(); i++) { - Klass* k = _global_klass_objects->at(i); - if (!k->is_objArray_klass()) { - // InstanceKlass and TypeArrayKlass will in turn call remove_unshareable_info - // on their array classes. - assert(k->is_instance_klass() || k->is_typeArray_klass(), "must be"); - k->remove_java_mirror(); - } - } -} - static void rewrite_nofast_bytecode(const methodHandle& method) { BytecodeStream bcs(method); while (!bcs.is_last_bytecode()) { @@ -587,21 +563,9 @@ static void rewrite_nofast_bytecode(const methodHandle& method) { } } -// Walk all methods in the class list to ensure that they won't be modified at -// run time. This includes: // [1] Rewrite all bytecodes as needed, so that the ConstMethod* will not be modified // at run time by RewriteBytecodes/RewriteFrequentPairs // [2] Assign a fingerprint, so one doesn't need to be assigned at run-time. -static void rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread) { - for (int i = 0; i < _global_klass_objects->length(); i++) { - Klass* k = _global_klass_objects->at(i); - if (k->is_instance_klass()) { - InstanceKlass* ik = InstanceKlass::cast(k); - MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(thread, ik); - } - } -} - void MetaspaceShared::rewrite_nofast_bytecodes_and_calculate_fingerprints(Thread* thread, InstanceKlass* ik) { for (int i = 0; i < ik->methods()->length(); i++) { methodHandle m(thread, ik->methods()->at(i)); @@ -645,7 +609,10 @@ class VM_PopulateDumpSharedSpace: public VM_Operation { class StaticArchiveBuilder : public ArchiveBuilder { public: StaticArchiveBuilder(DumpRegion* rw_region, DumpRegion* ro_region) - : ArchiveBuilder(rw_region, ro_region) {} + : ArchiveBuilder(rw_region, ro_region) { + _alloc_bottom = address(SharedBaseAddress); + _buffer_to_target_delta = 0; + } virtual void iterate_roots(MetaspaceClosure* it, bool is_relocating_pointers) { FileMapInfo::metaspace_pointers_do(it, false); @@ -669,13 +636,6 @@ class StaticArchiveBuilder : public ArchiveBuilder { char* VM_PopulateDumpSharedSpace::dump_read_only_tables() { ArchiveBuilder::OtherROAllocMark mark; - log_info(cds)("Removing java_mirror ... "); - if (!HeapShared::is_heap_object_archiving_allowed()) { - Universe::clear_basic_type_mirrors(); - } - remove_java_mirror_in_classes(); - log_info(cds)("done. "); - SystemDictionaryShared::write_to_archive(); // Write the other data to the output array. @@ -765,19 +725,10 @@ void VM_PopulateDumpSharedSpace::doit() { SystemDictionaryShared::check_excluded_classes(); StaticArchiveBuilder builder(&_rw_region, &_ro_region); + builder.set_current_dump_space(&_mc_region); builder.gather_klasses_and_symbols(); _global_klass_objects = builder.klasses(); - // Ensure the ConstMethods won't be modified at run-time - log_info(cds)("Updating ConstMethods ... "); - rewrite_nofast_bytecodes_and_calculate_fingerprints(THREAD); - log_info(cds)("done. "); - - // Remove all references outside the metadata - log_info(cds)("Removing unshareable information ... "); - remove_unshareable_in_classes(); - log_info(cds)("done. "); - builder.gather_source_objs(); CppVtables::allocate_cloned_cpp_vtptrs(); @@ -786,6 +737,7 @@ void VM_PopulateDumpSharedSpace::doit() { { _mc_region.pack(&_rw_region); + builder.set_current_dump_space(&_rw_region); builder.dump_rw_region(); #if INCLUDE_CDS_JAVA_HEAP if (MetaspaceShared::use_full_module_graph()) { @@ -798,6 +750,7 @@ void VM_PopulateDumpSharedSpace::doit() { } { _rw_region.pack(&_ro_region); + builder.set_current_dump_space(&_ro_region); builder.dump_ro_region(); #if INCLUDE_CDS_JAVA_HEAP if (MetaspaceShared::use_full_module_graph()) { @@ -818,6 +771,9 @@ void VM_PopulateDumpSharedSpace::doit() { builder.relocate_well_known_klasses(); + log_info(cds)("Make classes shareable"); + builder.make_klasses_shareable(); + char* serialized_data = dump_read_only_tables(); _ro_region.pack(); @@ -871,9 +827,9 @@ void VM_PopulateDumpSharedSpace::doit() { "for testing purposes only and should not be used in a production environment"); } - // There may be other pending VM operations that operate on the InstanceKlasses, - // which will fail because InstanceKlasses::remove_unshareable_info() - // has been called. Forget these operations and exit the VM directly. + // There may be pending VM operations. We have changed some global states + // (such as SystemDictionary::_well_known_klasses) that may cause these VM operations + // to fail. For safety, forget these operations and exit the VM directly. vm_direct_exit(0); } diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index 69b800bc2686e..a96b1f631d3e9 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -185,15 +185,6 @@ void Universe::replace_mirror(BasicType t, oop new_mirror) { Universe::_mirrors[t].replace(new_mirror); } -// Not sure why CDS has to do this -void Universe::clear_basic_type_mirrors() { - for (int i = T_BOOLEAN; i < T_VOID+1; i++) { - if (!is_reference_type((BasicType)i)) { - Universe::_mirrors[i].replace(NULL); - } - } -} - void Universe::basic_type_classes_do(void f(Klass*)) { for (int i = T_BOOLEAN; i < T_LONG+1; i++) { f(_typeArrayKlassObjs[i]); @@ -245,7 +236,11 @@ void Universe::serialize(SerializeClosure* f) { _mirrors[i] = OopHandle(vm_global(), mirror_oop); } } else { - mirror_oop = _mirrors[i].resolve(); + if (HeapShared::is_heap_object_archiving_allowed()) { + mirror_oop = _mirrors[i].resolve(); + } else { + mirror_oop = NULL; + } f->do_oop(&mirror_oop); // write to archive } if (mirror_oop != NULL) { // may be null if archived heap is disabled diff --git a/src/hotspot/share/memory/universe.hpp b/src/hotspot/share/memory/universe.hpp index 42b3e635ebbd8..2925c055eeb2f 100644 --- a/src/hotspot/share/memory/universe.hpp +++ b/src/hotspot/share/memory/universe.hpp @@ -232,7 +232,6 @@ class Universe: AllStatic { static oop java_mirror(BasicType t); static void replace_mirror(BasicType t, oop obj); - static void clear_basic_type_mirrors(); static oop main_thread_group(); static void set_main_thread_group(oop group); diff --git a/src/hotspot/share/oops/constantPool.cpp b/src/hotspot/share/oops/constantPool.cpp index f76a75fba4eed..922584e6c2d05 100644 --- a/src/hotspot/share/oops/constantPool.cpp +++ b/src/hotspot/share/oops/constantPool.cpp @@ -283,7 +283,6 @@ void ConstantPool::archive_resolved_references(Thread* THREAD) { ik->is_shared_app_class())) { // Archiving resolved references for classes from non-builtin loaders // is not yet supported. - set_resolved_references(OopHandle()); return; } @@ -316,7 +315,6 @@ void ConstantPool::archive_resolved_references(Thread* THREAD) { // resolved references will be created using the normal process // when there is no archived value. _cache->set_archived_references(archived); - set_resolved_references(OopHandle()); } } @@ -396,15 +394,7 @@ void ConstantPool::remove_unshareable_info() { // at runtime. set_resolved_reference_length( resolved_references() != NULL ? resolved_references()->length() : 0); - - // If archiving heap objects is not allowed, clear the resolved references. - // Otherwise, it is cleared after the resolved references array is cached - // (see archive_resolved_references()). - // If DynamicDumpSharedSpaces is enabled, clear the resolved references also - // as java objects are not archived in the top layer. - if (!HeapShared::is_heap_object_archiving_allowed() || DynamicDumpSharedSpaces) { - set_resolved_references(OopHandle()); - } + set_resolved_references(OopHandle()); // Shared ConstantPools are in the RO region, so the _flags cannot be modified. // The _on_stack flag is used to prevent ConstantPools from deallocation during From 24a424891caf2af73c283861190aa220d428b9d9 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Thu, 24 Sep 2020 22:29:25 +0000 Subject: [PATCH 07/79] 8253615: Change to Visual Studio 2019 16.7.2 for building on Windows at Oracle Reviewed-by: mikael --- doc/building.html | 2 +- doc/building.md | 2 +- make/conf/jib-profiles.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/building.html b/doc/building.html index fee88e2748920..55a434305386a 100644 --- a/doc/building.html +++ b/doc/building.html @@ -273,7 +273,7 @@

Native Compiler (Toolchain) Requ Windows -Microsoft Visual Studio 2019 update 16.5.3 +Microsoft Visual Studio 2019 update 16.7.2 diff --git a/doc/building.md b/doc/building.md index 539602036405e..0f3ce6e12e2d3 100644 --- a/doc/building.md +++ b/doc/building.md @@ -304,7 +304,7 @@ issues. ------------------ ------------------------------------------------------- Linux gcc 9.2.0 macOS Apple Xcode 10.1 (using clang 10.0.0) - Windows Microsoft Visual Studio 2019 update 16.5.3 + Windows Microsoft Visual Studio 2019 update 16.7.2 All compilers are expected to be able to compile to the C99 language standard, as some C99 features are used in the source code. Microsoft Visual Studio diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js index 36abc0a0ff4b1..a186c77168683 100644 --- a/make/conf/jib-profiles.js +++ b/make/conf/jib-profiles.js @@ -961,7 +961,7 @@ var getJibProfilesDependencies = function (input, common) { var devkit_platform_revisions = { linux_x64: "gcc9.2.0-OL6.4+1.0", macosx_x64: "Xcode11.3.1-MacOSX10.15+1.0", - windows_x64: "VS2019-16.5.3+1.0", + windows_x64: "VS2019-16.7.2+1.0", linux_aarch64: "gcc9.2.0-OL7.6+1.0", linux_arm: "gcc8.2.0-Fedora27+1.0", linux_ppc64le: "gcc8.2.0-Fedora27+1.0", From 8239b67d4f1dcbd063a78286a55aafc7c80aeb4f Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Thu, 24 Sep 2020 22:48:28 +0000 Subject: [PATCH 08/79] 8253322: Update the specification in the newly added constructors Reviewed-by: psadhukhan, prr --- .../share/classes/java/applet/Applet.java | 4 ++-- .../share/classes/java/awt/Button.java | 4 ++-- .../share/classes/java/awt/Canvas.java | 4 ++-- .../share/classes/java/awt/CheckboxMenuItem.java | 4 ++-- .../share/classes/java/awt/Component.java | 4 ++-- .../share/classes/java/awt/Container.java | 6 +++--- .../share/classes/java/awt/Dialog.java | 4 ++-- .../share/classes/java/awt/Frame.java | 4 ++-- src/java.desktop/share/classes/java/awt/Menu.java | 4 ++-- .../share/classes/java/awt/MenuBar.java | 4 ++-- .../share/classes/java/awt/MenuItem.java | 4 ++-- .../share/classes/java/awt/Panel.java | 4 ++-- .../share/classes/java/awt/PopupMenu.java | 4 ++-- .../share/classes/java/awt/ScrollPane.java | 4 ++-- .../share/classes/java/awt/Scrollbar.java | 4 ++-- .../share/classes/java/awt/TextArea.java | 4 ++-- .../share/classes/java/awt/TextField.java | 4 ++-- .../share/classes/java/awt/Window.java | 2 +- .../javax/sound/midi/spi/MidiDeviceProvider.java | 2 +- .../javax/sound/midi/spi/MidiFileReader.java | 2 +- .../javax/sound/midi/spi/MidiFileWriter.java | 2 +- .../javax/sound/midi/spi/SoundbankReader.java | 2 +- .../javax/sound/sampled/spi/AudioFileReader.java | 2 +- .../javax/sound/sampled/spi/AudioFileWriter.java | 2 +- .../sampled/spi/FormatConversionProvider.java | 2 +- .../javax/sound/sampled/spi/MixerProvider.java | 2 +- .../share/classes/javax/swing/Box.java | 8 +++++--- .../classes/javax/swing/CellRendererPane.java | 5 +++-- .../classes/javax/swing/DefaultCellEditor.java | 4 ++-- .../share/classes/javax/swing/ImageIcon.java | 4 ++-- .../share/classes/javax/swing/JApplet.java | 5 +++-- .../share/classes/javax/swing/JButton.java | 4 ++-- .../share/classes/javax/swing/JCheckBox.java | 4 ++-- .../classes/javax/swing/JCheckBoxMenuItem.java | 5 +++-- .../share/classes/javax/swing/JColorChooser.java | 4 ++-- .../share/classes/javax/swing/JComponent.java | 7 ++++--- .../share/classes/javax/swing/JDesktopPane.java | 4 ++-- .../share/classes/javax/swing/JDialog.java | 4 ++-- .../share/classes/javax/swing/JEditorPane.java | 4 ++-- .../share/classes/javax/swing/JFileChooser.java | 2 +- .../share/classes/javax/swing/JFrame.java | 4 ++-- .../share/classes/javax/swing/JInternalFrame.java | 6 +++--- .../share/classes/javax/swing/JLabel.java | 4 ++-- .../share/classes/javax/swing/JLayeredPane.java | 4 ++-- .../share/classes/javax/swing/JMenu.java | 4 ++-- .../share/classes/javax/swing/JMenuBar.java | 4 ++-- .../share/classes/javax/swing/JOptionPane.java | 4 ++-- .../share/classes/javax/swing/JPanel.java | 5 +++-- .../share/classes/javax/swing/JPasswordField.java | 4 ++-- .../share/classes/javax/swing/JProgressBar.java | 4 ++-- .../share/classes/javax/swing/JRadioButton.java | 4 ++-- .../classes/javax/swing/JRadioButtonMenuItem.java | 5 +++-- .../share/classes/javax/swing/JRootPane.java | 7 ++++--- .../share/classes/javax/swing/JScrollBar.java | 4 ++-- .../share/classes/javax/swing/JSeparator.java | 4 ++-- .../share/classes/javax/swing/JSplitPane.java | 5 +++-- .../share/classes/javax/swing/JTabbedPane.java | 5 +++-- .../share/classes/javax/swing/JTextArea.java | 4 ++-- .../share/classes/javax/swing/JTextField.java | 4 ++-- .../share/classes/javax/swing/JToolBar.java | 4 ++-- .../share/classes/javax/swing/JToolTip.java | 4 ++-- .../share/classes/javax/swing/JTree.java | 15 ++++++++------- .../share/classes/javax/swing/JViewport.java | 6 +++--- .../share/classes/javax/swing/JWindow.java | 4 ++-- .../share/classes/javax/swing/ToolTipManager.java | 11 +++++++---- .../classes/javax/swing/table/JTableHeader.java | 4 ++-- .../classes/javax/swing/text/html/FormView.java | 4 ++-- 67 files changed, 152 insertions(+), 137 deletions(-) diff --git a/src/java.desktop/share/classes/java/applet/Applet.java b/src/java.desktop/share/classes/java/applet/Applet.java index 42abb0bd25871..1592bee3f87fb 100644 --- a/src/java.desktop/share/classes/java/applet/Applet.java +++ b/src/java.desktop/share/classes/java/applet/Applet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -579,7 +579,7 @@ protected class AccessibleApplet extends AccessibleAWTPanel { private static final long serialVersionUID = 8127374778187708896L; /** - * Constructs an {@code AccessibleApplet} + * Constructs an {@code AccessibleApplet}. */ protected AccessibleApplet() {} diff --git a/src/java.desktop/share/classes/java/awt/Button.java b/src/java.desktop/share/classes/java/awt/Button.java index 89419f7e4eecd..c4b44effb5c3b 100644 --- a/src/java.desktop/share/classes/java/awt/Button.java +++ b/src/java.desktop/share/classes/java/awt/Button.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -538,7 +538,7 @@ protected class AccessibleAWTButton extends AccessibleAWTComponent private static final long serialVersionUID = -5932203980244017102L; /** - * Constructs an {@code AccessibleAWTButton} + * Constructs an {@code AccessibleAWTButton}. */ protected AccessibleAWTButton() {} diff --git a/src/java.desktop/share/classes/java/awt/Canvas.java b/src/java.desktop/share/classes/java/awt/Canvas.java index 0af731061d49e..079487097fa5d 100644 --- a/src/java.desktop/share/classes/java/awt/Canvas.java +++ b/src/java.desktop/share/classes/java/awt/Canvas.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -241,7 +241,7 @@ protected class AccessibleAWTCanvas extends AccessibleAWTComponent private static final long serialVersionUID = -6325592262103146699L; /** - * Constructs an {@code AccessibleAWTCanvas} + * Constructs an {@code AccessibleAWTCanvas}. */ protected AccessibleAWTCanvas() {} diff --git a/src/java.desktop/share/classes/java/awt/CheckboxMenuItem.java b/src/java.desktop/share/classes/java/awt/CheckboxMenuItem.java index e0e7eb7db3261..c7f164cc40b6d 100644 --- a/src/java.desktop/share/classes/java/awt/CheckboxMenuItem.java +++ b/src/java.desktop/share/classes/java/awt/CheckboxMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -537,7 +537,7 @@ protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem private static final long serialVersionUID = -1122642964303476L; /** - * Constructs an {@code AccessibleAWTCheckboxMenuItem} + * Constructs an {@code AccessibleAWTCheckboxMenuItem}. */ protected AccessibleAWTCheckboxMenuItem() {} diff --git a/src/java.desktop/share/classes/java/awt/Component.java b/src/java.desktop/share/classes/java/awt/Component.java index 2a2ff4d7aa82e..7b63b1b111c5e 100644 --- a/src/java.desktop/share/classes/java/awt/Component.java +++ b/src/java.desktop/share/classes/java/awt/Component.java @@ -9342,7 +9342,7 @@ protected class AccessibleAWTComponentHandler implements ComponentListener, Seri private static final long serialVersionUID = -1009684107426231869L; /** - * Constructs an {@code AccessibleAWTComponentHandler} + * Constructs an {@code AccessibleAWTComponentHandler}. */ protected AccessibleAWTComponentHandler() {} @@ -9379,7 +9379,7 @@ protected class AccessibleAWTFocusHandler implements FocusListener, Serializable private static final long serialVersionUID = 3150908257351582233L; /** - * Constructs an {@code AccessibleAWTFocusHandler} + * Constructs an {@code AccessibleAWTFocusHandler}. */ protected AccessibleAWTFocusHandler() {} diff --git a/src/java.desktop/share/classes/java/awt/Container.java b/src/java.desktop/share/classes/java/awt/Container.java index c91da6de7bfb5..b93b0d8bfd1b0 100644 --- a/src/java.desktop/share/classes/java/awt/Container.java +++ b/src/java.desktop/share/classes/java/awt/Container.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -3807,7 +3807,7 @@ protected class AccessibleAWTContainer extends AccessibleAWTComponent { private static final long serialVersionUID = 5081320404842566097L; /** - * Constructs an {@code AccessibleAWTContainer} + * Constructs an {@code AccessibleAWTContainer}. */ protected AccessibleAWTContainer() {} @@ -3869,7 +3869,7 @@ protected class AccessibleContainerHandler private static final long serialVersionUID = -480855353991814677L; /** - * Constructs an {@code AccessibleContainerHandler} + * Constructs an {@code AccessibleContainerHandler}. */ protected AccessibleContainerHandler() {} diff --git a/src/java.desktop/share/classes/java/awt/Dialog.java b/src/java.desktop/share/classes/java/awt/Dialog.java index 6c9926c17a4e9..3954d1bd5656c 100644 --- a/src/java.desktop/share/classes/java/awt/Dialog.java +++ b/src/java.desktop/share/classes/java/awt/Dialog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -1659,7 +1659,7 @@ protected class AccessibleAWTDialog extends AccessibleAWTWindow private static final long serialVersionUID = 4837230331833941201L; /** - * Constructs an {@code AccessibleAWTDialog} + * Constructs an {@code AccessibleAWTDialog}. */ protected AccessibleAWTDialog() {} diff --git a/src/java.desktop/share/classes/java/awt/Frame.java b/src/java.desktop/share/classes/java/awt/Frame.java index a6d568f422a78..10f9a2f4e8ee8 100644 --- a/src/java.desktop/share/classes/java/awt/Frame.java +++ b/src/java.desktop/share/classes/java/awt/Frame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -1298,7 +1298,7 @@ protected class AccessibleAWTFrame extends AccessibleAWTWindow private static final long serialVersionUID = -6172960752956030250L; /** - * Constructs an {@code AccessibleAWTFrame} + * Constructs an {@code AccessibleAWTFrame}. */ protected AccessibleAWTFrame() {} diff --git a/src/java.desktop/share/classes/java/awt/Menu.java b/src/java.desktop/share/classes/java/awt/Menu.java index 1c308997022c3..b98692b3e69aa 100644 --- a/src/java.desktop/share/classes/java/awt/Menu.java +++ b/src/java.desktop/share/classes/java/awt/Menu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -625,7 +625,7 @@ protected class AccessibleAWTMenu extends AccessibleAWTMenuItem private static final long serialVersionUID = 5228160894980069094L; /** - * Constructs an {@code AccessibleAWTMenu} + * Constructs an {@code AccessibleAWTMenu}. */ protected AccessibleAWTMenu() {} diff --git a/src/java.desktop/share/classes/java/awt/MenuBar.java b/src/java.desktop/share/classes/java/awt/MenuBar.java index cc1072f6b7590..76f738b046205 100644 --- a/src/java.desktop/share/classes/java/awt/MenuBar.java +++ b/src/java.desktop/share/classes/java/awt/MenuBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -512,7 +512,7 @@ protected class AccessibleAWTMenuBar extends AccessibleAWTMenuComponent private static final long serialVersionUID = -8577604491830083815L; /** - * Constructs an {@code AccessibleAWTMenuBar} + * Constructs an {@code AccessibleAWTMenuBar}. */ protected AccessibleAWTMenuBar() {} diff --git a/src/java.desktop/share/classes/java/awt/MenuItem.java b/src/java.desktop/share/classes/java/awt/MenuItem.java index 3b1ddbb961c2e..d9e6e7afb327e 100644 --- a/src/java.desktop/share/classes/java/awt/MenuItem.java +++ b/src/java.desktop/share/classes/java/awt/MenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -824,7 +824,7 @@ protected class AccessibleAWTMenuItem extends AccessibleAWTMenuComponent private static final long serialVersionUID = -217847831945965825L; /** - * Constructs an {@code AccessibleAWTMenuItem} + * Constructs an {@code AccessibleAWTMenuItem}. */ protected AccessibleAWTMenuItem() {} diff --git a/src/java.desktop/share/classes/java/awt/Panel.java b/src/java.desktop/share/classes/java/awt/Panel.java index cc2107687d4b0..036ca64028b53 100644 --- a/src/java.desktop/share/classes/java/awt/Panel.java +++ b/src/java.desktop/share/classes/java/awt/Panel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -120,7 +120,7 @@ protected class AccessibleAWTPanel extends AccessibleAWTContainer { private static final long serialVersionUID = -6409552226660031050L; /** - * Constructs an {@code AccessibleAWTPanel} + * Constructs an {@code AccessibleAWTPanel}. */ protected AccessibleAWTPanel() {} diff --git a/src/java.desktop/share/classes/java/awt/PopupMenu.java b/src/java.desktop/share/classes/java/awt/PopupMenu.java index a5cc04a345620..40f1904399aae 100644 --- a/src/java.desktop/share/classes/java/awt/PopupMenu.java +++ b/src/java.desktop/share/classes/java/awt/PopupMenu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2020, 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 @@ -229,7 +229,7 @@ protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu private static final long serialVersionUID = -4282044795947239955L; /** - * Constructs an {@code AccessibleAWTPopupMenu} + * Constructs an {@code AccessibleAWTPopupMenu}. */ protected AccessibleAWTPopupMenu() {} diff --git a/src/java.desktop/share/classes/java/awt/ScrollPane.java b/src/java.desktop/share/classes/java/awt/ScrollPane.java index 28634f2d7f5bc..99ed72ead2147 100644 --- a/src/java.desktop/share/classes/java/awt/ScrollPane.java +++ b/src/java.desktop/share/classes/java/awt/ScrollPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2020, 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 @@ -792,7 +792,7 @@ protected class AccessibleAWTScrollPane extends AccessibleAWTContainer private static final long serialVersionUID = 6100703663886637L; /** - * Constructs an {@code AccessibleAWTScrollPane} + * Constructs an {@code AccessibleAWTScrollPane}. */ protected AccessibleAWTScrollPane() {} diff --git a/src/java.desktop/share/classes/java/awt/Scrollbar.java b/src/java.desktop/share/classes/java/awt/Scrollbar.java index 3e4ffca3cd2bd..98da483bf66b2 100644 --- a/src/java.desktop/share/classes/java/awt/Scrollbar.java +++ b/src/java.desktop/share/classes/java/awt/Scrollbar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -1263,7 +1263,7 @@ protected class AccessibleAWTScrollBar extends AccessibleAWTComponent private static final long serialVersionUID = -344337268523697807L; /** - * Constructs an {@code AccessibleAWTScrollBar} + * Constructs an {@code AccessibleAWTScrollBar}. */ protected AccessibleAWTScrollBar() {} diff --git a/src/java.desktop/share/classes/java/awt/TextArea.java b/src/java.desktop/share/classes/java/awt/TextArea.java index b8bceb590bbfe..9bbbeed6554f5 100644 --- a/src/java.desktop/share/classes/java/awt/TextArea.java +++ b/src/java.desktop/share/classes/java/awt/TextArea.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -720,7 +720,7 @@ protected class AccessibleAWTTextArea extends AccessibleAWTTextComponent private static final long serialVersionUID = 3472827823632144419L; /** - * Constructs an {@code AccessibleAWTTextArea} + * Constructs an {@code AccessibleAWTTextArea}. */ protected AccessibleAWTTextArea() {} diff --git a/src/java.desktop/share/classes/java/awt/TextField.java b/src/java.desktop/share/classes/java/awt/TextField.java index 029856d0d936d..0c3d45ad3183b 100644 --- a/src/java.desktop/share/classes/java/awt/TextField.java +++ b/src/java.desktop/share/classes/java/awt/TextField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2020, 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 @@ -789,7 +789,7 @@ protected class AccessibleAWTTextField extends AccessibleAWTTextComponent private static final long serialVersionUID = 6219164359235943158L; /** - * Constructs an {@code AccessibleAWTTextField} + * Constructs an {@code AccessibleAWTTextField}. */ protected AccessibleAWTTextField() {} diff --git a/src/java.desktop/share/classes/java/awt/Window.java b/src/java.desktop/share/classes/java/awt/Window.java index a3a6e13fb7b10..8acca72fe52ab 100644 --- a/src/java.desktop/share/classes/java/awt/Window.java +++ b/src/java.desktop/share/classes/java/awt/Window.java @@ -3164,7 +3164,7 @@ protected class AccessibleAWTWindow extends AccessibleAWTContainer private static final long serialVersionUID = 4215068635060671780L; /** - * Constructs an {@code AccessibleAWTWindow} + * Constructs an {@code AccessibleAWTWindow}. */ protected AccessibleAWTWindow() {} diff --git a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java index c79f5916a304b..ae3d005c7cd8b 100644 --- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java +++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java @@ -39,7 +39,7 @@ public abstract class MidiDeviceProvider { /** - * Constructs a {@code MidiDeviceProvider}. + * Constructor for subclasses to call. */ protected MidiDeviceProvider() {} diff --git a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java index 6694456c877d8..243251ef7ecf2 100644 --- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java +++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java @@ -46,7 +46,7 @@ public abstract class MidiFileReader { /** - * Constructs a {@code MidiFileReader}. + * Constructor for subclasses to call. */ protected MidiFileReader() {} diff --git a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java index 672da99f32a27..98b45702d18ef 100644 --- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java +++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java @@ -43,7 +43,7 @@ public abstract class MidiFileWriter { /** - * Constructs a {@code MidiFileWriter}. + * Constructor for subclasses to call. */ protected MidiFileWriter() {} diff --git a/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java b/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java index b34c462237486..23dcb3ece79fa 100644 --- a/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java +++ b/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java @@ -45,7 +45,7 @@ public abstract class SoundbankReader { /** - * Constructs a {@code SoundbankReader}. + * Constructor for subclasses to call. */ protected SoundbankReader() {} diff --git a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java index 39475fad07e87..8ff88af3316b5 100644 --- a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java @@ -45,7 +45,7 @@ public abstract class AudioFileReader { /** - * Constructs an {@code AudioFileReader}. + * Constructor for subclasses to call. */ protected AudioFileReader() {} diff --git a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java index 25f3140f57c85..787cfc5ef129f 100644 --- a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java @@ -46,7 +46,7 @@ public abstract class AudioFileWriter { /** - * Constructs an {@code AudioFileWriter}. + * Constructor for subclasses to call. */ protected AudioFileWriter() {} diff --git a/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java b/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java index 803f7a2c554bd..e7058fc627364 100644 --- a/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java @@ -52,7 +52,7 @@ public abstract class FormatConversionProvider { /** - * Constructs a {@code FormatConversionProvider}. + * Constructor for subclasses to call. */ protected FormatConversionProvider() {} diff --git a/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java b/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java index 4360d90d65ba6..13610d1ae3c70 100644 --- a/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java @@ -40,7 +40,7 @@ public abstract class MixerProvider { /** - * Constructs a {@code MixerProvider}. + * Constructor for subclasses to call. */ protected MixerProvider() {} diff --git a/src/java.desktop/share/classes/javax/swing/Box.java b/src/java.desktop/share/classes/javax/swing/Box.java index 35d1cce327340..1fd81249a95a9 100644 --- a/src/java.desktop/share/classes/javax/swing/Box.java +++ b/src/java.desktop/share/classes/javax/swing/Box.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -384,8 +384,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") protected class AccessibleBoxFiller extends AccessibleAWTComponent { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleBoxFiller}. */ protected AccessibleBoxFiller() {} @@ -431,8 +432,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") protected class AccessibleBox extends AccessibleAWTContainer { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleBox}. */ protected AccessibleBox() {} diff --git a/src/java.desktop/share/classes/javax/swing/CellRendererPane.java b/src/java.desktop/share/classes/javax/swing/CellRendererPane.java index f5db762d7603d..67e8b59ccd14f 100644 --- a/src/java.desktop/share/classes/javax/swing/CellRendererPane.java +++ b/src/java.desktop/share/classes/javax/swing/CellRendererPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -244,8 +244,9 @@ public AccessibleContext getAccessibleContext() { * CellRendererPane class. */ protected class AccessibleCellRendererPane extends AccessibleAWTContainer { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleCellRendererPane}. */ protected AccessibleCellRendererPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/DefaultCellEditor.java b/src/java.desktop/share/classes/javax/swing/DefaultCellEditor.java index 1cd40fc4bfabd..0001dfa6c297b 100644 --- a/src/java.desktop/share/classes/javax/swing/DefaultCellEditor.java +++ b/src/java.desktop/share/classes/javax/swing/DefaultCellEditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -304,7 +304,7 @@ protected class EditorDelegate implements ActionListener, ItemListener, Serializ protected Object value; /** - * Constructor for subclasses to call. + * Constructs an {@code EditorDelegate}. */ protected EditorDelegate() {} diff --git a/src/java.desktop/share/classes/javax/swing/ImageIcon.java b/src/java.desktop/share/classes/javax/swing/ImageIcon.java index da3f6bedeaccd..c790a5f35e40f 100644 --- a/src/java.desktop/share/classes/javax/swing/ImageIcon.java +++ b/src/java.desktop/share/classes/javax/swing/ImageIcon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -597,7 +597,7 @@ protected class AccessibleImageIcon extends AccessibleContext implements AccessibleIcon, Serializable { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleImageIcon}. */ protected AccessibleImageIcon() {} diff --git a/src/java.desktop/share/classes/javax/swing/JApplet.java b/src/java.desktop/share/classes/javax/swing/JApplet.java index 7770056b9b944..59adfba696d0c 100644 --- a/src/java.desktop/share/classes/javax/swing/JApplet.java +++ b/src/java.desktop/share/classes/javax/swing/JApplet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -566,8 +566,9 @@ public AccessibleContext getAccessibleContext() { * JApplet class. */ protected class AccessibleJApplet extends AccessibleApplet { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJApplet}. */ protected AccessibleJApplet() {} diff --git a/src/java.desktop/share/classes/javax/swing/JButton.java b/src/java.desktop/share/classes/javax/swing/JButton.java index 20ef56a9f1607..0a5c2e2cadc3f 100644 --- a/src/java.desktop/share/classes/javax/swing/JButton.java +++ b/src/java.desktop/share/classes/javax/swing/JButton.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -302,7 +302,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJButton extends AccessibleAbstractButton { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJButton}. */ protected AccessibleJButton() {} diff --git a/src/java.desktop/share/classes/javax/swing/JCheckBox.java b/src/java.desktop/share/classes/javax/swing/JCheckBox.java index 3e6634a8711b9..44112936a2b18 100644 --- a/src/java.desktop/share/classes/javax/swing/JCheckBox.java +++ b/src/java.desktop/share/classes/javax/swing/JCheckBox.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -333,7 +333,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJCheckBox extends AccessibleJToggleButton { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJCheckBox}. */ protected AccessibleJCheckBox() {} diff --git a/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java b/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java index 24d6dd1cec94a..6604e2cbc7d21 100644 --- a/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java +++ b/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -304,8 +304,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJCheckBoxMenuItem}. */ protected AccessibleJCheckBoxMenuItem() {} diff --git a/src/java.desktop/share/classes/javax/swing/JColorChooser.java b/src/java.desktop/share/classes/javax/swing/JColorChooser.java index 83e1a7e4587c6..ae352e25ce990 100644 --- a/src/java.desktop/share/classes/javax/swing/JColorChooser.java +++ b/src/java.desktop/share/classes/javax/swing/JColorChooser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, 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 @@ -600,7 +600,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJColorChooser extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJColorChooser}. */ protected AccessibleJColorChooser() {} diff --git a/src/java.desktop/share/classes/javax/swing/JComponent.java b/src/java.desktop/share/classes/javax/swing/JComponent.java index d835ec619e1df..45190d3319959 100644 --- a/src/java.desktop/share/classes/javax/swing/JComponent.java +++ b/src/java.desktop/share/classes/javax/swing/JComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -3710,8 +3710,9 @@ protected AccessibleJComponent() { */ protected class AccessibleContainerHandler implements ContainerListener { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleContainerHandler}. */ protected AccessibleContainerHandler() {} public void componentAdded(ContainerEvent e) { @@ -3743,7 +3744,7 @@ public void componentRemoved(ContainerEvent e) { @Deprecated protected class AccessibleFocusHandler implements FocusListener { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleFocusHandler}. */ protected AccessibleFocusHandler() {} public void focusGained(FocusEvent event) { diff --git a/src/java.desktop/share/classes/javax/swing/JDesktopPane.java b/src/java.desktop/share/classes/javax/swing/JDesktopPane.java index 0c5f488fbe40b..df9f5d19f7182 100644 --- a/src/java.desktop/share/classes/javax/swing/JDesktopPane.java +++ b/src/java.desktop/share/classes/javax/swing/JDesktopPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -628,7 +628,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJDesktopPane extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJDesktopPane}. */ protected AccessibleJDesktopPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JDialog.java b/src/java.desktop/share/classes/javax/swing/JDialog.java index 147bb723d6c16..522c8dae0a005 100644 --- a/src/java.desktop/share/classes/javax/swing/JDialog.java +++ b/src/java.desktop/share/classes/javax/swing/JDialog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1239,7 +1239,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJDialog extends AccessibleAWTDialog { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJDialog}. */ protected AccessibleJDialog() {} diff --git a/src/java.desktop/share/classes/javax/swing/JEditorPane.java b/src/java.desktop/share/classes/javax/swing/JEditorPane.java index d222460e7de4b..ff965f7dd8f79 100644 --- a/src/java.desktop/share/classes/javax/swing/JEditorPane.java +++ b/src/java.desktop/share/classes/javax/swing/JEditorPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1660,7 +1660,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJEditorPane extends AccessibleJTextComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJEditorPane}. */ protected AccessibleJEditorPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JFileChooser.java b/src/java.desktop/share/classes/javax/swing/JFileChooser.java index 16c52873b0c5d..56a456b977991 100644 --- a/src/java.desktop/share/classes/javax/swing/JFileChooser.java +++ b/src/java.desktop/share/classes/javax/swing/JFileChooser.java @@ -2042,7 +2042,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJFileChooser extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJFileChooser}. */ protected AccessibleJFileChooser() {} diff --git a/src/java.desktop/share/classes/javax/swing/JFrame.java b/src/java.desktop/share/classes/javax/swing/JFrame.java index a25b1a31a495a..a87f10ec9b72a 100644 --- a/src/java.desktop/share/classes/javax/swing/JFrame.java +++ b/src/java.desktop/share/classes/javax/swing/JFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -883,7 +883,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJFrame extends AccessibleAWTFrame { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJFrame}. */ protected AccessibleJFrame() {} diff --git a/src/java.desktop/share/classes/javax/swing/JInternalFrame.java b/src/java.desktop/share/classes/javax/swing/JInternalFrame.java index a8515fe0a5dfb..8ab38c3b6bfd6 100644 --- a/src/java.desktop/share/classes/javax/swing/JInternalFrame.java +++ b/src/java.desktop/share/classes/javax/swing/JInternalFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -2012,7 +2012,7 @@ protected class AccessibleJInternalFrame extends AccessibleJComponent implements AccessibleValue { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJInternalFrame}. */ protected AccessibleJInternalFrame() {} @@ -2308,7 +2308,7 @@ protected class AccessibleJDesktopIcon extends AccessibleJComponent implements AccessibleValue { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJDesktopIcon}. */ protected AccessibleJDesktopIcon() {} diff --git a/src/java.desktop/share/classes/javax/swing/JLabel.java b/src/java.desktop/share/classes/javax/swing/JLabel.java index efe314688593a..7be241df4b0e3 100644 --- a/src/java.desktop/share/classes/javax/swing/JLabel.java +++ b/src/java.desktop/share/classes/javax/swing/JLabel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1044,7 +1044,7 @@ protected class AccessibleJLabel extends AccessibleJComponent implements AccessibleText, AccessibleExtendedComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJLabel}. */ protected AccessibleJLabel() {} diff --git a/src/java.desktop/share/classes/javax/swing/JLayeredPane.java b/src/java.desktop/share/classes/javax/swing/JLayeredPane.java index b42479546db49..4e4f0215f3e0d 100644 --- a/src/java.desktop/share/classes/javax/swing/JLayeredPane.java +++ b/src/java.desktop/share/classes/javax/swing/JLayeredPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -767,7 +767,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJLayeredPane extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJLayeredPane}. */ protected AccessibleJLayeredPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JMenu.java b/src/java.desktop/share/classes/javax/swing/JMenu.java index 9da984684e9df..c3e91e5404922 100644 --- a/src/java.desktop/share/classes/javax/swing/JMenu.java +++ b/src/java.desktop/share/classes/javax/swing/JMenu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1396,7 +1396,7 @@ protected class AccessibleJMenu extends AccessibleJMenuItem implements AccessibleSelection { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJMenu}. */ protected AccessibleJMenu() {} diff --git a/src/java.desktop/share/classes/javax/swing/JMenuBar.java b/src/java.desktop/share/classes/javax/swing/JMenuBar.java index 27f58de299a61..4a42d061b16d7 100644 --- a/src/java.desktop/share/classes/javax/swing/JMenuBar.java +++ b/src/java.desktop/share/classes/javax/swing/JMenuBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -511,7 +511,7 @@ protected class AccessibleJMenuBar extends AccessibleJComponent implements AccessibleSelection { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJMenuBar}. */ protected AccessibleJMenuBar() {} diff --git a/src/java.desktop/share/classes/javax/swing/JOptionPane.java b/src/java.desktop/share/classes/javax/swing/JOptionPane.java index a5367b42f8c74..861d3b6ee6d57 100644 --- a/src/java.desktop/share/classes/javax/swing/JOptionPane.java +++ b/src/java.desktop/share/classes/javax/swing/JOptionPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -2548,7 +2548,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJOptionPane extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJOptionPane}. */ protected AccessibleJOptionPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JPanel.java b/src/java.desktop/share/classes/javax/swing/JPanel.java index 6467f3d5489b3..89fd8a5666514 100644 --- a/src/java.desktop/share/classes/javax/swing/JPanel.java +++ b/src/java.desktop/share/classes/javax/swing/JPanel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -232,8 +232,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJPanel extends AccessibleJComponent { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJPanel}. */ protected AccessibleJPanel() {} diff --git a/src/java.desktop/share/classes/javax/swing/JPasswordField.java b/src/java.desktop/share/classes/javax/swing/JPasswordField.java index 40faaad88e98d..ae90708b72bbd 100644 --- a/src/java.desktop/share/classes/javax/swing/JPasswordField.java +++ b/src/java.desktop/share/classes/javax/swing/JPasswordField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -407,7 +407,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJPasswordField extends AccessibleJTextField { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJPasswordField}. */ protected AccessibleJPasswordField() {} diff --git a/src/java.desktop/share/classes/javax/swing/JProgressBar.java b/src/java.desktop/share/classes/javax/swing/JProgressBar.java index 2635298772b4a..499a110ec3ea3 100644 --- a/src/java.desktop/share/classes/javax/swing/JProgressBar.java +++ b/src/java.desktop/share/classes/javax/swing/JProgressBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1012,7 +1012,7 @@ protected class AccessibleJProgressBar extends AccessibleJComponent implements AccessibleValue { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJProgressBar}. */ protected AccessibleJProgressBar() {} diff --git a/src/java.desktop/share/classes/javax/swing/JRadioButton.java b/src/java.desktop/share/classes/javax/swing/JRadioButton.java index 75880d11f9739..d007a761ddcf4 100644 --- a/src/java.desktop/share/classes/javax/swing/JRadioButton.java +++ b/src/java.desktop/share/classes/javax/swing/JRadioButton.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -286,7 +286,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJRadioButton extends AccessibleJToggleButton { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJRadioButton}. */ protected AccessibleJRadioButton() {} diff --git a/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java b/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java index bfddd2e45d8de..44c44a4e4bfb0 100644 --- a/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java +++ b/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -278,8 +278,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJRadioButtonMenuItem}. */ protected AccessibleJRadioButtonMenuItem() {} diff --git a/src/java.desktop/share/classes/javax/swing/JRootPane.java b/src/java.desktop/share/classes/javax/swing/JRootPane.java index 556e298b2ad60..e191cc6d40523 100644 --- a/src/java.desktop/share/classes/javax/swing/JRootPane.java +++ b/src/java.desktop/share/classes/javax/swing/JRootPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -848,7 +848,7 @@ && getComponent(0) != glassPane) { protected class RootLayout implements LayoutManager2, Serializable { /** - * Constructor for subclasses to call. + * Constructs a {@code RootLayout}. */ protected RootLayout() {} @@ -1017,8 +1017,9 @@ public AccessibleContext getAccessibleContext() { */ @SuppressWarnings("serial") protected class AccessibleJRootPane extends AccessibleJComponent { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJRootPane}. */ protected AccessibleJRootPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JScrollBar.java b/src/java.desktop/share/classes/javax/swing/JScrollBar.java index 3281a0d8fa711..d1051765eec3b 100644 --- a/src/java.desktop/share/classes/javax/swing/JScrollBar.java +++ b/src/java.desktop/share/classes/javax/swing/JScrollBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -856,7 +856,7 @@ protected class AccessibleJScrollBar extends AccessibleJComponent implements AccessibleValue { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJScrollBar}. */ protected AccessibleJScrollBar() {} diff --git a/src/java.desktop/share/classes/javax/swing/JSeparator.java b/src/java.desktop/share/classes/javax/swing/JSeparator.java index b678bfc96e2a3..e554823b7c40e 100644 --- a/src/java.desktop/share/classes/javax/swing/JSeparator.java +++ b/src/java.desktop/share/classes/javax/swing/JSeparator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -278,7 +278,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJSeparator extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJSeparator}. */ protected AccessibleJSeparator() {} diff --git a/src/java.desktop/share/classes/javax/swing/JSplitPane.java b/src/java.desktop/share/classes/javax/swing/JSplitPane.java index 6b013cceb0556..2ff7722f45822 100644 --- a/src/java.desktop/share/classes/javax/swing/JSplitPane.java +++ b/src/java.desktop/share/classes/javax/swing/JSplitPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1135,8 +1135,9 @@ public AccessibleContext getAccessibleContext() { @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJSplitPane extends AccessibleJComponent implements AccessibleValue { + /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJSplitPane}. */ protected AccessibleJSplitPane() {} diff --git a/src/java.desktop/share/classes/javax/swing/JTabbedPane.java b/src/java.desktop/share/classes/javax/swing/JTabbedPane.java index 8e3146daab320..cffa9e784f428 100644 --- a/src/java.desktop/share/classes/javax/swing/JTabbedPane.java +++ b/src/java.desktop/share/classes/javax/swing/JTabbedPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -289,8 +289,9 @@ public String getUIClassID() { * the tabbedpane (instead of the model itself) as the event source. */ protected class ModelListener implements ChangeListener, Serializable { + /** - * Constructor for subclasses to call. + * Constructs a {@code ModelListener}. */ protected ModelListener() {} diff --git a/src/java.desktop/share/classes/javax/swing/JTextArea.java b/src/java.desktop/share/classes/javax/swing/JTextArea.java index e370aade002e6..57b62e7153591 100644 --- a/src/java.desktop/share/classes/javax/swing/JTextArea.java +++ b/src/java.desktop/share/classes/javax/swing/JTextArea.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -784,7 +784,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJTextArea extends AccessibleJTextComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJTextArea}. */ protected AccessibleJTextArea() {} diff --git a/src/java.desktop/share/classes/javax/swing/JTextField.java b/src/java.desktop/share/classes/javax/swing/JTextField.java index fc4a492c6d023..f4fb65d68985d 100644 --- a/src/java.desktop/share/classes/javax/swing/JTextField.java +++ b/src/java.desktop/share/classes/javax/swing/JTextField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -951,7 +951,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJTextField extends AccessibleJTextComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJTextField}. */ protected AccessibleJTextField() {} diff --git a/src/java.desktop/share/classes/javax/swing/JToolBar.java b/src/java.desktop/share/classes/javax/swing/JToolBar.java index 7c2fef9d8c588..b8bbdbb617926 100644 --- a/src/java.desktop/share/classes/javax/swing/JToolBar.java +++ b/src/java.desktop/share/classes/javax/swing/JToolBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -832,7 +832,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJToolBar extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJToolBar}. */ protected AccessibleJToolBar() {} diff --git a/src/java.desktop/share/classes/javax/swing/JToolTip.java b/src/java.desktop/share/classes/javax/swing/JToolTip.java index 817200fec1f83..d22c7ba888476 100644 --- a/src/java.desktop/share/classes/javax/swing/JToolTip.java +++ b/src/java.desktop/share/classes/javax/swing/JToolTip.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -262,7 +262,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJToolTip extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJToolTip}. */ protected AccessibleJToolTip() {} diff --git a/src/java.desktop/share/classes/javax/swing/JTree.java b/src/java.desktop/share/classes/javax/swing/JTree.java index 810bea55b5f63..43112a781a428 100644 --- a/src/java.desktop/share/classes/javax/swing/JTree.java +++ b/src/java.desktop/share/classes/javax/swing/JTree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -3321,7 +3321,7 @@ protected static class EmptySelectionModel extends DefaultTreeSelectionModel { /** - * Constructor for subclasses to call. + * Constructs an {@code EmptySelectionModel}. */ protected EmptySelectionModel() {} @@ -3448,7 +3448,7 @@ protected class TreeSelectionRedirector implements Serializable, TreeSelectionListener { /** - * Constructor for subclasses to call. + * Constructs a {@code TreeSelectionRedirector}. */ protected TreeSelectionRedirector() {} @@ -3873,10 +3873,11 @@ void removeDescendantSelectedPaths(TreeModelEvent e) { * accordingly when nodes are removed, or changed. */ protected class TreeModelHandler implements TreeModelListener { - /** - * Constructor for subclasses to call. - */ - protected TreeModelHandler() {} + + /** + * Constructs a {@code TreeModelHandler}. + */ + protected TreeModelHandler() {} public void treeNodesChanged(TreeModelEvent e) { } diff --git a/src/java.desktop/share/classes/javax/swing/JViewport.java b/src/java.desktop/share/classes/javax/swing/JViewport.java index ac2cfd747013f..26549bfb2862a 100644 --- a/src/java.desktop/share/classes/javax/swing/JViewport.java +++ b/src/java.desktop/share/classes/javax/swing/JViewport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -1406,7 +1406,7 @@ public void setExtentSize(Dimension newExtent) { protected class ViewListener extends ComponentAdapter implements Serializable { /** - * Constructor for subclasses to call. + * Constructs a {@code ViewListener}. */ protected ViewListener() {} @@ -1882,7 +1882,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJViewport extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJViewport}. */ protected AccessibleJViewport() {} diff --git a/src/java.desktop/share/classes/javax/swing/JWindow.java b/src/java.desktop/share/classes/javax/swing/JWindow.java index 7ca38702353e0..69269c9f284ce 100644 --- a/src/java.desktop/share/classes/javax/swing/JWindow.java +++ b/src/java.desktop/share/classes/javax/swing/JWindow.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -655,7 +655,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJWindow extends AccessibleAWTWindow { // everything is in the new parent, AccessibleAWTWindow /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJWindow}. */ protected AccessibleJWindow() {} } diff --git a/src/java.desktop/share/classes/javax/swing/ToolTipManager.java b/src/java.desktop/share/classes/javax/swing/ToolTipManager.java index b0b179b9c7b35..bb37b05e906f0 100644 --- a/src/java.desktop/share/classes/javax/swing/ToolTipManager.java +++ b/src/java.desktop/share/classes/javax/swing/ToolTipManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -677,8 +677,9 @@ private void checkForTipChange(MouseEvent event) { * Inside timer action. */ protected class insideTimerAction implements ActionListener { + /** - * Constructor for subclasses to call. + * Constructs an {@code insideTimerAction}. */ protected insideTimerAction() {} @@ -712,8 +713,9 @@ public void actionPerformed(ActionEvent e) { * Outside timer action. */ protected class outsideTimerAction implements ActionListener { + /** - * Constructor for subclasses to call. + * Constructs an {@code outsideTimerAction}. */ protected outsideTimerAction() {} @@ -729,8 +731,9 @@ public void actionPerformed(ActionEvent e) { * Still inside timer action. */ protected class stillInsideTimerAction implements ActionListener { + /** - * Constructor for subclasses to call. + * Constructs a {@code stillInsideTimerAction}. */ protected stillInsideTimerAction() {} diff --git a/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java b/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java index 504e9078f1ad6..7b80dd876f1af 100644 --- a/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java +++ b/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -809,7 +809,7 @@ public AccessibleContext getAccessibleContext() { protected class AccessibleJTableHeader extends AccessibleJComponent { /** - * Constructor for subclasses to call. + * Constructs an {@code AccessibleJTableHeader}. */ protected AccessibleJTableHeader() {} diff --git a/src/java.desktop/share/classes/javax/swing/text/html/FormView.java b/src/java.desktop/share/classes/javax/swing/text/html/FormView.java index 4ce1c7952587f..467651a9d98d2 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/FormView.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/FormView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2020, 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 @@ -553,7 +553,7 @@ private void storePostData(HTMLDocument doc, String target, String data) { protected class MouseEventListener extends MouseAdapter { /** - * Constructor for subclasses to call. + * Constructs a {@code MouseEventListener}. */ protected MouseEventListener() {} From 0b83fc0150108c7250da3e80ec8f02deb3b5861c Mon Sep 17 00:00:00 2001 From: Anthony Scarpino Date: Fri, 25 Sep 2020 02:40:36 +0000 Subject: [PATCH 09/79] 8235710: Remove the legacy elliptic curves Reviewed-by: xuelei, erikj --- make/autoconf/configure.ac | 1 - make/autoconf/jdk-options.m4 | 17 - .../classes/sun/security/util/CurveDB.java | 5 - .../share/conf/security/java.security | 19 +- .../sun/security/ec/ECDHKeyAgreement.java | 58 +- .../sun/security/ec/ECDSASignature.java | 161 +- .../sun/security/ec/ECKeyPairGenerator.java | 81 +- .../share/classes/sun/security/ec/SunEC.java | 64 +- src/jdk.crypto.ec/share/legal/ecc.md | 599 -- .../share/native/libsunec/ECC_JNI.cpp | 527 -- .../share/native/libsunec/impl/ec.c | 1091 ---- .../share/native/libsunec/impl/ec.h | 52 - .../share/native/libsunec/impl/ec2.h | 126 - .../share/native/libsunec/impl/ec2_163.c | 260 - .../share/native/libsunec/impl/ec2_193.c | 277 - .../share/native/libsunec/impl/ec2_233.c | 300 - .../share/native/libsunec/impl/ec2_aff.c | 349 -- .../share/native/libsunec/impl/ec2_mont.c | 278 - .../share/native/libsunec/impl/ec_naf.c | 102 - .../share/native/libsunec/impl/ecc_impl.h | 271 - .../share/native/libsunec/impl/ecdecode.c | 642 --- .../share/native/libsunec/impl/ecl-curve.h | 733 --- .../share/native/libsunec/impl/ecl-exp.h | 201 - .../share/native/libsunec/impl/ecl-priv.h | 300 - .../share/native/libsunec/impl/ecl.c | 454 -- .../share/native/libsunec/impl/ecl.h | 92 - .../share/native/libsunec/impl/ecl_curve.c | 195 - .../share/native/libsunec/impl/ecl_gf.c | 1043 ---- .../share/native/libsunec/impl/ecl_mult.c | 362 -- .../share/native/libsunec/impl/ecp.h | 144 - .../share/native/libsunec/impl/ecp_192.c | 517 -- .../share/native/libsunec/impl/ecp_224.c | 373 -- .../share/native/libsunec/impl/ecp_256.c | 430 -- .../share/native/libsunec/impl/ecp_384.c | 294 - .../share/native/libsunec/impl/ecp_521.c | 171 - .../share/native/libsunec/impl/ecp_aff.c | 360 -- .../share/native/libsunec/impl/ecp_jac.c | 564 -- .../share/native/libsunec/impl/ecp_jm.c | 396 -- .../share/native/libsunec/impl/ecp_mont.c | 202 - .../share/native/libsunec/impl/logtab.h | 61 - .../share/native/libsunec/impl/mp_gf2m-priv.h | 101 - .../share/native/libsunec/impl/mp_gf2m.c | 603 -- .../share/native/libsunec/impl/mp_gf2m.h | 62 - .../share/native/libsunec/impl/mpi-config.h | 109 - .../share/native/libsunec/impl/mpi-priv.h | 320 -- .../share/native/libsunec/impl/mpi.c | 4871 ----------------- .../share/native/libsunec/impl/mpi.h | 387 -- .../share/native/libsunec/impl/mplogic.c | 218 - .../share/native/libsunec/impl/mplogic.h | 83 - .../share/native/libsunec/impl/mpmontg.c | 176 - .../share/native/libsunec/impl/mpprime.h | 66 - .../share/native/libsunec/impl/oid.c | 538 -- .../share/native/libsunec/impl/secitem.c | 179 - .../share/native/libsunec/impl/secoidt.h | 82 - .../KeyAgreement/KeyAgreementTest.java | 30 +- .../security/KeyAgreement/KeySizeTest.java | 4 +- .../net/ssl/templates/SSLSocketTemplate.java | 55 - test/jdk/jdk/security/jarsigner/Spec.java | 6 +- test/jdk/sun/security/ec/ECDSAJavaVerify.java | 13 +- .../security/ec/SignatureDigestTruncate.java | 12 +- test/jdk/sun/security/ec/TestEC.java | 12 +- test/jdk/sun/security/ec/keystore | Bin 4288 -> 3486 bytes .../ec/pkcs12/sect193r1server-rsa1024ca.p12 | Bin 1252 -> 0 bytes .../sun/security/pkcs11/ec/ReadPKCS12.java | 6 +- test/jdk/sun/security/pkcs11/ec/TestECDH.java | 11 +- .../jdk/sun/security/pkcs11/ec/TestECDSA.java | 8 +- .../security/pkcs11/ec/TestKeyFactory.java | 15 +- .../ec/pkcs12/sect193r1server-rsa1024ca.p12 | Bin 1252 -> 0 bytes test/jdk/sun/security/pkcs11/sslecc/keystore | Bin 4288 -> 3486 bytes .../security/provider/KeyStore/DKSTest.java | 8 +- .../security/provider/KeyStore/domains.cfg | 4 - .../ssl/CipherSuite/DisabledCurve.java | 25 +- .../tools/jarsigner/RestrictedAlgo.java | 14 +- .../sun/security/tools/keytool/GroupName.java | 5 - .../sun/security/tools/keytool/KeyAlg.java | 4 - .../fakegen/DefaultSignatureAlgorithm.java | 7 +- .../sun/security/ec/ECKeyPairGenerator.java | 28 +- 77 files changed, 107 insertions(+), 20127 deletions(-) delete mode 100644 src/jdk.crypto.ec/share/legal/ecc.md delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/ECC_JNI.cpp delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2_163.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2_193.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2_233.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2_aff.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec2_mont.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ec_naf.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecc_impl.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl-curve.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl-exp.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl-priv.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl_curve.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl_gf.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_192.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_224.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_256.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_384.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_521.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_aff.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/ecp_mont.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/logtab.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m-priv.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpi-config.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpi-priv.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpi.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpmontg.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/mpprime.h delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/oid.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/secitem.c delete mode 100644 src/jdk.crypto.ec/share/native/libsunec/impl/secoidt.h delete mode 100644 test/jdk/sun/security/ec/pkcs12/sect193r1server-rsa1024ca.p12 delete mode 100644 test/jdk/sun/security/pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12 diff --git a/make/autoconf/configure.ac b/make/autoconf/configure.ac index 16e4bcfebaa8f..449f88689835b 100644 --- a/make/autoconf/configure.ac +++ b/make/autoconf/configure.ac @@ -242,7 +242,6 @@ HOTSPOT_SETUP_MISC # ############################################################################### -JDKOPT_DETECT_INTREE_EC JDKOPT_ENABLE_DISABLE_FAILURE_HANDLER JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST JDKOPT_EXCLUDE_TRANSLATIONS diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4 index 7ebda1de5258c..8f58db17d4a3f 100644 --- a/make/autoconf/jdk-options.m4 +++ b/make/autoconf/jdk-options.m4 @@ -228,23 +228,6 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS], ]) ############################################################################### -# -# Enable or disable the elliptic curve crypto implementation -# -AC_DEFUN_ONCE([JDKOPT_DETECT_INTREE_EC], -[ - AC_MSG_CHECKING([if elliptic curve crypto implementation is present]) - - if test -d "${TOPDIR}/src/jdk.crypto.ec/share/native/libsunec/impl"; then - ENABLE_INTREE_EC=true - AC_MSG_RESULT([yes]) - else - ENABLE_INTREE_EC=false - AC_MSG_RESULT([no]) - fi - - AC_SUBST(ENABLE_INTREE_EC) -]) AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_SYMBOLS], [ diff --git a/src/java.base/share/classes/sun/security/util/CurveDB.java b/src/java.base/share/classes/sun/security/util/CurveDB.java index 4cf268fa8aee5..e16e5238fd1e6 100644 --- a/src/java.base/share/classes/sun/security/util/CurveDB.java +++ b/src/java.base/share/classes/sun/security/util/CurveDB.java @@ -53,11 +53,6 @@ public class CurveDB { private static Collection specCollection; - // Used by SunECEntries - public static CollectiongetSupportedCurves() { - return specCollection; - } - // Return a NamedCurve for the specified OID/name or null if unknown. public static NamedCurve lookup(String name) { NamedCurve spec = oidMap.get(name); diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index b87bf271cce27..b84a9d3e0ccfd 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -495,16 +495,7 @@ sun.security.krb5.maxReferrals=5 # in the jdk.[tls|certpath|jar].disabledAlgorithms properties. To include this # list in any of the disabledAlgorithms properties, add the property name as # an entry. -jdk.disabled.namedCurves = secp112r1, secp112r2, secp128r1, secp128r2, \ - secp160k1, secp160r1, secp160r2, secp192k1, secp192r1, secp224k1, \ - secp224r1, secp256k1, sect113r1, sect113r2, sect131r1, sect131r2, \ - sect163k1, sect163r1, sect163r2, sect193r1, sect193r2, sect233k1, \ - sect233r1, sect239k1, sect283k1, sect283r1, sect409k1, sect409r1, \ - sect571k1, sect571r1, X9.62 c2tnb191v1, X9.62 c2tnb191v2, \ - X9.62 c2tnb191v3, X9.62 c2tnb239v1, X9.62 c2tnb239v2, X9.62 c2tnb239v3, \ - X9.62 c2tnb359v1, X9.62 c2tnb431r1, X9.62 prime192v2, X9.62 prime192v3, \ - X9.62 prime239v1, X9.62 prime239v2, X9.62 prime239v3, brainpoolP256r1, \ - brainpoolP320r1, brainpoolP384r1, brainpoolP512r1 +#jdk.disabled.namedCurves= # # Algorithm restrictions for certification path (CertPath) processing @@ -642,8 +633,7 @@ jdk.disabled.namedCurves = secp112r1, secp112r2, secp128r1, secp128r2, \ # # jdk.certpath.disabledAlgorithms=MD2, MD5, SHA1 jdkCA & usage TLSServer, \ - RSA keySize < 1024, DSA keySize < 1024, EC keySize < 224, \ - include jdk.disabled.namedCurves + RSA keySize < 1024, DSA keySize < 1024, EC keySize < 224 # # Legacy algorithms for certification path (CertPath) processing and @@ -707,7 +697,7 @@ jdk.security.legacyAlgorithms=SHA1, \ # See "jdk.certpath.disabledAlgorithms" for syntax descriptions. # jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, \ - DSA keySize < 1024, include jdk.disabled.namedCurves + DSA keySize < 1024 # # Algorithm restrictions for Secure Socket Layer/Transport Layer Security @@ -742,8 +732,7 @@ jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, \ # jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048, \ # rsa_pkcs1_sha1, secp224r1 jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, \ - EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ - include jdk.disabled.namedCurves + EC keySize < 224, 3DES_EDE_CBC, anon, NULL # # Legacy algorithms for Secure Socket Layer/Transport Layer Security (SSL/TLS) diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java index cccd4a68812fd..cb5b90cdd5176 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java @@ -169,22 +169,12 @@ protected byte[] engineGenerateSecret() throws IllegalStateException { } byte[] result; Optional resultOpt = deriveKeyImpl(privateKey, publicKey); - if (resultOpt.isPresent()) { - result = resultOpt.get(); - } else { - if (SunEC.isNativeDisabled()) { - NamedCurve privNC = CurveDB.lookup(privateKey.getParams()); - NamedCurve pubNC = CurveDB.lookup(publicKey.getParams()); - throw new IllegalStateException( - new InvalidAlgorithmParameterException("Legacy SunEC " + - "curve disabled, one or both keys: " + - "Private: " + ((privNC != null) ? - privNC.toString() : " unknown") + - ", PublicKey:" + ((pubNC != null) ? - pubNC.toString() : " unknown"))); - } - result = deriveKeyNative(privateKey, publicKey); + if (resultOpt.isEmpty()) { + throw new IllegalStateException( + new InvalidAlgorithmParameterException("Curve not supported: " + + publicKey.getParams().toString())); } + result = resultOpt.get(); publicKey = null; return result; } @@ -263,42 +253,4 @@ Optional deriveKeyImpl(ECPrivateKey priv, ECPublicKey pubKey) { return Optional.of(result); } - - private static - byte[] deriveKeyNative(ECPrivateKey privateKey, ECPublicKey publicKey) { - - ECParameterSpec params = privateKey.getParams(); - byte[] s = privateKey.getS().toByteArray(); - byte[] encodedParams = // DER OID - ECUtil.encodeECParameterSpec(null, params); - - byte[] publicValue; - if (publicKey instanceof ECPublicKeyImpl) { - ECPublicKeyImpl ecPub = (ECPublicKeyImpl) publicKey; - publicValue = ecPub.getEncodedPublicValue(); - } else { // instanceof ECPublicKey - publicValue = - ECUtil.encodePoint(publicKey.getW(), params.getCurve()); - } - - try { - return deriveKey(s, publicValue, encodedParams); - - } catch (GeneralSecurityException e) { - throw new ProviderException("Could not derive key", e); - } - } - - - /** - * Generates a secret key using the public and private keys. - * - * @param s the private key's S value. - * @param w the public key's W point (in uncompressed form). - * @param encodedParams the curve's DER encoded object identifier. - * - * @return byte[] the secret key. - */ - private static native byte[] deriveKey(byte[] s, byte[] w, - byte[] encodedParams) throws GeneralSecurityException; } diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDSASignature.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDSASignature.java index 41c18e91f7b32..4bf63d77e74e2 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDSASignature.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDSASignature.java @@ -466,53 +466,6 @@ private byte[] signDigestImpl(ECDSAOperations ops, int seedBits, } - private Optional signDigestAvailable(ECPrivateKey privateKey, - byte[] digest, SecureRandom random) throws SignatureException { - - ECParameterSpec params = privateKey.getParams(); - - // seed is the key size + 64 bits - int seedBits = params.getOrder().bitLength() + 64; - Optional opsOpt = - ECDSAOperations.forParameters(params); - if (opsOpt.isEmpty()) { - return Optional.empty(); - } else { - byte[] sig = signDigestImpl(opsOpt.get(), seedBits, digest, - privateKey, random); - return Optional.of(sig); - } - } - - private byte[] signDigestNative(ECPrivateKey privateKey, byte[] digest, - SecureRandom random) throws SignatureException { - - byte[] s = privateKey.getS().toByteArray(); - ECParameterSpec params = privateKey.getParams(); - - // DER OID - byte[] encodedParams = ECUtil.encodeECParameterSpec(null, params); - int orderLength = params.getOrder().bitLength(); - - // seed is twice the order length (in bytes) plus 1 - byte[] seed = new byte[(((orderLength + 7) >> 3) + 1) * 2]; - - random.nextBytes(seed); - - // random bits needed for timing countermeasures - int timingArgument = random.nextInt(); - // values must be non-zero to enable countermeasures - timingArgument |= 1; - - try { - return signDigest(digest, s, encodedParams, seed, - timingArgument); - } catch (GeneralSecurityException e) { - throw new SignatureException("Could not sign data", e); - } - - } - // sign the data and return the signature. See JCA doc @Override protected byte[] engineSign() throws SignatureException { @@ -522,21 +475,18 @@ protected byte[] engineSign() throws SignatureException { } byte[] digest = getDigestValue(); - Optional sigOpt = signDigestAvailable(privateKey, digest, random); - byte[] sig; - if (sigOpt.isPresent()) { - sig = sigOpt.get(); - } else { - if (SunEC.isNativeDisabled()) { - NamedCurve nc = CurveDB.lookup(privateKey.getParams()); - throw new SignatureException( - new InvalidAlgorithmParameterException( - "Legacy SunEC curve disabled: " + - (nc != null ? nc.toString() - : "unknown"))); - } - sig = signDigestNative(privateKey, digest, random); + ECParameterSpec params = privateKey.getParams(); + + // seed is the key size + 64 bits + int seedBits = params.getOrder().bitLength() + 64; + Optional opsOpt = + ECDSAOperations.forParameters(params); + if (opsOpt.isEmpty()) { + throw new SignatureException("Curve not supported: " + + params.toString()); } + byte[] sig = signDigestImpl(opsOpt.get(), seedBits, digest, privateKey, + random); if (p1363Format) { return sig; @@ -557,59 +507,14 @@ protected boolean engineVerify(byte[] signature) throws SignatureException { } byte[] digest = getDigestValue(); - Optional verifyOpt - = verifySignedDigestAvailable(publicKey, sig, digest); - - if (verifyOpt.isPresent()) { - return verifyOpt.get(); - } else { - if (SunEC.isNativeDisabled()) { - NamedCurve nc = CurveDB.lookup(publicKey.getParams()); - throw new SignatureException( - new InvalidAlgorithmParameterException( - "Legacy SunEC curve disabled: " + - (nc != null ? nc.toString() - : "unknown"))); - } - - byte[] w; - ECParameterSpec params = publicKey.getParams(); - // DER OID - byte[] encodedParams = ECUtil.encodeECParameterSpec(null, params); - - if (publicKey instanceof ECPublicKeyImpl) { - w = ((ECPublicKeyImpl) publicKey).getEncodedPublicValue(); - } else { // instanceof ECPublicKey - w = ECUtil.encodePoint(publicKey.getW(), params.getCurve()); - } - - try { - return verifySignedDigest(sig, digest, w, encodedParams); - } catch (GeneralSecurityException e) { - throw new SignatureException("Could not verify signature", e); - } - } - } - - private Optional verifySignedDigestAvailable( - ECPublicKey publicKey, byte[] sig, byte[] digestValue) { - - ECParameterSpec params = publicKey.getParams(); Optional opsOpt = - ECDSAOperations.forParameters(params); + ECDSAOperations.forParameters(publicKey.getParams()); if (opsOpt.isEmpty()) { - return Optional.empty(); - } else { - boolean result = verifySignedDigestImpl(opsOpt.get(), digestValue, - publicKey, sig); - return Optional.of(result); + throw new SignatureException("Curve not supported: " + + publicKey.getParams().toString()); } - } - - private boolean verifySignedDigestImpl(ECDSAOperations ops, - byte[] digest, ECPublicKey pub, byte[] sig) { - return ops.verifySignedDigest(digest, sig, pub.getW()); + return opsOpt.get().verifySignedDigest(digest, sig, publicKey.getW()); } // set parameter, not supported. See JCA doc @@ -657,40 +562,4 @@ protected AlgorithmParameters engineGetParameters() { throw new ProviderException("Error retrieving EC parameters", e); } } - - /** - * Signs the digest using the private key. - * - * @param digest the digest to be signed. - * @param s the private key's S value. - * @param encodedParams the curve's DER encoded object identifier. - * @param seed the random seed. - * @param timing When non-zero, the implmentation will use timing - * countermeasures to hide secrets from timing channels. The EC - * implementation will disable the countermeasures when this value is - * zero, because the underlying EC functions are shared by several - * crypto operations, some of which do not use the countermeasures. - * The high-order 31 bits must be uniformly random. The entropy from - * these bits is used by the countermeasures. - * - * @return byte[] the signature. - */ - private static native byte[] signDigest(byte[] digest, byte[] s, - byte[] encodedParams, byte[] seed, int timing) - throws GeneralSecurityException; - - /** - * Verifies the signed digest using the public key. - * - * @param signature the signature to be verified. It is encoded - * as a concatenation of the key's R and S values. - * @param digest the digest to be used. - * @param w the public key's W point (in uncompressed form). - * @param encodedParams the curve's DER encoded object identifier. - * - * @return boolean true if the signature is successfully verified. - */ - private static native boolean verifySignedDigest(byte[] signature, - byte[] digest, byte[] w, byte[] encodedParams) - throws GeneralSecurityException; } diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECKeyPairGenerator.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECKeyPairGenerator.java index 804313a8cae95..1898c882cc825 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECKeyPairGenerator.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECKeyPairGenerator.java @@ -95,7 +95,7 @@ public void initialize(AlgorithmParameterSpec params, SecureRandom random) ecSpec = ECUtil.getECParameterSpec(null, ecParams); if (ecSpec == null) { throw new InvalidAlgorithmParameterException( - "Unsupported curve: " + params); + "Curve not supported: " + params); } } else if (params instanceof ECGenParameterSpec) { String name = ((ECGenParameterSpec) params).getName(); @@ -126,29 +126,13 @@ private static void ensureCurveIsSupported(ECParameterSpec ecSpec) ecParams.init(ecSpec); } catch (InvalidParameterSpecException ex) { throw new InvalidAlgorithmParameterException( - "Unsupported curve: " + ecSpec.toString()); + "Curve not supported: " + ecSpec.toString()); } // Check if the java implementation supports this curve - if (ECOperations.forParameters(ecSpec).isPresent()) { - return; - } - - // Check if the native library supported this curve, if available - if (SunEC.isNativeDisabled()) { - throw new InvalidAlgorithmParameterException( - "Unsupported curve: " + ecSpec.toString()); - } - - byte[] encodedParams; - try { - encodedParams = ecParams.getEncoded(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - if (!isCurveSupported(encodedParams)) { + if (ECOperations.forParameters(ecSpec).isEmpty()) { throw new InvalidAlgorithmParameterException( - "Unsupported curve: " + ecParams.toString()); + "Curve not supported: " + ecSpec.toString()); } } @@ -168,15 +152,8 @@ public KeyPair generateKeyPair() { } catch (Exception ex) { throw new ProviderException(ex); } - if (SunEC.isNativeDisabled()) { - throw new ProviderException("Legacy SunEC curve disabled: " + - params.toString()); - } - try { - return generateKeyPairNative(random); - } catch (Exception ex) { - throw new ProviderException(ex); - } + throw new ProviderException("Curve not supported: " + + params.toString()); } private byte[] generatePrivateScalar(SecureRandom random, @@ -231,32 +208,6 @@ private Optional generateKeyPairImpl(SecureRandom random) return Optional.of(new KeyPair(publicKey, privateKey)); } - private KeyPair generateKeyPairNative(SecureRandom random) - throws Exception { - - ECParameterSpec ecParams = (ECParameterSpec) params; - byte[] encodedParams = ECUtil.encodeECParameterSpec(null, ecParams); - - // seed is twice the key size (in bytes) plus 1 - byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2]; - random.nextBytes(seed); - Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed); - - // The 'params' object supplied above is equivalent to the native - // one so there is no need to fetch it. - // keyBytes[0] is the encoding of the native private key - BigInteger s = new BigInteger(1, (byte[]) keyBytes[0]); - - PrivateKey privateKey = new ECPrivateKeyImpl(s, ecParams); - - // keyBytes[1] is the encoding of the native public key - byte[] pubKey = (byte[]) keyBytes[1]; - ECPoint w = ECUtil.decodePoint(pubKey, ecParams.getCurve()); - PublicKey publicKey = new ECPublicKeyImpl(w, ecParams); - - return new KeyPair(publicKey, privateKey); - } - private void checkKeySize(int keySize) throws InvalidParameterException { if (keySize < KEY_SIZE_MIN) { throw new InvalidParameterException @@ -268,24 +219,4 @@ private void checkKeySize(int keySize) throws InvalidParameterException { } this.keySize = keySize; } - - /** - * Checks whether the curve in the encoded parameters is supported by the - * native implementation. Some curve operations will be performed by the - * Java implementation, but not all of them. So native support is still - * required for all curves. - * - * @param encodedParams encoded parameters in the same form accepted - * by generateECKeyPair - * @return true if and only if generateECKeyPair will succeed for - * the supplied parameters - */ - private static native boolean isCurveSupported(byte[] encodedParams); - - /* - * Generates the keypair and returns a 2-element array of encoding bytes. - * The first one is for the private key, the second for the public key. - */ - private static native Object[] generateECKeyPair(int keySize, - byte[] encodedParams, byte[] seed) throws GeneralSecurityException; } diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java index e5c7d404c533c..eb3b78867d925 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java @@ -31,9 +31,11 @@ import java.security.PrivilegedAction; import java.security.Provider; import java.security.ProviderException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import sun.security.ec.ed.EdDSAAlgorithmParameters; @@ -41,6 +43,7 @@ import sun.security.ec.ed.EdDSAKeyPairGenerator; import sun.security.ec.ed.EdDSASignature; import sun.security.util.CurveDB; +import sun.security.util.KnownOIDs; import sun.security.util.NamedCurve; import static sun.security.util.SecurityConstants.PROVIDER_VER; @@ -48,54 +51,11 @@ /** * Provider class for the Elliptic Curve provider. - * Supports EC keypair and parameter generation, ECDSA signing and - * ECDH key agreement. - * - * IMPLEMENTATION NOTE: - * The Java classes in this provider access a native ECC implementation - * via JNI to a C++ wrapper class which in turn calls C functions. - * The Java classes are packaged into the jdk.crypto.sunec module and the - * C++ and C functions are packaged into libsunec.so or sunec.dll in the - * JRE native libraries directory. If the native library is not present - * then this provider is registered with support for fewer ECC algorithms - * (KeyPairGenerator, Signature and KeyAgreement are omitted). - * - * @since 1.7 */ public final class SunEC extends Provider { private static final long serialVersionUID = -2279741672933606418L; - // This flag is true if the native library is disabled or not loaded. - private static boolean disableNative = true; - - static { - String s = sun.security.action.GetPropertyAction.privilegedGetProperty( - "jdk.sunec.disableNative"); - if (s != null && s.equalsIgnoreCase("false")) { - disableNative = false; - } - - // If native is enabled, verify the library is available. - if (!disableNative) { - try { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - System.loadLibrary("sunec"); // check for native library - return null; - } - }); - } catch (UnsatisfiedLinkError e) { - disableNative = true; - } - } - } - - // Check if native library support is disabled. - static boolean isNativeDisabled() { - return SunEC.disableNative; - } - private static class ProviderServiceA extends ProviderService { ProviderServiceA(Provider p, String type, String algo, String cn, HashMap attrs) { @@ -258,17 +218,11 @@ void putEntries() { boolean firstCurve = true; StringBuilder names = new StringBuilder(); - Collection supportedCurves; - if (SunEC.isNativeDisabled()) { - supportedCurves = Collections.unmodifiableList(List.of( - CurveDB.lookup("secp256r1"), - CurveDB.lookup("secp384r1"), - CurveDB.lookup("secp521r1"))); - } else { - supportedCurves = CurveDB.getSupportedCurves(); - } - - for (NamedCurve namedCurve : supportedCurves) { + for (NamedCurve namedCurve : + List.of( + CurveDB.lookup("secp256r1"), + CurveDB.lookup("secp384r1"), + CurveDB.lookup("secp521r1"))) { if (!firstCurve) { names.append("|"); } else { @@ -380,7 +334,6 @@ private void putXDHEntries() { HashMap ATTRS = new HashMap<>(1); ATTRS.put("ImplementedIn", "Software"); - /* XDH does not require native implementation */ putService(new ProviderService(this, "KeyFactory", "XDH", "sun.security.ec.XDHKeyFactory", null, ATTRS)); putService(new ProviderServiceA(this, "KeyFactory", @@ -414,7 +367,6 @@ private void putEdDSAEntries() { HashMap ATTRS = new HashMap<>(1); ATTRS.put("ImplementedIn", "Software"); - /* EdDSA does not require native implementation */ putService(new ProviderService(this, "KeyFactory", "EdDSA", "sun.security.ec.ed.EdDSAKeyFactory", null, ATTRS)); putService(new ProviderServiceA(this, "KeyFactory", diff --git a/src/jdk.crypto.ec/share/legal/ecc.md b/src/jdk.crypto.ec/share/legal/ecc.md deleted file mode 100644 index 9484110555bf9..0000000000000 --- a/src/jdk.crypto.ec/share/legal/ecc.md +++ /dev/null @@ -1,599 +0,0 @@ -## Mozilla Elliptic Curve Cryptography (ECC) - -### Mozilla ECC Notice - -You are receiving a -[copy](http://hg.openjdk.java.net/jdk/jdk/file/tip/src/jdk.crypto.ec/share/native/libsunec/impl) -of the Elliptic Curve Cryptography library in source form or object code. - -``` -The terms of the Oracle license do NOT apply to the Elliptic Curve Cryptography -library; it is licensed under the following license, separately from the Oracle -programs you received. If you do not wish to install the Elliptic Curve -Cryptography library, you may delete the Elliptic Curve Cryptography library by -removing: - - Linux: $(JAVA_HOME)/lib/libsunec.so - macOS: $(JAVA_HOME)/lib/libsunec.dylib - Windows: $(JAVA_HOME)\bin\sunec.dll - -``` - -#### Mozilla ECC Library Removal Impact -``` -The Java Cryptographic Service SunEC Provider uses the Mozilla ECC library. If -this native library is removed, the following algorithms will no longer be -available from the SunEC provider using the JCA/JCE APIs: - - KeyPairGenerator: EC - KeyAgreement: ECDH - Signature: names that include *withECDSA* - -``` - -#### Written Offer for Source Code - -``` -For third party technology that you receive from Oracle in binary form which -is licensed under an open source license that gives you the right to receive -the source code for that binary, you can also receive a copy of the source -code on physical media by submitting a written request to: - - Oracle America, Inc. - Attn: Associate General Counsel, - Development and Engineering Legal - 500 Oracle Parkway, 10th Floor - Redwood Shores, CA 94065 - -Your request should include: -``` - -* The name of the component or binary file(s) for which you are requesting - the source code -* The name and version number of the Oracle product containing the binary -* The date you received the Oracle product -* Your name -* Your company name (if applicable) -* Your return mailing address and email and -* A telephone number in the event we need to reach you. - -``` -We may charge you a fee to cover the cost of physical media and processing. -Your request must be sent (i) within three (3) years of the date you received -the Oracle product that included the component or binary file(s) that are the -subject of your request, or (ii) in the case of code licensed under the GPL -v3, for as long as Oracle offers spare parts or customer support for that -product model. - -``` - -### Mozilla ECC License -``` -Software distributed under the License is distributed on an "AS IS" basis, -WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -for the specific language governing rights and limitations under the -License. - -The Original Code is the Elliptic Curve Cryptography library. - -The Initial Developer of the Original Code is -Sun Microsystems, Inc. -Portions created by the Initial Developer are Copyright (C) 2003 -the Initial Developer. All Rights Reserved. - -Contributor(s): -Dr Vipul Gupta and -Douglas Stebila, Sun Microsystems Laboratories - -The Elliptic Curve Cryptography Library is subject to GNU Lesser Public License -Version 2.1. -``` - -#### LGPL 2.1 -``` - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - -``` - diff --git a/src/jdk.crypto.ec/share/native/libsunec/ECC_JNI.cpp b/src/jdk.crypto.ec/share/native/libsunec/ECC_JNI.cpp deleted file mode 100644 index eeae66e7cde29..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/ECC_JNI.cpp +++ /dev/null @@ -1,527 +0,0 @@ -/* - * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -#include -#include "jni_util.h" -#include "impl/ecc_impl.h" -#include "sun_security_ec_ECDHKeyAgreement.h" -#include "sun_security_ec_ECKeyPairGenerator.h" -#include "sun_security_ec_ECDSASignature.h" - -#define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException" -#define INVALID_ALGORITHM_PARAMETER_EXCEPTION \ - "java/security/InvalidAlgorithmParameterException" -#define INVALID_PARAMETER_EXCEPTION \ - "java/security/InvalidParameterException" -#define KEY_EXCEPTION "java/security/KeyException" - -extern "C" { - -/* - * Declare library specific JNI_Onload entry if static build - */ -DEF_STATIC_JNI_OnLoad - -/* - * Throws an arbitrary Java exception. - */ -void ThrowException(JNIEnv *env, const char *exceptionName) -{ - jclass exceptionClazz = env->FindClass(exceptionName); - if (exceptionClazz != NULL) { - env->ThrowNew(exceptionClazz, NULL); - } -} - -/* - * Deep free of the ECParams struct - */ -void FreeECParams(ECParams *ecparams, jboolean freeStruct) -{ - // Use B_FALSE to free the SECItem->data element, but not the SECItem itself - // Use B_TRUE to free both - - SECITEM_FreeItem(&ecparams->fieldID.u.prime, B_FALSE); - SECITEM_FreeItem(&ecparams->curve.a, B_FALSE); - SECITEM_FreeItem(&ecparams->curve.b, B_FALSE); - SECITEM_FreeItem(&ecparams->curve.seed, B_FALSE); - SECITEM_FreeItem(&ecparams->base, B_FALSE); - SECITEM_FreeItem(&ecparams->order, B_FALSE); - SECITEM_FreeItem(&ecparams->DEREncoding, B_FALSE); - SECITEM_FreeItem(&ecparams->curveOID, B_FALSE); - if (freeStruct) - free(ecparams); -} - -jbyteArray getEncodedBytes(JNIEnv *env, SECItem *hSECItem) -{ - SECItem *s = (SECItem *)hSECItem; - - jbyteArray jEncodedBytes = env->NewByteArray(s->len); - if (jEncodedBytes == NULL) { - return NULL; - } - // Copy bytes from a native SECItem buffer to Java byte array - env->SetByteArrayRegion(jEncodedBytes, 0, s->len, (jbyte *)s->data); - if (env->ExceptionCheck()) { // should never happen - return NULL; - } - return jEncodedBytes; -} - -/* - * Class: sun_security_ec_ECKeyPairGenerator - * Method: isCurveSupported - * Signature: ([B)Z - */ -JNIEXPORT jboolean -JNICALL Java_sun_security_ec_ECKeyPairGenerator_isCurveSupported - (JNIEnv *env, jclass clazz, jbyteArray encodedParams) -{ - SECKEYECParams params_item; - ECParams *ecparams = NULL; - jboolean result = JNI_FALSE; - - // The curve is supported if we can get parameters for it - params_item.len = env->GetArrayLength(encodedParams); - params_item.data = - (unsigned char *) env->GetByteArrayElements(encodedParams, 0); - if (params_item.data == NULL) { - goto cleanup; - } - - // Fill a new ECParams using the supplied OID - if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { - /* bad curve OID */ - goto cleanup; - } - - // If we make it to here, then the curve is supported - result = JNI_TRUE; - -cleanup: - { - if (params_item.data) { - env->ReleaseByteArrayElements(encodedParams, - (jbyte *) params_item.data, JNI_ABORT); - } - if (ecparams) { - FreeECParams(ecparams, true); - } - } - - return result; -} - -/* - * Class: sun_security_ec_ECKeyPairGenerator - * Method: generateECKeyPair - * Signature: (I[B[B)[[B - */ -JNIEXPORT jobjectArray -JNICALL Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair - (JNIEnv *env, jclass clazz, jint keySize, jbyteArray encodedParams, jbyteArray seed) -{ - ECPrivateKey *privKey = NULL; // contains both public and private values - ECParams *ecparams = NULL; - SECKEYECParams params_item; - jint jSeedLength; - jbyte* pSeedBuffer = NULL; - jobjectArray result = NULL; - jclass baCls = NULL; - jbyteArray jba; - - // Initialize the ECParams struct - params_item.len = env->GetArrayLength(encodedParams); - params_item.data = - (unsigned char *) env->GetByteArrayElements(encodedParams, 0); - if (params_item.data == NULL) { - goto cleanup; - } - - // Fill a new ECParams using the supplied OID - if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { - /* bad curve OID */ - ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); - goto cleanup; - } - - // Copy seed from Java to native buffer - jSeedLength = env->GetArrayLength(seed); - pSeedBuffer = new jbyte[jSeedLength]; - env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer); - - // Generate the new keypair (using the supplied seed) - if (EC_NewKey(ecparams, &privKey, (unsigned char *) pSeedBuffer, - jSeedLength, 0) != SECSuccess) { - ThrowException(env, KEY_EXCEPTION); - goto cleanup; - } - - jboolean isCopy; - baCls = env->FindClass("[B"); - if (baCls == NULL) { - goto cleanup; - } - result = env->NewObjectArray(2, baCls, NULL); - if (result == NULL) { - goto cleanup; - } - jba = getEncodedBytes(env, &(privKey->privateValue)); - if (jba == NULL) { - result = NULL; - goto cleanup; - } - env->SetObjectArrayElement(result, 0, jba); // big integer - if (env->ExceptionCheck()) { // should never happen - result = NULL; - goto cleanup; - } - - jba = getEncodedBytes(env, &(privKey->publicValue)); - if (jba == NULL) { - result = NULL; - goto cleanup; - } - env->SetObjectArrayElement(result, 1, jba); // encoded ec point - if (env->ExceptionCheck()) { // should never happen - result = NULL; - goto cleanup; - } - -cleanup: - { - if (params_item.data) { - env->ReleaseByteArrayElements(encodedParams, - (jbyte *) params_item.data, JNI_ABORT); - } - if (ecparams) { - FreeECParams(ecparams, true); - } - if (privKey) { - FreeECParams(&privKey->ecParams, false); - SECITEM_FreeItem(&privKey->version, B_FALSE); - SECITEM_FreeItem(&privKey->privateValue, B_FALSE); - SECITEM_FreeItem(&privKey->publicValue, B_FALSE); - free(privKey); - } - - if (pSeedBuffer) { - delete [] pSeedBuffer; - } - } - - return result; -} - -/* - * Class: sun_security_ec_ECDSASignature - * Method: signDigest - * Signature: ([B[B[B[B)[B - */ -JNIEXPORT jbyteArray -JNICALL Java_sun_security_ec_ECDSASignature_signDigest - (JNIEnv *env, jclass clazz, jbyteArray digest, jbyteArray privateKey, jbyteArray encodedParams, jbyteArray seed, jint timing) -{ - jbyte* pDigestBuffer = NULL; - jint jDigestLength = env->GetArrayLength(digest); - jbyteArray jSignedDigest = NULL; - - SECItem signature_item; - jbyte* pSignedDigestBuffer = NULL; - jbyteArray temp; - - jint jSeedLength = env->GetArrayLength(seed); - jbyte* pSeedBuffer = NULL; - - // Copy digest from Java to native buffer - pDigestBuffer = new jbyte[jDigestLength]; - env->GetByteArrayRegion(digest, 0, jDigestLength, pDigestBuffer); - SECItem digest_item; - digest_item.data = (unsigned char *) pDigestBuffer; - digest_item.len = jDigestLength; - - ECPrivateKey privKey; - privKey.privateValue.data = NULL; - - // Initialize the ECParams struct - ECParams *ecparams = NULL; - SECKEYECParams params_item; - params_item.len = env->GetArrayLength(encodedParams); - params_item.data = - (unsigned char *) env->GetByteArrayElements(encodedParams, 0); - if (params_item.data == NULL) { - goto cleanup; - } - - // Fill a new ECParams using the supplied OID - if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { - /* bad curve OID */ - ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); - goto cleanup; - } - - // Extract private key data - privKey.ecParams = *ecparams; // struct assignment - privKey.privateValue.len = env->GetArrayLength(privateKey); - privKey.privateValue.data = - (unsigned char *) env->GetByteArrayElements(privateKey, 0); - if (privKey.privateValue.data == NULL) { - goto cleanup; - } - - // Prepare a buffer for the signature (twice the key length) - pSignedDigestBuffer = new jbyte[ecparams->order.len * 2]; - signature_item.data = (unsigned char *) pSignedDigestBuffer; - signature_item.len = ecparams->order.len * 2; - - // Copy seed from Java to native buffer - pSeedBuffer = new jbyte[jSeedLength]; - env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer); - - // Sign the digest (using the supplied seed) - if (ECDSA_SignDigest(&privKey, &signature_item, &digest_item, - (unsigned char *) pSeedBuffer, jSeedLength, 0, timing) != SECSuccess) { - ThrowException(env, KEY_EXCEPTION); - goto cleanup; - } - - // Create new byte array - temp = env->NewByteArray(signature_item.len); - if (temp == NULL) { - goto cleanup; - } - - // Copy data from native buffer - env->SetByteArrayRegion(temp, 0, signature_item.len, pSignedDigestBuffer); - jSignedDigest = temp; - -cleanup: - { - if (params_item.data) { - env->ReleaseByteArrayElements(encodedParams, - (jbyte *) params_item.data, JNI_ABORT); - } - if (privKey.privateValue.data) { - env->ReleaseByteArrayElements(privateKey, - (jbyte *) privKey.privateValue.data, JNI_ABORT); - } - if (pDigestBuffer) { - delete [] pDigestBuffer; - } - if (pSignedDigestBuffer) { - delete [] pSignedDigestBuffer; - } - if (pSeedBuffer) { - delete [] pSeedBuffer; - } - if (ecparams) { - FreeECParams(ecparams, true); - } - } - - return jSignedDigest; -} - -/* - * Class: sun_security_ec_ECDSASignature - * Method: verifySignedDigest - * Signature: ([B[B[B[B)Z - */ -JNIEXPORT jboolean -JNICALL Java_sun_security_ec_ECDSASignature_verifySignedDigest - (JNIEnv *env, jclass clazz, jbyteArray signedDigest, jbyteArray digest, jbyteArray publicKey, jbyteArray encodedParams) -{ - jboolean isValid = false; - - // Copy signedDigest from Java to native buffer - jbyte* pSignedDigestBuffer = NULL; - jint jSignedDigestLength = env->GetArrayLength(signedDigest); - pSignedDigestBuffer = new jbyte[jSignedDigestLength]; - env->GetByteArrayRegion(signedDigest, 0, jSignedDigestLength, - pSignedDigestBuffer); - SECItem signature_item; - signature_item.data = (unsigned char *) pSignedDigestBuffer; - signature_item.len = jSignedDigestLength; - - // Copy digest from Java to native buffer - jbyte* pDigestBuffer = NULL; - jint jDigestLength = env->GetArrayLength(digest); - pDigestBuffer = new jbyte[jDigestLength]; - env->GetByteArrayRegion(digest, 0, jDigestLength, pDigestBuffer); - SECItem digest_item; - digest_item.data = (unsigned char *) pDigestBuffer; - digest_item.len = jDigestLength; - - // Extract public key data - ECPublicKey pubKey; - pubKey.publicValue.data = NULL; - ECParams *ecparams = NULL; - SECKEYECParams params_item; - - // Initialize the ECParams struct - params_item.len = env->GetArrayLength(encodedParams); - params_item.data = - (unsigned char *) env->GetByteArrayElements(encodedParams, 0); - if (params_item.data == NULL) { - goto cleanup; - } - - // Fill a new ECParams using the supplied OID - if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { - /* bad curve OID */ - ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); - goto cleanup; - } - pubKey.ecParams = *ecparams; // struct assignment - pubKey.publicValue.len = env->GetArrayLength(publicKey); - pubKey.publicValue.data = - (unsigned char *) env->GetByteArrayElements(publicKey, 0); - - if (ECDSA_VerifyDigest(&pubKey, &signature_item, &digest_item, 0) - != SECSuccess) { - goto cleanup; - } - - isValid = true; - -cleanup: - { - if (params_item.data) - env->ReleaseByteArrayElements(encodedParams, - (jbyte *) params_item.data, JNI_ABORT); - - if (pubKey.publicValue.data) - env->ReleaseByteArrayElements(publicKey, - (jbyte *) pubKey.publicValue.data, JNI_ABORT); - - if (ecparams) - FreeECParams(ecparams, true); - - if (pSignedDigestBuffer) - delete [] pSignedDigestBuffer; - - if (pDigestBuffer) - delete [] pDigestBuffer; - } - - return isValid; -} - -/* - * Class: sun_security_ec_ECDHKeyAgreement - * Method: deriveKey - * Signature: ([B[B[B)[B - */ -JNIEXPORT jbyteArray -JNICALL Java_sun_security_ec_ECDHKeyAgreement_deriveKey - (JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey, jbyteArray encodedParams) -{ - jbyteArray jSecret = NULL; - ECParams *ecparams = NULL; - SECItem privateValue_item; - privateValue_item.data = NULL; - SECItem publicValue_item; - publicValue_item.data = NULL; - SECKEYECParams params_item; - params_item.data = NULL; - - // Extract private key value - privateValue_item.len = env->GetArrayLength(privateKey); - privateValue_item.data = - (unsigned char *) env->GetByteArrayElements(privateKey, 0); - if (privateValue_item.data == NULL) { - goto cleanup; - } - - // Extract public key value - publicValue_item.len = env->GetArrayLength(publicKey); - publicValue_item.data = - (unsigned char *) env->GetByteArrayElements(publicKey, 0); - if (publicValue_item.data == NULL) { - goto cleanup; - } - - // Initialize the ECParams struct - params_item.len = env->GetArrayLength(encodedParams); - params_item.data = - (unsigned char *) env->GetByteArrayElements(encodedParams, 0); - if (params_item.data == NULL) { - goto cleanup; - } - - // Fill a new ECParams using the supplied OID - if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { - /* bad curve OID */ - ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); - goto cleanup; - } - - // Prepare a buffer for the secret - SECItem secret_item; - secret_item.data = NULL; - secret_item.len = ecparams->order.len * 2; - - if (ECDH_Derive(&publicValue_item, ecparams, &privateValue_item, B_FALSE, - &secret_item, 0) != SECSuccess) { - ThrowException(env, ILLEGAL_STATE_EXCEPTION); - goto cleanup; - } - - // Create new byte array - jSecret = env->NewByteArray(secret_item.len); - if (jSecret == NULL) { - goto cleanup; - } - - // Copy bytes from the SECItem buffer to a Java byte array - env->SetByteArrayRegion(jSecret, 0, secret_item.len, - (jbyte *)secret_item.data); - - // Free the SECItem data buffer - SECITEM_FreeItem(&secret_item, B_FALSE); - -cleanup: - { - if (privateValue_item.data) - env->ReleaseByteArrayElements(privateKey, - (jbyte *) privateValue_item.data, JNI_ABORT); - - if (publicValue_item.data) - env->ReleaseByteArrayElements(publicKey, - (jbyte *) publicValue_item.data, JNI_ABORT); - - if (params_item.data) - env->ReleaseByteArrayElements(encodedParams, - (jbyte *) params_item.data, JNI_ABORT); - - if (ecparams) - FreeECParams(ecparams, true); - } - - return jSecret; -} - -} /* extern "C" */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c deleted file mode 100644 index 8c98bdd74d4ed..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.c +++ /dev/null @@ -1,1091 +0,0 @@ -/* - * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Elliptic Curve Cryptography library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta and - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "mplogic.h" -#include "ec.h" -#include "ecl.h" - -#include -#ifndef _KERNEL -#include -#include -#include - -#ifndef _WIN32 -#include -#endif /* _WIN32 */ - -#endif -#include "ecl-exp.h" -#include "mpi.h" -#include "ecc_impl.h" - -#ifdef _KERNEL -#define PORT_ZFree(p, l) bzero((p), (l)); kmem_free((p), (l)) -#else -#ifndef _WIN32 -#define PORT_ZFree(p, l) bzero((p), (l)); free((p)) -#else -#define PORT_ZFree(p, l) memset((p), 0, (l)); free((p)) -#endif /* _WIN32 */ -#endif - -/* - * Returns true if pointP is the point at infinity, false otherwise - */ -PRBool -ec_point_at_infinity(SECItem *pointP) -{ - unsigned int i; - - for (i = 1; i < pointP->len; i++) { - if (pointP->data[i] != 0x00) return PR_FALSE; - } - - return PR_TRUE; -} - -/* - * Computes scalar point multiplication pointQ = k1 * G + k2 * pointP for - * the curve whose parameters are encoded in params with base point G. - */ -SECStatus -ec_points_mul(const ECParams *params, const mp_int *k1, const mp_int *k2, - const SECItem *pointP, SECItem *pointQ, int kmflag, int timing) -{ - mp_int Px, Py, Qx, Qy; - mp_int Gx, Gy, order, irreducible, a, b; -#if 0 /* currently don't support non-named curves */ - unsigned int irr_arr[5]; -#endif - ECGroup *group = NULL; - SECStatus rv = SECFailure; - mp_err err = MP_OKAY; - unsigned int len; - -#if EC_DEBUG - int i; - char mpstr[256]; - - printf("ec_points_mul: params [len=%d]:", params->DEREncoding.len); - for (i = 0; i < params->DEREncoding.len; i++) - printf("%02x:", params->DEREncoding.data[i]); - printf("\n"); - - if (k1 != NULL) { - mp_tohex((mp_int*)k1, mpstr); - printf("ec_points_mul: scalar k1: %s\n", mpstr); - mp_todecimal((mp_int*)k1, mpstr); - printf("ec_points_mul: scalar k1: %s (dec)\n", mpstr); - } - - if (k2 != NULL) { - mp_tohex((mp_int*)k2, mpstr); - printf("ec_points_mul: scalar k2: %s\n", mpstr); - mp_todecimal((mp_int*)k2, mpstr); - printf("ec_points_mul: scalar k2: %s (dec)\n", mpstr); - } - - if (pointP != NULL) { - printf("ec_points_mul: pointP [len=%d]:", pointP->len); - for (i = 0; i < pointP->len; i++) - printf("%02x:", pointP->data[i]); - printf("\n"); - } -#endif - - /* NOTE: We only support uncompressed points for now */ - len = (params->fieldID.size + 7) >> 3; - if (pointP != NULL) { - if ((pointP->data[0] != EC_POINT_FORM_UNCOMPRESSED) || - (pointP->len != (2 * len + 1))) { - return SECFailure; - }; - } - - MP_DIGITS(&Px) = 0; - MP_DIGITS(&Py) = 0; - MP_DIGITS(&Qx) = 0; - MP_DIGITS(&Qy) = 0; - MP_DIGITS(&Gx) = 0; - MP_DIGITS(&Gy) = 0; - MP_DIGITS(&order) = 0; - MP_DIGITS(&irreducible) = 0; - MP_DIGITS(&a) = 0; - MP_DIGITS(&b) = 0; - CHECK_MPI_OK( mp_init(&Px, kmflag) ); - CHECK_MPI_OK( mp_init(&Py, kmflag) ); - CHECK_MPI_OK( mp_init(&Qx, kmflag) ); - CHECK_MPI_OK( mp_init(&Qy, kmflag) ); - CHECK_MPI_OK( mp_init(&Gx, kmflag) ); - CHECK_MPI_OK( mp_init(&Gy, kmflag) ); - CHECK_MPI_OK( mp_init(&order, kmflag) ); - CHECK_MPI_OK( mp_init(&irreducible, kmflag) ); - CHECK_MPI_OK( mp_init(&a, kmflag) ); - CHECK_MPI_OK( mp_init(&b, kmflag) ); - - if ((k2 != NULL) && (pointP != NULL)) { - /* Initialize Px and Py */ - CHECK_MPI_OK( mp_read_unsigned_octets(&Px, pointP->data + 1, (mp_size) len) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&Py, pointP->data + 1 + len, (mp_size) len) ); - } - - /* construct from named params, if possible */ - if (params->name != ECCurve_noName) { - group = ECGroup_fromName(params->name, kmflag); - } - -#if 0 /* currently don't support non-named curves */ - if (group == NULL) { - /* Set up mp_ints containing the curve coefficients */ - CHECK_MPI_OK( mp_read_unsigned_octets(&Gx, params->base.data + 1, - (mp_size) len) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&Gy, params->base.data + 1 + len, - (mp_size) len) ); - SECITEM_TO_MPINT( params->order, &order ); - SECITEM_TO_MPINT( params->curve.a, &a ); - SECITEM_TO_MPINT( params->curve.b, &b ); - if (params->fieldID.type == ec_field_GFp) { - SECITEM_TO_MPINT( params->fieldID.u.prime, &irreducible ); - group = ECGroup_consGFp(&irreducible, &a, &b, &Gx, &Gy, &order, params->cofactor); - } else { - SECITEM_TO_MPINT( params->fieldID.u.poly, &irreducible ); - irr_arr[0] = params->fieldID.size; - irr_arr[1] = params->fieldID.k1; - irr_arr[2] = params->fieldID.k2; - irr_arr[3] = params->fieldID.k3; - irr_arr[4] = 0; - group = ECGroup_consGF2m(&irreducible, irr_arr, &a, &b, &Gx, &Gy, &order, params->cofactor); - } - } -#endif - if (group == NULL) - goto cleanup; - - if ((k2 != NULL) && (pointP != NULL)) { - CHECK_MPI_OK( ECPoints_mul(group, k1, k2, &Px, &Py, &Qx, &Qy, timing) ); - } else { - CHECK_MPI_OK( ECPoints_mul(group, k1, NULL, NULL, NULL, &Qx, &Qy, timing) ); - } - - /* Construct the SECItem representation of point Q */ - pointQ->data[0] = EC_POINT_FORM_UNCOMPRESSED; - CHECK_MPI_OK( mp_to_fixlen_octets(&Qx, pointQ->data + 1, - (mp_size) len) ); - CHECK_MPI_OK( mp_to_fixlen_octets(&Qy, pointQ->data + 1 + len, - (mp_size) len) ); - - rv = SECSuccess; - -#if EC_DEBUG - printf("ec_points_mul: pointQ [len=%d]:", pointQ->len); - for (i = 0; i < pointQ->len; i++) - printf("%02x:", pointQ->data[i]); - printf("\n"); -#endif - -cleanup: - ECGroup_free(group); - mp_clear(&Px); - mp_clear(&Py); - mp_clear(&Qx); - mp_clear(&Qy); - mp_clear(&Gx); - mp_clear(&Gy); - mp_clear(&order); - mp_clear(&irreducible); - mp_clear(&a); - mp_clear(&b); - if (err) { - MP_TO_SEC_ERROR(err); - rv = SECFailure; - } - - return rv; -} - -/* Generates a new EC key pair. The private key is a supplied - * value and the public key is the result of performing a scalar - * point multiplication of that value with the curve's base point. - */ -SECStatus -ec_NewKey(ECParams *ecParams, ECPrivateKey **privKey, - const unsigned char *privKeyBytes, int privKeyLen, int kmflag) -{ - SECStatus rv = SECFailure; - PRArenaPool *arena; - ECPrivateKey *key; - mp_int k; - mp_err err = MP_OKAY; - int len; - -#if EC_DEBUG - printf("ec_NewKey called\n"); -#endif - k.dp = (mp_digit*)NULL; - - if (!ecParams || !privKey || !privKeyBytes || (privKeyLen < 0)) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return SECFailure; - } - - /* Initialize an arena for the EC key. */ - if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE))) - return SECFailure; - - key = (ECPrivateKey *)PORT_ArenaZAlloc(arena, sizeof(ECPrivateKey), - kmflag); - if (!key) { - PORT_FreeArena(arena, PR_TRUE); - return SECFailure; - } - - /* Set the version number (SEC 1 section C.4 says it should be 1) */ - SECITEM_AllocItem(arena, &key->version, 1, kmflag); - key->version.data[0] = 1; - - /* Copy all of the fields from the ECParams argument to the - * ECParams structure within the private key. - */ - key->ecParams.arena = arena; - key->ecParams.type = ecParams->type; - key->ecParams.fieldID.size = ecParams->fieldID.size; - key->ecParams.fieldID.type = ecParams->fieldID.type; - if (ecParams->fieldID.type == ec_field_GFp) { - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.fieldID.u.prime, - &ecParams->fieldID.u.prime, kmflag)); - } else { - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.fieldID.u.poly, - &ecParams->fieldID.u.poly, kmflag)); - } - key->ecParams.fieldID.k1 = ecParams->fieldID.k1; - key->ecParams.fieldID.k2 = ecParams->fieldID.k2; - key->ecParams.fieldID.k3 = ecParams->fieldID.k3; - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.curve.a, - &ecParams->curve.a, kmflag)); - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.curve.b, - &ecParams->curve.b, kmflag)); - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.curve.seed, - &ecParams->curve.seed, kmflag)); - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.base, - &ecParams->base, kmflag)); - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.order, - &ecParams->order, kmflag)); - key->ecParams.cofactor = ecParams->cofactor; - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.DEREncoding, - &ecParams->DEREncoding, kmflag)); - key->ecParams.name = ecParams->name; - CHECK_SEC_OK(SECITEM_CopyItem(arena, &key->ecParams.curveOID, - &ecParams->curveOID, kmflag)); - - len = (ecParams->fieldID.size + 7) >> 3; - SECITEM_AllocItem(arena, &key->publicValue, 2*len + 1, kmflag); - len = ecParams->order.len; - SECITEM_AllocItem(arena, &key->privateValue, len, kmflag); - - /* Copy private key */ - if (privKeyLen >= len) { - memcpy(key->privateValue.data, privKeyBytes, len); - } else { - memset(key->privateValue.data, 0, (len - privKeyLen)); - memcpy(key->privateValue.data + (len - privKeyLen), privKeyBytes, privKeyLen); - } - - /* Compute corresponding public key */ - MP_DIGITS(&k) = 0; - CHECK_MPI_OK( mp_init(&k, kmflag) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&k, key->privateValue.data, - (mp_size) len) ); - - /* key generation does not support timing mitigation */ - rv = ec_points_mul(ecParams, &k, NULL, NULL, &(key->publicValue), kmflag, /*timing*/ 0); - if (rv != SECSuccess) goto cleanup; - *privKey = key; - -cleanup: - mp_clear(&k); - if (rv) { - PORT_FreeArena(arena, PR_TRUE); - } - -#if EC_DEBUG - printf("ec_NewKey returning %s\n", - (rv == SECSuccess) ? "success" : "failure"); -#endif - - return rv; - -} - -/* Generates a new EC key pair. The private key is a supplied - * random value (in seed) and the public key is the result of - * performing a scalar point multiplication of that value with - * the curve's base point. - */ -SECStatus -EC_NewKeyFromSeed(ECParams *ecParams, ECPrivateKey **privKey, - const unsigned char *seed, int seedlen, int kmflag) -{ - SECStatus rv = SECFailure; - rv = ec_NewKey(ecParams, privKey, seed, seedlen, kmflag); - return rv; -} - -/* Generate a random private key using the algorithm A.4.1 of ANSI X9.62, - * modified a la FIPS 186-2 Change Notice 1 to eliminate the bias in the - * random number generator. - * - * Parameters - * - order: a buffer that holds the curve's group order - * - len: the length in octets of the order buffer - * - random: a buffer of 2 * len random bytes - * - randomlen: the length in octets of the random buffer - * - * Return Value - * Returns a buffer of len octets that holds the private key. The caller - * is responsible for freeing the buffer with PORT_ZFree. - */ -static unsigned char * -ec_GenerateRandomPrivateKey(const unsigned char *order, int len, - const unsigned char *random, int randomlen, int kmflag) -{ - SECStatus rv = SECSuccess; - mp_err err; - unsigned char *privKeyBytes = NULL; - mp_int privKeyVal, order_1, one; - - MP_DIGITS(&privKeyVal) = 0; - MP_DIGITS(&order_1) = 0; - MP_DIGITS(&one) = 0; - CHECK_MPI_OK( mp_init(&privKeyVal, kmflag) ); - CHECK_MPI_OK( mp_init(&order_1, kmflag) ); - CHECK_MPI_OK( mp_init(&one, kmflag) ); - - /* - * Reduces the 2*len buffer of random bytes modulo the group order. - */ - if ((privKeyBytes = PORT_Alloc(2*len, kmflag)) == NULL) goto cleanup; - if (randomlen != 2 * len) { - randomlen = 2 * len; - } - /* No need to generate - random bytes are now supplied */ - /* CHECK_SEC_OK( RNG_GenerateGlobalRandomBytes(privKeyBytes, 2*len) );*/ - memcpy(privKeyBytes, random, randomlen); - - CHECK_MPI_OK( mp_read_unsigned_octets(&privKeyVal, privKeyBytes, 2*len) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&order_1, order, len) ); - CHECK_MPI_OK( mp_set_int(&one, 1) ); - CHECK_MPI_OK( mp_sub(&order_1, &one, &order_1) ); - CHECK_MPI_OK( mp_mod(&privKeyVal, &order_1, &privKeyVal) ); - CHECK_MPI_OK( mp_add(&privKeyVal, &one, &privKeyVal) ); - CHECK_MPI_OK( mp_to_fixlen_octets(&privKeyVal, privKeyBytes, len) ); - memset(privKeyBytes+len, 0, len); -cleanup: - mp_clear(&privKeyVal); - mp_clear(&order_1); - mp_clear(&one); - if (err < MP_OKAY) { - MP_TO_SEC_ERROR(err); - rv = SECFailure; - } - if (rv != SECSuccess && privKeyBytes) { -#ifdef _KERNEL - kmem_free(privKeyBytes, 2*len); -#else - free(privKeyBytes); -#endif - privKeyBytes = NULL; - } - return privKeyBytes; -} - -/* Generates a new EC key pair. The private key is a random value and - * the public key is the result of performing a scalar point multiplication - * of that value with the curve's base point. - */ -SECStatus -EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey, - const unsigned char* random, int randomlen, int kmflag) -{ - SECStatus rv = SECFailure; - int len; - unsigned char *privKeyBytes = NULL; - - if (!ecParams) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return SECFailure; - } - - len = ecParams->order.len; - privKeyBytes = ec_GenerateRandomPrivateKey(ecParams->order.data, len, - random, randomlen, kmflag); - if (privKeyBytes == NULL) goto cleanup; - /* generate public key */ - CHECK_SEC_OK( ec_NewKey(ecParams, privKey, privKeyBytes, len, kmflag) ); - -cleanup: - if (privKeyBytes) { - PORT_ZFree(privKeyBytes, len * 2); - } -#if EC_DEBUG - printf("EC_NewKey returning %s\n", - (rv == SECSuccess) ? "success" : "failure"); -#endif - - return rv; -} - -/* Validates an EC public key as described in Section 5.2.2 of - * X9.62. The ECDH primitive when used without the cofactor does - * not address small subgroup attacks, which may occur when the - * public key is not valid. These attacks can be prevented by - * validating the public key before using ECDH. - */ -SECStatus -EC_ValidatePublicKey(ECParams *ecParams, SECItem *publicValue, int kmflag) -{ - mp_int Px, Py; - ECGroup *group = NULL; - SECStatus rv = SECFailure; - mp_err err = MP_OKAY; - unsigned int len; - - if (!ecParams || !publicValue) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return SECFailure; - } - - /* NOTE: We only support uncompressed points for now */ - len = (ecParams->fieldID.size + 7) >> 3; - if (publicValue->data[0] != EC_POINT_FORM_UNCOMPRESSED) { - PORT_SetError(SEC_ERROR_UNSUPPORTED_EC_POINT_FORM); - return SECFailure; - } else if (publicValue->len != (2 * len + 1)) { - PORT_SetError(SEC_ERROR_BAD_KEY); - return SECFailure; - } - - MP_DIGITS(&Px) = 0; - MP_DIGITS(&Py) = 0; - CHECK_MPI_OK( mp_init(&Px, kmflag) ); - CHECK_MPI_OK( mp_init(&Py, kmflag) ); - - /* Initialize Px and Py */ - CHECK_MPI_OK( mp_read_unsigned_octets(&Px, publicValue->data + 1, (mp_size) len) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&Py, publicValue->data + 1 + len, (mp_size) len) ); - - /* construct from named params */ - group = ECGroup_fromName(ecParams->name, kmflag); - if (group == NULL) { - /* - * ECGroup_fromName fails if ecParams->name is not a valid - * ECCurveName value, or if we run out of memory, or perhaps - * for other reasons. Unfortunately if ecParams->name is a - * valid ECCurveName value, we don't know what the right error - * code should be because ECGroup_fromName doesn't return an - * error code to the caller. Set err to MP_UNDEF because - * that's what ECGroup_fromName uses internally. - */ - if ((ecParams->name <= ECCurve_noName) || - (ecParams->name >= ECCurve_pastLastCurve)) { - err = MP_BADARG; - } else { - err = MP_UNDEF; - } - goto cleanup; - } - - /* validate public point */ - if ((err = ECPoint_validate(group, &Px, &Py)) < MP_YES) { - if (err == MP_NO) { - PORT_SetError(SEC_ERROR_BAD_KEY); - rv = SECFailure; - err = MP_OKAY; /* don't change the error code */ - } - goto cleanup; - } - - rv = SECSuccess; - -cleanup: - ECGroup_free(group); - mp_clear(&Px); - mp_clear(&Py); - if (err) { - MP_TO_SEC_ERROR(err); - rv = SECFailure; - } - return rv; -} - -/* -** Performs an ECDH key derivation by computing the scalar point -** multiplication of privateValue and publicValue (with or without the -** cofactor) and returns the x-coordinate of the resulting elliptic -** curve point in derived secret. If successful, derivedSecret->data -** is set to the address of the newly allocated buffer containing the -** derived secret, and derivedSecret->len is the size of the secret -** produced. It is the caller's responsibility to free the allocated -** buffer containing the derived secret. -*/ -SECStatus -ECDH_Derive(SECItem *publicValue, - ECParams *ecParams, - SECItem *privateValue, - PRBool withCofactor, - SECItem *derivedSecret, - int kmflag) -{ - SECStatus rv = SECFailure; - unsigned int len = 0; - SECItem pointQ = {siBuffer, NULL, 0}; - mp_int k; /* to hold the private value */ - mp_int cofactor; - mp_err err = MP_OKAY; -#if EC_DEBUG - int i; -#endif - - if (!publicValue || !ecParams || !privateValue || - !derivedSecret) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return SECFailure; - } - - if (EC_ValidatePublicKey(ecParams, publicValue, kmflag) != SECSuccess) { - return SECFailure; - } - - memset(derivedSecret, 0, sizeof *derivedSecret); - len = (ecParams->fieldID.size + 7) >> 3; - pointQ.len = 2*len + 1; - if ((pointQ.data = PORT_Alloc(2*len + 1, kmflag)) == NULL) goto cleanup; - - MP_DIGITS(&k) = 0; - CHECK_MPI_OK( mp_init(&k, kmflag) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&k, privateValue->data, - (mp_size) privateValue->len) ); - - if (withCofactor && (ecParams->cofactor != 1)) { - /* multiply k with the cofactor */ - MP_DIGITS(&cofactor) = 0; - CHECK_MPI_OK( mp_init(&cofactor, kmflag) ); - mp_set(&cofactor, ecParams->cofactor); - CHECK_MPI_OK( mp_mul(&k, &cofactor, &k) ); - } - - /* Multiply our private key and peer's public point */ - /* ECDH doesn't support timing mitigation */ - if ((ec_points_mul(ecParams, NULL, &k, publicValue, &pointQ, kmflag, /*timing*/ 0) != SECSuccess) || - ec_point_at_infinity(&pointQ)) - goto cleanup; - - /* Allocate memory for the derived secret and copy - * the x co-ordinate of pointQ into it. - */ - SECITEM_AllocItem(NULL, derivedSecret, len, kmflag); - memcpy(derivedSecret->data, pointQ.data + 1, len); - - rv = SECSuccess; - -#if EC_DEBUG - printf("derived_secret:\n"); - for (i = 0; i < derivedSecret->len; i++) - printf("%02x:", derivedSecret->data[i]); - printf("\n"); -#endif - -cleanup: - mp_clear(&k); - - if (pointQ.data) { - PORT_ZFree(pointQ.data, 2*len + 1); - } - - return rv; -} - -/* Computes the ECDSA signature (a concatenation of two values r and s) - * on the digest using the given key and the random value kb (used in - * computing s). - */ -SECStatus -ECDSA_SignDigestWithSeed(ECPrivateKey *key, SECItem *signature, - const SECItem *digest, const unsigned char *kb, const int kblen, int kmflag, - int timing) -{ - SECStatus rv = SECFailure; - mp_int x1; - mp_int d, k; /* private key, random integer */ - mp_int r, s; /* tuple (r, s) is the signature */ - mp_int n; - mp_err err = MP_OKAY; - ECParams *ecParams = NULL; - SECItem kGpoint = { siBuffer, NULL, 0}; - int flen = 0; /* length in bytes of the field size */ - unsigned olen; /* length in bytes of the base point order */ - unsigned int orderBitSize; - -#if EC_DEBUG - char mpstr[256]; -#endif - - /* Initialize MPI integers. */ - /* must happen before the first potential call to cleanup */ - MP_DIGITS(&x1) = 0; - MP_DIGITS(&d) = 0; - MP_DIGITS(&k) = 0; - MP_DIGITS(&r) = 0; - MP_DIGITS(&s) = 0; - MP_DIGITS(&n) = 0; - - /* Check args */ - if (!key || !signature || !digest || !kb || (kblen < 0)) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - goto cleanup; - } - - ecParams = &(key->ecParams); - flen = (ecParams->fieldID.size + 7) >> 3; - olen = ecParams->order.len; - if (signature->data == NULL) { - /* a call to get the signature length only */ - goto finish; - } - if (signature->len < 2*olen) { - PORT_SetError(SEC_ERROR_OUTPUT_LEN); - rv = SECBufferTooSmall; - goto cleanup; - } - - - CHECK_MPI_OK( mp_init(&x1, kmflag) ); - CHECK_MPI_OK( mp_init(&d, kmflag) ); - CHECK_MPI_OK( mp_init(&k, kmflag) ); - CHECK_MPI_OK( mp_init(&r, kmflag) ); - CHECK_MPI_OK( mp_init(&s, kmflag) ); - CHECK_MPI_OK( mp_init(&n, kmflag) ); - - SECITEM_TO_MPINT( ecParams->order, &n ); - SECITEM_TO_MPINT( key->privateValue, &d ); - CHECK_MPI_OK( mp_read_unsigned_octets(&k, kb, kblen) ); - /* Make sure k is in the interval [1, n-1] */ - if ((mp_cmp_z(&k) <= 0) || (mp_cmp(&k, &n) >= 0)) { -#if EC_DEBUG - printf("k is outside [1, n-1]\n"); - mp_tohex(&k, mpstr); - printf("k : %s \n", mpstr); - mp_tohex(&n, mpstr); - printf("n : %s \n", mpstr); -#endif - PORT_SetError(SEC_ERROR_NEED_RANDOM); - goto cleanup; - } - - /* - ** ANSI X9.62, Section 5.3.2, Step 2 - ** - ** Compute kG - */ - kGpoint.len = 2*flen + 1; - kGpoint.data = PORT_Alloc(2*flen + 1, kmflag); - if ((kGpoint.data == NULL) || - (ec_points_mul(ecParams, &k, NULL, NULL, &kGpoint, kmflag, timing) - != SECSuccess)) - goto cleanup; - - /* - ** ANSI X9.62, Section 5.3.3, Step 1 - ** - ** Extract the x co-ordinate of kG into x1 - */ - CHECK_MPI_OK( mp_read_unsigned_octets(&x1, kGpoint.data + 1, - (mp_size) flen) ); - - /* - ** ANSI X9.62, Section 5.3.3, Step 2 - ** - ** r = x1 mod n NOTE: n is the order of the curve - */ - CHECK_MPI_OK( mp_mod(&x1, &n, &r) ); - - /* - ** ANSI X9.62, Section 5.3.3, Step 3 - ** - ** verify r != 0 - */ - if (mp_cmp_z(&r) == 0) { - PORT_SetError(SEC_ERROR_NEED_RANDOM); - goto cleanup; - } - - /* - ** ANSI X9.62, Section 5.3.3, Step 4 - ** - ** s = (k**-1 * (HASH(M) + d*r)) mod n - */ - SECITEM_TO_MPINT(*digest, &s); /* s = HASH(M) */ - - /* In the definition of EC signing, digests are truncated - * to the order length - * (see SEC 1 "Elliptic Curve Digit Signature Algorithm" section 4.1.*/ - orderBitSize = mpl_significant_bits(&n); - if (digest->len*8 > orderBitSize) { - mpl_rsh(&s,&s,digest->len*8 - orderBitSize); - } - -#if EC_DEBUG - mp_todecimal(&n, mpstr); - printf("n : %s (dec)\n", mpstr); - mp_todecimal(&d, mpstr); - printf("d : %s (dec)\n", mpstr); - mp_tohex(&x1, mpstr); - printf("x1: %s\n", mpstr); - mp_todecimal(&s, mpstr); - printf("digest: %s (decimal)\n", mpstr); - mp_todecimal(&r, mpstr); - printf("r : %s (dec)\n", mpstr); - mp_tohex(&r, mpstr); - printf("r : %s\n", mpstr); -#endif - - CHECK_MPI_OK( mp_invmod(&k, &n, &k) ); /* k = k**-1 mod n */ - CHECK_MPI_OK( mp_mulmod(&d, &r, &n, &d) ); /* d = d * r mod n */ - CHECK_MPI_OK( mp_addmod(&s, &d, &n, &s) ); /* s = s + d mod n */ - CHECK_MPI_OK( mp_mulmod(&s, &k, &n, &s) ); /* s = s * k mod n */ - -#if EC_DEBUG - mp_todecimal(&s, mpstr); - printf("s : %s (dec)\n", mpstr); - mp_tohex(&s, mpstr); - printf("s : %s\n", mpstr); -#endif - - /* - ** ANSI X9.62, Section 5.3.3, Step 5 - ** - ** verify s != 0 - */ - if (mp_cmp_z(&s) == 0) { - PORT_SetError(SEC_ERROR_NEED_RANDOM); - goto cleanup; - } - - /* - ** - ** Signature is tuple (r, s) - */ - CHECK_MPI_OK( mp_to_fixlen_octets(&r, signature->data, olen) ); - CHECK_MPI_OK( mp_to_fixlen_octets(&s, signature->data + olen, olen) ); -finish: - signature->len = 2*olen; - - rv = SECSuccess; - err = MP_OKAY; -cleanup: - mp_clear(&x1); - mp_clear(&d); - mp_clear(&k); - mp_clear(&r); - mp_clear(&s); - mp_clear(&n); - - if (kGpoint.data) { - PORT_ZFree(kGpoint.data, 2*flen + 1); - } - - if (err) { - MP_TO_SEC_ERROR(err); - rv = SECFailure; - } - -#if EC_DEBUG - printf("ECDSA signing with seed %s\n", - (rv == SECSuccess) ? "succeeded" : "failed"); -#endif - - return rv; -} - -/* -** Computes the ECDSA signature on the digest using the given key -** and a random seed. -*/ -SECStatus -ECDSA_SignDigest(ECPrivateKey *key, SECItem *signature, const SECItem *digest, - const unsigned char* random, int randomLen, int kmflag, int timing) -{ - SECStatus rv = SECFailure; - int len; - unsigned char *kBytes= NULL; - - if (!key) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - return SECFailure; - } - - /* Generate random value k */ - len = key->ecParams.order.len; - kBytes = ec_GenerateRandomPrivateKey(key->ecParams.order.data, len, - random, randomLen, kmflag); - if (kBytes == NULL) goto cleanup; - - /* Generate ECDSA signature with the specified k value */ - rv = ECDSA_SignDigestWithSeed(key, signature, digest, kBytes, len, kmflag, timing); - -cleanup: - if (kBytes) { - PORT_ZFree(kBytes, len * 2); - } - -#if EC_DEBUG - printf("ECDSA signing %s\n", - (rv == SECSuccess) ? "succeeded" : "failed"); -#endif - - return rv; -} - -/* -** Checks the signature on the given digest using the key provided. -*/ -SECStatus -ECDSA_VerifyDigest(ECPublicKey *key, const SECItem *signature, - const SECItem *digest, int kmflag) -{ - SECStatus rv = SECFailure; - mp_int r_, s_; /* tuple (r', s') is received signature) */ - mp_int c, u1, u2, v; /* intermediate values used in verification */ - mp_int x1; - mp_int n; - mp_err err = MP_OKAY; - ECParams *ecParams = NULL; - SECItem pointC = { siBuffer, NULL, 0 }; - int slen; /* length in bytes of a half signature (r or s) */ - int flen; /* length in bytes of the field size */ - unsigned olen; /* length in bytes of the base point order */ - unsigned int orderBitSize; - -#if EC_DEBUG - char mpstr[256]; - printf("ECDSA verification called\n"); -#endif - - /* Initialize MPI integers. */ - /* must happen before the first potential call to cleanup */ - MP_DIGITS(&r_) = 0; - MP_DIGITS(&s_) = 0; - MP_DIGITS(&c) = 0; - MP_DIGITS(&u1) = 0; - MP_DIGITS(&u2) = 0; - MP_DIGITS(&x1) = 0; - MP_DIGITS(&v) = 0; - MP_DIGITS(&n) = 0; - - /* Check args */ - if (!key || !signature || !digest) { - PORT_SetError(SEC_ERROR_INVALID_ARGS); - goto cleanup; - } - - ecParams = &(key->ecParams); - flen = (ecParams->fieldID.size + 7) >> 3; - olen = ecParams->order.len; - if (signature->len == 0 || signature->len%2 != 0 || - signature->len > 2*olen) { - PORT_SetError(SEC_ERROR_INPUT_LEN); - goto cleanup; - } - slen = signature->len/2; - - SECITEM_AllocItem(NULL, &pointC, 2*flen + 1, kmflag); - if (pointC.data == NULL) - goto cleanup; - - CHECK_MPI_OK( mp_init(&r_, kmflag) ); - CHECK_MPI_OK( mp_init(&s_, kmflag) ); - CHECK_MPI_OK( mp_init(&c, kmflag) ); - CHECK_MPI_OK( mp_init(&u1, kmflag) ); - CHECK_MPI_OK( mp_init(&u2, kmflag) ); - CHECK_MPI_OK( mp_init(&x1, kmflag) ); - CHECK_MPI_OK( mp_init(&v, kmflag) ); - CHECK_MPI_OK( mp_init(&n, kmflag) ); - - /* - ** Convert received signature (r', s') into MPI integers. - */ - CHECK_MPI_OK( mp_read_unsigned_octets(&r_, signature->data, slen) ); - CHECK_MPI_OK( mp_read_unsigned_octets(&s_, signature->data + slen, slen) ); - - /* - ** ANSI X9.62, Section 5.4.2, Steps 1 and 2 - ** - ** Verify that 0 < r' < n and 0 < s' < n - */ - SECITEM_TO_MPINT(ecParams->order, &n); - if (mp_cmp_z(&r_) <= 0 || mp_cmp_z(&s_) <= 0 || - mp_cmp(&r_, &n) >= 0 || mp_cmp(&s_, &n) >= 0) { - PORT_SetError(SEC_ERROR_BAD_SIGNATURE); - goto cleanup; /* will return rv == SECFailure */ - } - - /* - ** ANSI X9.62, Section 5.4.2, Step 3 - ** - ** c = (s')**-1 mod n - */ - CHECK_MPI_OK( mp_invmod(&s_, &n, &c) ); /* c = (s')**-1 mod n */ - - /* - ** ANSI X9.62, Section 5.4.2, Step 4 - ** - ** u1 = ((HASH(M')) * c) mod n - */ - SECITEM_TO_MPINT(*digest, &u1); /* u1 = HASH(M) */ - - /* In the definition of EC signing, digests are truncated - * to the order length, in bits. - * (see SEC 1 "Elliptic Curve Digit Signature Algorithm" section 4.1.*/ - /* u1 = HASH(M') */ - orderBitSize = mpl_significant_bits(&n); - if (digest->len*8 > orderBitSize) { - mpl_rsh(&u1,&u1,digest->len*8- orderBitSize); - } - -#if EC_DEBUG - mp_todecimal(&r_, mpstr); - printf("r_: %s (dec)\n", mpstr); - mp_todecimal(&s_, mpstr); - printf("s_: %s (dec)\n", mpstr); - mp_todecimal(&c, mpstr); - printf("c : %s (dec)\n", mpstr); - mp_todecimal(&u1, mpstr); - printf("digest: %s (dec)\n", mpstr); -#endif - - CHECK_MPI_OK( mp_mulmod(&u1, &c, &n, &u1) ); /* u1 = u1 * c mod n */ - - /* - ** ANSI X9.62, Section 5.4.2, Step 4 - ** - ** u2 = ((r') * c) mod n - */ - CHECK_MPI_OK( mp_mulmod(&r_, &c, &n, &u2) ); - - /* - ** ANSI X9.62, Section 5.4.3, Step 1 - ** - ** Compute u1*G + u2*Q - ** Here, A = u1.G B = u2.Q and C = A + B - ** If the result, C, is the point at infinity, reject the signature - */ - /* verification does not support timing mitigation */ - if (ec_points_mul(ecParams, &u1, &u2, &key->publicValue, &pointC, kmflag, /*timing*/ 0) - != SECSuccess) { - rv = SECFailure; - goto cleanup; - } - if (ec_point_at_infinity(&pointC)) { - PORT_SetError(SEC_ERROR_BAD_SIGNATURE); - rv = SECFailure; - goto cleanup; - } - - CHECK_MPI_OK( mp_read_unsigned_octets(&x1, pointC.data + 1, flen) ); - - /* - ** ANSI X9.62, Section 5.4.4, Step 2 - ** - ** v = x1 mod n - */ - CHECK_MPI_OK( mp_mod(&x1, &n, &v) ); - -#if EC_DEBUG - mp_todecimal(&r_, mpstr); - printf("r_: %s (dec)\n", mpstr); - mp_todecimal(&v, mpstr); - printf("v : %s (dec)\n", mpstr); -#endif - - /* - ** ANSI X9.62, Section 5.4.4, Step 3 - ** - ** Verification: v == r' - */ - if (mp_cmp(&v, &r_)) { - PORT_SetError(SEC_ERROR_BAD_SIGNATURE); - rv = SECFailure; /* Signature failed to verify. */ - } else { - rv = SECSuccess; /* Signature verified. */ - } - -#if EC_DEBUG - mp_todecimal(&u1, mpstr); - printf("u1: %s (dec)\n", mpstr); - mp_todecimal(&u2, mpstr); - printf("u2: %s (dec)\n", mpstr); - mp_tohex(&x1, mpstr); - printf("x1: %s\n", mpstr); - mp_todecimal(&v, mpstr); - printf("v : %s (dec)\n", mpstr); -#endif - -cleanup: - mp_clear(&r_); - mp_clear(&s_); - mp_clear(&c); - mp_clear(&u1); - mp_clear(&u2); - mp_clear(&x1); - mp_clear(&v); - mp_clear(&n); - - if (pointC.data) SECITEM_FreeItem(&pointC, PR_FALSE); - if (err) { - MP_TO_SEC_ERROR(err); - rv = SECFailure; - } - -#if EC_DEBUG - printf("ECDSA verification %s\n", - (rv == SECSuccess) ? "succeeded" : "failed"); -#endif - - return rv; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ec.h deleted file mode 100644 index 958419aa72466..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Elliptic Curve Cryptography library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#ifndef __ec_h_ -#define __ec_h_ - -#define EC_DEBUG 0 -#define EC_POINT_FORM_COMPRESSED_Y0 0x02 -#define EC_POINT_FORM_COMPRESSED_Y1 0x03 -#define EC_POINT_FORM_UNCOMPRESSED 0x04 -#define EC_POINT_FORM_HYBRID_Y0 0x06 -#define EC_POINT_FORM_HYBRID_Y1 0x07 - -#define ANSI_X962_CURVE_OID_TOTAL_LEN 10 -#define SECG_CURVE_OID_TOTAL_LEN 7 -#define BRAINPOOL_CURVE_OID_TOTAL_LEN 11 - -#endif /* __ec_h_ */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2.h deleted file mode 100644 index 72df04ef41321..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#ifndef _EC2_H -#define _EC2_H - -#include "ecl-priv.h" - -/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ -mp_err ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py); - -/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ -mp_err ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py); - -/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx, - * qy). Uses affine coordinates. */ -mp_err ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Computes R = P - Q. Uses affine coordinates. */ -mp_err ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Computes R = 2P. Uses affine coordinates. */ -mp_err ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Validates a point on a GF2m curve. */ -mp_err ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group); - -/* by default, this routine is unused and thus doesn't need to be compiled */ -#ifdef ECL_ENABLE_GF2M_PT_MUL_AFF -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the irreducible that - * determines the field GF2m. Uses affine coordinates. */ -mp_err ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group); -#endif - -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the irreducible that - * determines the field GF2m. Uses Montgomery projective coordinates. */ -mp_err ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing); - -#ifdef ECL_ENABLE_GF2M_PROJ -/* Converts a point P(px, py) from affine coordinates to projective - * coordinates R(rx, ry, rz). */ -mp_err ec_GF2m_pt_aff2proj(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, mp_int *rz, const ECGroup *group); - -/* Converts a point P(px, py, pz) from projective coordinates to affine - * coordinates R(rx, ry). */ -mp_err ec_GF2m_pt_proj2aff(const mp_int *px, const mp_int *py, - const mp_int *pz, mp_int *rx, mp_int *ry, - const ECGroup *group); - -/* Checks if point P(px, py, pz) is at infinity. Uses projective - * coordinates. */ -mp_err ec_GF2m_pt_is_inf_proj(const mp_int *px, const mp_int *py, - const mp_int *pz); - -/* Sets P(px, py, pz) to be the point at infinity. Uses projective - * coordinates. */ -mp_err ec_GF2m_pt_set_inf_proj(mp_int *px, mp_int *py, mp_int *pz); - -/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is - * (qx, qy, qz). Uses projective coordinates. */ -mp_err ec_GF2m_pt_add_proj(const mp_int *px, const mp_int *py, - const mp_int *pz, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - mp_int *rz, const ECGroup *group); - -/* Computes R = 2P. Uses projective coordinates. */ -mp_err ec_GF2m_pt_dbl_proj(const mp_int *px, const mp_int *py, - const mp_int *pz, mp_int *rx, mp_int *ry, - mp_int *rz, const ECGroup *group); - -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the prime that - * determines the field GF2m. Uses projective coordinates. */ -mp_err ec_GF2m_pt_mul_proj(const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group); -#endif - -#endif /* _EC2_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_163.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_163.c deleted file mode 100644 index d35d11d008dd8..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_163.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * - *********************************************************************** */ - -#include "ec2.h" -#include "mp_gf2m.h" -#include "mp_gf2m-priv.h" -#include "mpi.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Fast reduction for polynomials over a 163-bit curve. Assumes reduction - * polynomial with terms {163, 7, 6, 3, 0}. */ -mp_err -ec_GF2m_163_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, z; - - if (a != r) { - MP_CHECKOK(mp_copy(a, r)); - } -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(r) < 6) { - MP_CHECKOK(s_mp_pad(r, 6)); - } - u = MP_DIGITS(r); - MP_USED(r) = 6; - - /* u[5] only has 6 significant bits */ - z = u[5]; - u[2] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29); - z = u[4]; - u[2] ^= (z >> 28) ^ (z >> 29) ^ (z >> 32) ^ (z >> 35); - u[1] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29); - z = u[3]; - u[1] ^= (z >> 28) ^ (z >> 29) ^ (z >> 32) ^ (z >> 35); - u[0] ^= (z << 36) ^ (z << 35) ^ (z << 32) ^ (z << 29); - z = u[2] >> 35; /* z only has 29 significant bits */ - u[0] ^= (z << 7) ^ (z << 6) ^ (z << 3) ^ z; - /* clear bits above 163 */ - u[5] = u[4] = u[3] = 0; - u[2] ^= z << 35; -#else - if (MP_USED(r) < 11) { - MP_CHECKOK(s_mp_pad(r, 11)); - } - u = MP_DIGITS(r); - MP_USED(r) = 11; - - /* u[11] only has 6 significant bits */ - z = u[10]; - u[5] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3); - u[4] ^= (z << 29); - z = u[9]; - u[5] ^= (z >> 28) ^ (z >> 29); - u[4] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3); - u[3] ^= (z << 29); - z = u[8]; - u[4] ^= (z >> 28) ^ (z >> 29); - u[3] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3); - u[2] ^= (z << 29); - z = u[7]; - u[3] ^= (z >> 28) ^ (z >> 29); - u[2] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3); - u[1] ^= (z << 29); - z = u[6]; - u[2] ^= (z >> 28) ^ (z >> 29); - u[1] ^= (z << 4) ^ (z << 3) ^ z ^ (z >> 3); - u[0] ^= (z << 29); - z = u[5] >> 3; /* z only has 29 significant bits */ - u[1] ^= (z >> 25) ^ (z >> 26); - u[0] ^= (z << 7) ^ (z << 6) ^ (z << 3) ^ z; - /* clear bits above 163 */ - u[11] = u[10] = u[9] = u[8] = u[7] = u[6] = 0; - u[5] ^= z << 3; -#endif - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* Fast squaring for polynomials over a 163-bit curve. Assumes reduction - * polynomial with terms {163, 7, 6, 3, 0}. */ -mp_err -ec_GF2m_163_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, *v; - - v = MP_DIGITS(a); - -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(a) < 3) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 6) { - MP_CHECKOK(s_mp_pad(r, 6)); - } - MP_USED(r) = 6; -#else - if (MP_USED(a) < 6) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 12) { - MP_CHECKOK(s_mp_pad(r, 12)); - } - MP_USED(r) = 12; -#endif - u = MP_DIGITS(r); - -#ifdef ECL_THIRTY_TWO_BIT - u[11] = gf2m_SQR1(v[5]); - u[10] = gf2m_SQR0(v[5]); - u[9] = gf2m_SQR1(v[4]); - u[8] = gf2m_SQR0(v[4]); - u[7] = gf2m_SQR1(v[3]); - u[6] = gf2m_SQR0(v[3]); -#endif - u[5] = gf2m_SQR1(v[2]); - u[4] = gf2m_SQR0(v[2]); - u[3] = gf2m_SQR1(v[1]); - u[2] = gf2m_SQR0(v[1]); - u[1] = gf2m_SQR1(v[0]); - u[0] = gf2m_SQR0(v[0]); - return ec_GF2m_163_mod(r, r, meth); - - CLEANUP: - return res; -} - -/* Fast multiplication for polynomials over a 163-bit curve. Assumes - * reduction polynomial with terms {163, 7, 6, 3, 0}. */ -mp_err -ec_GF2m_163_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a2 = 0, a1 = 0, a0, b2 = 0, b1 = 0, b0; - -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a5 = 0, a4 = 0, a3 = 0, b5 = 0, b4 = 0, b3 = 0; - mp_digit rm[6]; -#endif - - if (a == b) { - return ec_GF2m_163_sqr(a, r, meth); - } else { - switch (MP_USED(a)) { -#ifdef ECL_THIRTY_TWO_BIT - case 6: - a5 = MP_DIGIT(a, 5); - case 5: - a4 = MP_DIGIT(a, 4); - case 4: - a3 = MP_DIGIT(a, 3); -#endif - case 3: - a2 = MP_DIGIT(a, 2); - case 2: - a1 = MP_DIGIT(a, 1); - default: - a0 = MP_DIGIT(a, 0); - } - switch (MP_USED(b)) { -#ifdef ECL_THIRTY_TWO_BIT - case 6: - b5 = MP_DIGIT(b, 5); - case 5: - b4 = MP_DIGIT(b, 4); - case 4: - b3 = MP_DIGIT(b, 3); -#endif - case 3: - b2 = MP_DIGIT(b, 2); - case 2: - b1 = MP_DIGIT(b, 1); - default: - b0 = MP_DIGIT(b, 0); - } -#ifdef ECL_SIXTY_FOUR_BIT - MP_CHECKOK(s_mp_pad(r, 6)); - s_bmul_3x3(MP_DIGITS(r), a2, a1, a0, b2, b1, b0); - MP_USED(r) = 6; - s_mp_clamp(r); -#else - MP_CHECKOK(s_mp_pad(r, 12)); - s_bmul_3x3(MP_DIGITS(r) + 6, a5, a4, a3, b5, b4, b3); - s_bmul_3x3(MP_DIGITS(r), a2, a1, a0, b2, b1, b0); - s_bmul_3x3(rm, a5 ^ a2, a4 ^ a1, a3 ^ a0, b5 ^ b2, b4 ^ b1, - b3 ^ b0); - rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 11); - rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 10); - rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 9); - rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 8); - rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 7); - rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 6); - MP_DIGIT(r, 8) ^= rm[5]; - MP_DIGIT(r, 7) ^= rm[4]; - MP_DIGIT(r, 6) ^= rm[3]; - MP_DIGIT(r, 5) ^= rm[2]; - MP_DIGIT(r, 4) ^= rm[1]; - MP_DIGIT(r, 3) ^= rm[0]; - MP_USED(r) = 12; - s_mp_clamp(r); -#endif - return ec_GF2m_163_mod(r, r, meth); - } - - CLEANUP: - return res; -} - -/* Wire in fast field arithmetic for 163-bit curves. */ -mp_err -ec_group_set_gf2m163(ECGroup *group, ECCurveName name) -{ - group->meth->field_mod = &ec_GF2m_163_mod; - group->meth->field_mul = &ec_GF2m_163_mul; - group->meth->field_sqr = &ec_GF2m_163_sqr; - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_193.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_193.c deleted file mode 100644 index bbff2e50f80d5..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_193.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * - *********************************************************************** */ - -#include "ec2.h" -#include "mp_gf2m.h" -#include "mp_gf2m-priv.h" -#include "mpi.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Fast reduction for polynomials over a 193-bit curve. Assumes reduction - * polynomial with terms {193, 15, 0}. */ -mp_err -ec_GF2m_193_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, z; - - if (a != r) { - MP_CHECKOK(mp_copy(a, r)); - } -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(r) < 7) { - MP_CHECKOK(s_mp_pad(r, 7)); - } - u = MP_DIGITS(r); - MP_USED(r) = 7; - - /* u[6] only has 2 significant bits */ - z = u[6]; - u[3] ^= (z << 14) ^ (z >> 1); - u[2] ^= (z << 63); - z = u[5]; - u[3] ^= (z >> 50); - u[2] ^= (z << 14) ^ (z >> 1); - u[1] ^= (z << 63); - z = u[4]; - u[2] ^= (z >> 50); - u[1] ^= (z << 14) ^ (z >> 1); - u[0] ^= (z << 63); - z = u[3] >> 1; /* z only has 63 significant bits */ - u[1] ^= (z >> 49); - u[0] ^= (z << 15) ^ z; - /* clear bits above 193 */ - u[6] = u[5] = u[4] = 0; - u[3] ^= z << 1; -#else - if (MP_USED(r) < 13) { - MP_CHECKOK(s_mp_pad(r, 13)); - } - u = MP_DIGITS(r); - MP_USED(r) = 13; - - /* u[12] only has 2 significant bits */ - z = u[12]; - u[6] ^= (z << 14) ^ (z >> 1); - u[5] ^= (z << 31); - z = u[11]; - u[6] ^= (z >> 18); - u[5] ^= (z << 14) ^ (z >> 1); - u[4] ^= (z << 31); - z = u[10]; - u[5] ^= (z >> 18); - u[4] ^= (z << 14) ^ (z >> 1); - u[3] ^= (z << 31); - z = u[9]; - u[4] ^= (z >> 18); - u[3] ^= (z << 14) ^ (z >> 1); - u[2] ^= (z << 31); - z = u[8]; - u[3] ^= (z >> 18); - u[2] ^= (z << 14) ^ (z >> 1); - u[1] ^= (z << 31); - z = u[7]; - u[2] ^= (z >> 18); - u[1] ^= (z << 14) ^ (z >> 1); - u[0] ^= (z << 31); - z = u[6] >> 1; /* z only has 31 significant bits */ - u[1] ^= (z >> 17); - u[0] ^= (z << 15) ^ z; - /* clear bits above 193 */ - u[12] = u[11] = u[10] = u[9] = u[8] = u[7] = 0; - u[6] ^= z << 1; -#endif - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* Fast squaring for polynomials over a 193-bit curve. Assumes reduction - * polynomial with terms {193, 15, 0}. */ -mp_err -ec_GF2m_193_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, *v; - - v = MP_DIGITS(a); - -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(a) < 4) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 7) { - MP_CHECKOK(s_mp_pad(r, 7)); - } - MP_USED(r) = 7; -#else - if (MP_USED(a) < 7) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 13) { - MP_CHECKOK(s_mp_pad(r, 13)); - } - MP_USED(r) = 13; -#endif - u = MP_DIGITS(r); - -#ifdef ECL_THIRTY_TWO_BIT - u[12] = gf2m_SQR0(v[6]); - u[11] = gf2m_SQR1(v[5]); - u[10] = gf2m_SQR0(v[5]); - u[9] = gf2m_SQR1(v[4]); - u[8] = gf2m_SQR0(v[4]); - u[7] = gf2m_SQR1(v[3]); -#endif - u[6] = gf2m_SQR0(v[3]); - u[5] = gf2m_SQR1(v[2]); - u[4] = gf2m_SQR0(v[2]); - u[3] = gf2m_SQR1(v[1]); - u[2] = gf2m_SQR0(v[1]); - u[1] = gf2m_SQR1(v[0]); - u[0] = gf2m_SQR0(v[0]); - return ec_GF2m_193_mod(r, r, meth); - - CLEANUP: - return res; -} - -/* Fast multiplication for polynomials over a 193-bit curve. Assumes - * reduction polynomial with terms {193, 15, 0}. */ -mp_err -ec_GF2m_193_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a3 = 0, a2 = 0, a1 = 0, a0, b3 = 0, b2 = 0, b1 = 0, b0; - -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a6 = 0, a5 = 0, a4 = 0, b6 = 0, b5 = 0, b4 = 0; - mp_digit rm[8]; -#endif - - if (a == b) { - return ec_GF2m_193_sqr(a, r, meth); - } else { - switch (MP_USED(a)) { -#ifdef ECL_THIRTY_TWO_BIT - case 7: - a6 = MP_DIGIT(a, 6); - case 6: - a5 = MP_DIGIT(a, 5); - case 5: - a4 = MP_DIGIT(a, 4); -#endif - case 4: - a3 = MP_DIGIT(a, 3); - case 3: - a2 = MP_DIGIT(a, 2); - case 2: - a1 = MP_DIGIT(a, 1); - default: - a0 = MP_DIGIT(a, 0); - } - switch (MP_USED(b)) { -#ifdef ECL_THIRTY_TWO_BIT - case 7: - b6 = MP_DIGIT(b, 6); - case 6: - b5 = MP_DIGIT(b, 5); - case 5: - b4 = MP_DIGIT(b, 4); -#endif - case 4: - b3 = MP_DIGIT(b, 3); - case 3: - b2 = MP_DIGIT(b, 2); - case 2: - b1 = MP_DIGIT(b, 1); - default: - b0 = MP_DIGIT(b, 0); - } -#ifdef ECL_SIXTY_FOUR_BIT - MP_CHECKOK(s_mp_pad(r, 8)); - s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0); - MP_USED(r) = 8; - s_mp_clamp(r); -#else - MP_CHECKOK(s_mp_pad(r, 14)); - s_bmul_3x3(MP_DIGITS(r) + 8, a6, a5, a4, b6, b5, b4); - s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0); - s_bmul_4x4(rm, a3, a6 ^ a2, a5 ^ a1, a4 ^ a0, b3, b6 ^ b2, b5 ^ b1, - b4 ^ b0); - rm[7] ^= MP_DIGIT(r, 7); - rm[6] ^= MP_DIGIT(r, 6); - rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 13); - rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 12); - rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 11); - rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 10); - rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 9); - rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 8); - MP_DIGIT(r, 11) ^= rm[7]; - MP_DIGIT(r, 10) ^= rm[6]; - MP_DIGIT(r, 9) ^= rm[5]; - MP_DIGIT(r, 8) ^= rm[4]; - MP_DIGIT(r, 7) ^= rm[3]; - MP_DIGIT(r, 6) ^= rm[2]; - MP_DIGIT(r, 5) ^= rm[1]; - MP_DIGIT(r, 4) ^= rm[0]; - MP_USED(r) = 14; - s_mp_clamp(r); -#endif - return ec_GF2m_193_mod(r, r, meth); - } - - CLEANUP: - return res; -} - -/* Wire in fast field arithmetic for 193-bit curves. */ -mp_err -ec_group_set_gf2m193(ECGroup *group, ECCurveName name) -{ - group->meth->field_mod = &ec_GF2m_193_mod; - group->meth->field_mul = &ec_GF2m_193_mul; - group->meth->field_sqr = &ec_GF2m_193_sqr; - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_233.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_233.c deleted file mode 100644 index 6ba2706ceda76..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_233.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * - *********************************************************************** */ - -#include "ec2.h" -#include "mp_gf2m.h" -#include "mp_gf2m-priv.h" -#include "mpi.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Fast reduction for polynomials over a 233-bit curve. Assumes reduction - * polynomial with terms {233, 74, 0}. */ -mp_err -ec_GF2m_233_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, z; - - if (a != r) { - MP_CHECKOK(mp_copy(a, r)); - } -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(r) < 8) { - MP_CHECKOK(s_mp_pad(r, 8)); - } - u = MP_DIGITS(r); - MP_USED(r) = 8; - - /* u[7] only has 18 significant bits */ - z = u[7]; - u[4] ^= (z << 33) ^ (z >> 41); - u[3] ^= (z << 23); - z = u[6]; - u[4] ^= (z >> 31); - u[3] ^= (z << 33) ^ (z >> 41); - u[2] ^= (z << 23); - z = u[5]; - u[3] ^= (z >> 31); - u[2] ^= (z << 33) ^ (z >> 41); - u[1] ^= (z << 23); - z = u[4]; - u[2] ^= (z >> 31); - u[1] ^= (z << 33) ^ (z >> 41); - u[0] ^= (z << 23); - z = u[3] >> 41; /* z only has 23 significant bits */ - u[1] ^= (z << 10); - u[0] ^= z; - /* clear bits above 233 */ - u[7] = u[6] = u[5] = u[4] = 0; - u[3] ^= z << 41; -#else - if (MP_USED(r) < 15) { - MP_CHECKOK(s_mp_pad(r, 15)); - } - u = MP_DIGITS(r); - MP_USED(r) = 15; - - /* u[14] only has 18 significant bits */ - z = u[14]; - u[9] ^= (z << 1); - u[7] ^= (z >> 9); - u[6] ^= (z << 23); - z = u[13]; - u[9] ^= (z >> 31); - u[8] ^= (z << 1); - u[6] ^= (z >> 9); - u[5] ^= (z << 23); - z = u[12]; - u[8] ^= (z >> 31); - u[7] ^= (z << 1); - u[5] ^= (z >> 9); - u[4] ^= (z << 23); - z = u[11]; - u[7] ^= (z >> 31); - u[6] ^= (z << 1); - u[4] ^= (z >> 9); - u[3] ^= (z << 23); - z = u[10]; - u[6] ^= (z >> 31); - u[5] ^= (z << 1); - u[3] ^= (z >> 9); - u[2] ^= (z << 23); - z = u[9]; - u[5] ^= (z >> 31); - u[4] ^= (z << 1); - u[2] ^= (z >> 9); - u[1] ^= (z << 23); - z = u[8]; - u[4] ^= (z >> 31); - u[3] ^= (z << 1); - u[1] ^= (z >> 9); - u[0] ^= (z << 23); - z = u[7] >> 9; /* z only has 23 significant bits */ - u[3] ^= (z >> 22); - u[2] ^= (z << 10); - u[0] ^= z; - /* clear bits above 233 */ - u[14] = u[13] = u[12] = u[11] = u[10] = u[9] = u[8] = 0; - u[7] ^= z << 9; -#endif - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* Fast squaring for polynomials over a 233-bit curve. Assumes reduction - * polynomial with terms {233, 74, 0}. */ -mp_err -ec_GF2m_233_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit *u, *v; - - v = MP_DIGITS(a); - -#ifdef ECL_SIXTY_FOUR_BIT - if (MP_USED(a) < 4) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 8) { - MP_CHECKOK(s_mp_pad(r, 8)); - } - MP_USED(r) = 8; -#else - if (MP_USED(a) < 8) { - return mp_bsqrmod(a, meth->irr_arr, r); - } - if (MP_USED(r) < 15) { - MP_CHECKOK(s_mp_pad(r, 15)); - } - MP_USED(r) = 15; -#endif - u = MP_DIGITS(r); - -#ifdef ECL_THIRTY_TWO_BIT - u[14] = gf2m_SQR0(v[7]); - u[13] = gf2m_SQR1(v[6]); - u[12] = gf2m_SQR0(v[6]); - u[11] = gf2m_SQR1(v[5]); - u[10] = gf2m_SQR0(v[5]); - u[9] = gf2m_SQR1(v[4]); - u[8] = gf2m_SQR0(v[4]); -#endif - u[7] = gf2m_SQR1(v[3]); - u[6] = gf2m_SQR0(v[3]); - u[5] = gf2m_SQR1(v[2]); - u[4] = gf2m_SQR0(v[2]); - u[3] = gf2m_SQR1(v[1]); - u[2] = gf2m_SQR0(v[1]); - u[1] = gf2m_SQR1(v[0]); - u[0] = gf2m_SQR0(v[0]); - return ec_GF2m_233_mod(r, r, meth); - - CLEANUP: - return res; -} - -/* Fast multiplication for polynomials over a 233-bit curve. Assumes - * reduction polynomial with terms {233, 74, 0}. */ -mp_err -ec_GF2m_233_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a3 = 0, a2 = 0, a1 = 0, a0, b3 = 0, b2 = 0, b1 = 0, b0; - -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a7 = 0, a6 = 0, a5 = 0, a4 = 0, b7 = 0, b6 = 0, b5 = 0, b4 = - 0; - mp_digit rm[8]; -#endif - - if (a == b) { - return ec_GF2m_233_sqr(a, r, meth); - } else { - switch (MP_USED(a)) { -#ifdef ECL_THIRTY_TWO_BIT - case 8: - a7 = MP_DIGIT(a, 7); - case 7: - a6 = MP_DIGIT(a, 6); - case 6: - a5 = MP_DIGIT(a, 5); - case 5: - a4 = MP_DIGIT(a, 4); -#endif - case 4: - a3 = MP_DIGIT(a, 3); - case 3: - a2 = MP_DIGIT(a, 2); - case 2: - a1 = MP_DIGIT(a, 1); - default: - a0 = MP_DIGIT(a, 0); - } - switch (MP_USED(b)) { -#ifdef ECL_THIRTY_TWO_BIT - case 8: - b7 = MP_DIGIT(b, 7); - case 7: - b6 = MP_DIGIT(b, 6); - case 6: - b5 = MP_DIGIT(b, 5); - case 5: - b4 = MP_DIGIT(b, 4); -#endif - case 4: - b3 = MP_DIGIT(b, 3); - case 3: - b2 = MP_DIGIT(b, 2); - case 2: - b1 = MP_DIGIT(b, 1); - default: - b0 = MP_DIGIT(b, 0); - } -#ifdef ECL_SIXTY_FOUR_BIT - MP_CHECKOK(s_mp_pad(r, 8)); - s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0); - MP_USED(r) = 8; - s_mp_clamp(r); -#else - MP_CHECKOK(s_mp_pad(r, 16)); - s_bmul_4x4(MP_DIGITS(r) + 8, a7, a6, a5, a4, b7, b6, b5, b4); - s_bmul_4x4(MP_DIGITS(r), a3, a2, a1, a0, b3, b2, b1, b0); - s_bmul_4x4(rm, a7 ^ a3, a6 ^ a2, a5 ^ a1, a4 ^ a0, b7 ^ b3, - b6 ^ b2, b5 ^ b1, b4 ^ b0); - rm[7] ^= MP_DIGIT(r, 7) ^ MP_DIGIT(r, 15); - rm[6] ^= MP_DIGIT(r, 6) ^ MP_DIGIT(r, 14); - rm[5] ^= MP_DIGIT(r, 5) ^ MP_DIGIT(r, 13); - rm[4] ^= MP_DIGIT(r, 4) ^ MP_DIGIT(r, 12); - rm[3] ^= MP_DIGIT(r, 3) ^ MP_DIGIT(r, 11); - rm[2] ^= MP_DIGIT(r, 2) ^ MP_DIGIT(r, 10); - rm[1] ^= MP_DIGIT(r, 1) ^ MP_DIGIT(r, 9); - rm[0] ^= MP_DIGIT(r, 0) ^ MP_DIGIT(r, 8); - MP_DIGIT(r, 11) ^= rm[7]; - MP_DIGIT(r, 10) ^= rm[6]; - MP_DIGIT(r, 9) ^= rm[5]; - MP_DIGIT(r, 8) ^= rm[4]; - MP_DIGIT(r, 7) ^= rm[3]; - MP_DIGIT(r, 6) ^= rm[2]; - MP_DIGIT(r, 5) ^= rm[1]; - MP_DIGIT(r, 4) ^= rm[0]; - MP_USED(r) = 16; - s_mp_clamp(r); -#endif - return ec_GF2m_233_mod(r, r, meth); - } - - CLEANUP: - return res; -} - -/* Wire in fast field arithmetic for 233-bit curves. */ -mp_err -ec_group_set_gf2m233(ECGroup *group, ECCurveName name) -{ - group->meth->field_mod = &ec_GF2m_233_mod; - group->meth->field_mul = &ec_GF2m_233_mul; - group->meth->field_sqr = &ec_GF2m_233_sqr; - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_aff.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_aff.c deleted file mode 100644 index 8d0f5460f6ad2..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_aff.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "ec2.h" -#include "mplogic.h" -#include "mp_gf2m.h" -#ifndef _KERNEL -#include -#endif - -/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ -mp_err -ec_GF2m_pt_is_inf_aff(const mp_int *px, const mp_int *py) -{ - - if ((mp_cmp_z(px) == 0) && (mp_cmp_z(py) == 0)) { - return MP_YES; - } else { - return MP_NO; - } - -} - -/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ -mp_err -ec_GF2m_pt_set_inf_aff(mp_int *px, mp_int *py) -{ - mp_zero(px); - mp_zero(py); - return MP_OKAY; -} - -/* Computes R = P + Q based on IEEE P1363 A.10.2. Elliptic curve points P, - * Q, and R can all be identical. Uses affine coordinates. */ -mp_err -ec_GF2m_pt_add_aff(const mp_int *px, const mp_int *py, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int lambda, tempx, tempy; - - MP_DIGITS(&lambda) = 0; - MP_DIGITS(&tempx) = 0; - MP_DIGITS(&tempy) = 0; - MP_CHECKOK(mp_init(&lambda, FLAG(px))); - MP_CHECKOK(mp_init(&tempx, FLAG(px))); - MP_CHECKOK(mp_init(&tempy, FLAG(px))); - /* if P = inf, then R = Q */ - if (ec_GF2m_pt_is_inf_aff(px, py) == 0) { - MP_CHECKOK(mp_copy(qx, rx)); - MP_CHECKOK(mp_copy(qy, ry)); - res = MP_OKAY; - goto CLEANUP; - } - /* if Q = inf, then R = P */ - if (ec_GF2m_pt_is_inf_aff(qx, qy) == 0) { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - res = MP_OKAY; - goto CLEANUP; - } - /* if px != qx, then lambda = (py+qy) / (px+qx), tempx = a + lambda^2 - * + lambda + px + qx */ - if (mp_cmp(px, qx) != 0) { - MP_CHECKOK(group->meth->field_add(py, qy, &tempy, group->meth)); - MP_CHECKOK(group->meth->field_add(px, qx, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_div(&tempy, &tempx, &lambda, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, &lambda, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, &group->curvea, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, px, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, qx, &tempx, group->meth)); - } else { - /* if py != qy or qx = 0, then R = inf */ - if (((mp_cmp(py, qy) != 0)) || (mp_cmp_z(qx) == 0)) { - mp_zero(rx); - mp_zero(ry); - res = MP_OKAY; - goto CLEANUP; - } - /* lambda = qx + qy / qx */ - MP_CHECKOK(group->meth->field_div(qy, qx, &lambda, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&lambda, qx, &lambda, group->meth)); - /* tempx = a + lambda^2 + lambda */ - MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, &lambda, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, &group->curvea, &tempx, group->meth)); - } - /* ry = (qx + tempx) * lambda + tempx + qy */ - MP_CHECKOK(group->meth->field_add(qx, &tempx, &tempy, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(&tempy, &lambda, &tempy, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempy, &tempx, &tempy, group->meth)); - MP_CHECKOK(group->meth->field_add(&tempy, qy, ry, group->meth)); - /* rx = tempx */ - MP_CHECKOK(mp_copy(&tempx, rx)); - - CLEANUP: - mp_clear(&lambda); - mp_clear(&tempx); - mp_clear(&tempy); - return res; -} - -/* Computes R = P - Q. Elliptic curve points P, Q, and R can all be - * identical. Uses affine coordinates. */ -mp_err -ec_GF2m_pt_sub_aff(const mp_int *px, const mp_int *py, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int nqy; - - MP_DIGITS(&nqy) = 0; - MP_CHECKOK(mp_init(&nqy, FLAG(px))); - /* nqy = qx+qy */ - MP_CHECKOK(group->meth->field_add(qx, qy, &nqy, group->meth)); - MP_CHECKOK(group->point_add(px, py, qx, &nqy, rx, ry, group)); - CLEANUP: - mp_clear(&nqy); - return res; -} - -/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses - * affine coordinates. */ -mp_err -ec_GF2m_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group) -{ - return group->point_add(px, py, px, py, rx, ry, group); -} - -/* by default, this routine is unused and thus doesn't need to be compiled */ -#ifdef ECL_ENABLE_GF2M_PT_MUL_AFF -/* Computes R = nP based on IEEE P1363 A.10.3. Elliptic curve points P and - * R can be identical. Uses affine coordinates. */ -mp_err -ec_GF2m_pt_mul_aff(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int k, k3, qx, qy, sx, sy; - int b1, b3, i, l; - - MP_DIGITS(&k) = 0; - MP_DIGITS(&k3) = 0; - MP_DIGITS(&qx) = 0; - MP_DIGITS(&qy) = 0; - MP_DIGITS(&sx) = 0; - MP_DIGITS(&sy) = 0; - MP_CHECKOK(mp_init(&k)); - MP_CHECKOK(mp_init(&k3)); - MP_CHECKOK(mp_init(&qx)); - MP_CHECKOK(mp_init(&qy)); - MP_CHECKOK(mp_init(&sx)); - MP_CHECKOK(mp_init(&sy)); - - /* if n = 0 then r = inf */ - if (mp_cmp_z(n) == 0) { - mp_zero(rx); - mp_zero(ry); - res = MP_OKAY; - goto CLEANUP; - } - /* Q = P, k = n */ - MP_CHECKOK(mp_copy(px, &qx)); - MP_CHECKOK(mp_copy(py, &qy)); - MP_CHECKOK(mp_copy(n, &k)); - /* if n < 0 then Q = -Q, k = -k */ - if (mp_cmp_z(n) < 0) { - MP_CHECKOK(group->meth->field_add(&qx, &qy, &qy, group->meth)); - MP_CHECKOK(mp_neg(&k, &k)); - } -#ifdef ECL_DEBUG /* basic double and add method */ - l = mpl_significant_bits(&k) - 1; - MP_CHECKOK(mp_copy(&qx, &sx)); - MP_CHECKOK(mp_copy(&qy, &sy)); - for (i = l - 1; i >= 0; i--) { - /* S = 2S */ - MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group)); - /* if k_i = 1, then S = S + Q */ - if (mpl_get_bit(&k, i) != 0) { - MP_CHECKOK(group-> - point_add(&sx, &sy, &qx, &qy, &sx, &sy, group)); - } - } -#else /* double and add/subtract method from - * standard */ - /* k3 = 3 * k */ - MP_CHECKOK(mp_set_int(&k3, 3)); - MP_CHECKOK(mp_mul(&k, &k3, &k3)); - /* S = Q */ - MP_CHECKOK(mp_copy(&qx, &sx)); - MP_CHECKOK(mp_copy(&qy, &sy)); - /* l = index of high order bit in binary representation of 3*k */ - l = mpl_significant_bits(&k3) - 1; - /* for i = l-1 downto 1 */ - for (i = l - 1; i >= 1; i--) { - /* S = 2S */ - MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group)); - b3 = MP_GET_BIT(&k3, i); - b1 = MP_GET_BIT(&k, i); - /* if k3_i = 1 and k_i = 0, then S = S + Q */ - if ((b3 == 1) && (b1 == 0)) { - MP_CHECKOK(group-> - point_add(&sx, &sy, &qx, &qy, &sx, &sy, group)); - /* if k3_i = 0 and k_i = 1, then S = S - Q */ - } else if ((b3 == 0) && (b1 == 1)) { - MP_CHECKOK(group-> - point_sub(&sx, &sy, &qx, &qy, &sx, &sy, group)); - } - } -#endif - /* output S */ - MP_CHECKOK(mp_copy(&sx, rx)); - MP_CHECKOK(mp_copy(&sy, ry)); - - CLEANUP: - mp_clear(&k); - mp_clear(&k3); - mp_clear(&qx); - mp_clear(&qy); - mp_clear(&sx); - mp_clear(&sy); - return res; -} -#endif - -/* Validates a point on a GF2m curve. */ -mp_err -ec_GF2m_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group) -{ - mp_err res = MP_NO; - mp_int accl, accr, tmp, pxt, pyt; - - MP_DIGITS(&accl) = 0; - MP_DIGITS(&accr) = 0; - MP_DIGITS(&tmp) = 0; - MP_DIGITS(&pxt) = 0; - MP_DIGITS(&pyt) = 0; - MP_CHECKOK(mp_init(&accl, FLAG(px))); - MP_CHECKOK(mp_init(&accr, FLAG(px))); - MP_CHECKOK(mp_init(&tmp, FLAG(px))); - MP_CHECKOK(mp_init(&pxt, FLAG(px))); - MP_CHECKOK(mp_init(&pyt, FLAG(px))); - - /* 1: Verify that publicValue is not the point at infinity */ - if (ec_GF2m_pt_is_inf_aff(px, py) == MP_YES) { - res = MP_NO; - goto CLEANUP; - } - /* 2: Verify that the coordinates of publicValue are elements - * of the field. - */ - if ((MP_SIGN(px) == MP_NEG) || (mp_cmp(px, &group->meth->irr) >= 0) || - (MP_SIGN(py) == MP_NEG) || (mp_cmp(py, &group->meth->irr) >= 0)) { - res = MP_NO; - goto CLEANUP; - } - /* 3: Verify that publicValue is on the curve. */ - if (group->meth->field_enc) { - group->meth->field_enc(px, &pxt, group->meth); - group->meth->field_enc(py, &pyt, group->meth); - } else { - mp_copy(px, &pxt); - mp_copy(py, &pyt); - } - /* left-hand side: y^2 + x*y */ - MP_CHECKOK( group->meth->field_sqr(&pyt, &accl, group->meth) ); - MP_CHECKOK( group->meth->field_mul(&pxt, &pyt, &tmp, group->meth) ); - MP_CHECKOK( group->meth->field_add(&accl, &tmp, &accl, group->meth) ); - /* right-hand side: x^3 + a*x^2 + b */ - MP_CHECKOK( group->meth->field_sqr(&pxt, &tmp, group->meth) ); - MP_CHECKOK( group->meth->field_mul(&pxt, &tmp, &accr, group->meth) ); - MP_CHECKOK( group->meth->field_mul(&group->curvea, &tmp, &tmp, group->meth) ); - MP_CHECKOK( group->meth->field_add(&tmp, &accr, &accr, group->meth) ); - MP_CHECKOK( group->meth->field_add(&accr, &group->curveb, &accr, group->meth) ); - /* check LHS - RHS == 0 */ - MP_CHECKOK( group->meth->field_add(&accl, &accr, &accr, group->meth) ); - if (mp_cmp_z(&accr) != 0) { - res = MP_NO; - goto CLEANUP; - } - /* 4: Verify that the order of the curve times the publicValue - * is the point at infinity. - */ - /* timing mitigation is not supported */ - MP_CHECKOK( ECPoint_mul(group, &group->order, px, py, &pxt, &pyt, /*timing*/ 0) ); - if (ec_GF2m_pt_is_inf_aff(&pxt, &pyt) != MP_YES) { - res = MP_NO; - goto CLEANUP; - } - - res = MP_YES; - -CLEANUP: - mp_clear(&accl); - mp_clear(&accr); - mp_clear(&tmp); - mp_clear(&pxt); - mp_clear(&pyt); - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_mont.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_mont.c deleted file mode 100644 index bb605536f0f5a..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec2_mont.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for binary polynomial field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "ec2.h" -#include "mplogic.h" -#include "mp_gf2m.h" -#ifndef _KERNEL -#include -#endif - -/* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery - * projective coordinates. Uses algorithm Mdouble in appendix of Lopez, J. - * and Dahab, R. "Fast multiplication on elliptic curves over GF(2^m) - * without precomputation". modified to not require precomputation of - * c=b^{2^{m-1}}. */ -static mp_err -gf2m_Mdouble(mp_int *x, mp_int *z, const ECGroup *group, int kmflag) -{ - mp_err res = MP_OKAY; - mp_int t1; - - MP_DIGITS(&t1) = 0; - MP_CHECKOK(mp_init(&t1, kmflag)); - - MP_CHECKOK(group->meth->field_sqr(x, x, group->meth)); - MP_CHECKOK(group->meth->field_sqr(z, &t1, group->meth)); - MP_CHECKOK(group->meth->field_mul(x, &t1, z, group->meth)); - MP_CHECKOK(group->meth->field_sqr(x, x, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&t1, &t1, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(&group->curveb, &t1, &t1, group->meth)); - MP_CHECKOK(group->meth->field_add(x, &t1, x, group->meth)); - - CLEANUP: - mp_clear(&t1); - return res; -} - -/* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in - * Montgomery projective coordinates. Uses algorithm Madd in appendix of - * Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over - * GF(2^m) without precomputation". */ -static mp_err -gf2m_Madd(const mp_int *x, mp_int *x1, mp_int *z1, mp_int *x2, mp_int *z2, - const ECGroup *group, int kmflag) -{ - mp_err res = MP_OKAY; - mp_int t1, t2; - - MP_DIGITS(&t1) = 0; - MP_DIGITS(&t2) = 0; - MP_CHECKOK(mp_init(&t1, kmflag)); - MP_CHECKOK(mp_init(&t2, kmflag)); - - MP_CHECKOK(mp_copy(x, &t1)); - MP_CHECKOK(group->meth->field_mul(x1, z2, x1, group->meth)); - MP_CHECKOK(group->meth->field_mul(z1, x2, z1, group->meth)); - MP_CHECKOK(group->meth->field_mul(x1, z1, &t2, group->meth)); - MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth)); - MP_CHECKOK(group->meth->field_sqr(z1, z1, group->meth)); - MP_CHECKOK(group->meth->field_mul(z1, &t1, x1, group->meth)); - MP_CHECKOK(group->meth->field_add(x1, &t2, x1, group->meth)); - - CLEANUP: - mp_clear(&t1); - mp_clear(&t2); - return res; -} - -/* Compute the x, y affine coordinates from the point (x1, z1) (x2, z2) - * using Montgomery point multiplication algorithm Mxy() in appendix of - * Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over - * GF(2^m) without precomputation". Returns: 0 on error 1 if return value - * should be the point at infinity 2 otherwise */ -static int -gf2m_Mxy(const mp_int *x, const mp_int *y, mp_int *x1, mp_int *z1, - mp_int *x2, mp_int *z2, const ECGroup *group) -{ - mp_err res = MP_OKAY; - int ret = 0; - mp_int t3, t4, t5; - - MP_DIGITS(&t3) = 0; - MP_DIGITS(&t4) = 0; - MP_DIGITS(&t5) = 0; - MP_CHECKOK(mp_init(&t3, FLAG(x2))); - MP_CHECKOK(mp_init(&t4, FLAG(x2))); - MP_CHECKOK(mp_init(&t5, FLAG(x2))); - - if (mp_cmp_z(z1) == 0) { - mp_zero(x2); - mp_zero(z2); - ret = 1; - goto CLEANUP; - } - - if (mp_cmp_z(z2) == 0) { - MP_CHECKOK(mp_copy(x, x2)); - MP_CHECKOK(group->meth->field_add(x, y, z2, group->meth)); - ret = 2; - goto CLEANUP; - } - - MP_CHECKOK(mp_set_int(&t5, 1)); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(&t5, &t5, group->meth)); - } - - MP_CHECKOK(group->meth->field_mul(z1, z2, &t3, group->meth)); - - MP_CHECKOK(group->meth->field_mul(z1, x, z1, group->meth)); - MP_CHECKOK(group->meth->field_add(z1, x1, z1, group->meth)); - MP_CHECKOK(group->meth->field_mul(z2, x, z2, group->meth)); - MP_CHECKOK(group->meth->field_mul(z2, x1, x1, group->meth)); - MP_CHECKOK(group->meth->field_add(z2, x2, z2, group->meth)); - - MP_CHECKOK(group->meth->field_mul(z2, z1, z2, group->meth)); - MP_CHECKOK(group->meth->field_sqr(x, &t4, group->meth)); - MP_CHECKOK(group->meth->field_add(&t4, y, &t4, group->meth)); - MP_CHECKOK(group->meth->field_mul(&t4, &t3, &t4, group->meth)); - MP_CHECKOK(group->meth->field_add(&t4, z2, &t4, group->meth)); - - MP_CHECKOK(group->meth->field_mul(&t3, x, &t3, group->meth)); - MP_CHECKOK(group->meth->field_div(&t5, &t3, &t3, group->meth)); - MP_CHECKOK(group->meth->field_mul(&t3, &t4, &t4, group->meth)); - MP_CHECKOK(group->meth->field_mul(x1, &t3, x2, group->meth)); - MP_CHECKOK(group->meth->field_add(x2, x, z2, group->meth)); - - MP_CHECKOK(group->meth->field_mul(z2, &t4, z2, group->meth)); - MP_CHECKOK(group->meth->field_add(z2, y, z2, group->meth)); - - ret = 2; - - CLEANUP: - mp_clear(&t3); - mp_clear(&t4); - mp_clear(&t5); - if (res == MP_OKAY) { - return ret; - } else { - return 0; - } -} - -/* Computes R = nP based on algorithm 2P of Lopex, J. and Dahab, R. "Fast - * multiplication on elliptic curves over GF(2^m) without - * precomputation". Elliptic curve points P and R can be identical. Uses - * Montgomery projective coordinates. The timing parameter is ignored - * because this algorithm resists timing attacks by default. */ -mp_err -ec_GF2m_pt_mul_mont(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group, - int timing) -{ - mp_err res = MP_OKAY; - mp_int x1, x2, z1, z2; - int i, j; - mp_digit top_bit, mask; - - MP_DIGITS(&x1) = 0; - MP_DIGITS(&x2) = 0; - MP_DIGITS(&z1) = 0; - MP_DIGITS(&z2) = 0; - MP_CHECKOK(mp_init(&x1, FLAG(n))); - MP_CHECKOK(mp_init(&x2, FLAG(n))); - MP_CHECKOK(mp_init(&z1, FLAG(n))); - MP_CHECKOK(mp_init(&z2, FLAG(n))); - - /* if result should be point at infinity */ - if ((mp_cmp_z(n) == 0) || (ec_GF2m_pt_is_inf_aff(px, py) == MP_YES)) { - MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry)); - goto CLEANUP; - } - - MP_CHECKOK(mp_copy(px, &x1)); /* x1 = px */ - MP_CHECKOK(mp_set_int(&z1, 1)); /* z1 = 1 */ - MP_CHECKOK(group->meth->field_sqr(&x1, &z2, group->meth)); /* z2 = - * x1^2 = - * px^2 */ - MP_CHECKOK(group->meth->field_sqr(&z2, &x2, group->meth)); - MP_CHECKOK(group->meth->field_add(&x2, &group->curveb, &x2, group->meth)); /* x2 - * = - * px^4 - * + - * b - */ - - /* find top-most bit and go one past it */ - i = MP_USED(n) - 1; - j = MP_DIGIT_BIT - 1; - top_bit = 1; - top_bit <<= MP_DIGIT_BIT - 1; - mask = top_bit; - while (!(MP_DIGITS(n)[i] & mask)) { - mask >>= 1; - j--; - } - mask >>= 1; - j--; - - /* if top most bit was at word break, go to next word */ - if (!mask) { - i--; - j = MP_DIGIT_BIT - 1; - mask = top_bit; - } - - for (; i >= 0; i--) { - for (; j >= 0; j--) { - if (MP_DIGITS(n)[i] & mask) { - MP_CHECKOK(gf2m_Madd(px, &x1, &z1, &x2, &z2, group, FLAG(n))); - MP_CHECKOK(gf2m_Mdouble(&x2, &z2, group, FLAG(n))); - } else { - MP_CHECKOK(gf2m_Madd(px, &x2, &z2, &x1, &z1, group, FLAG(n))); - MP_CHECKOK(gf2m_Mdouble(&x1, &z1, group, FLAG(n))); - } - mask >>= 1; - } - j = MP_DIGIT_BIT - 1; - mask = top_bit; - } - - /* convert out of "projective" coordinates */ - i = gf2m_Mxy(px, py, &x1, &z1, &x2, &z2, group); - if (i == 0) { - res = MP_BADARG; - goto CLEANUP; - } else if (i == 1) { - MP_CHECKOK(ec_GF2m_pt_set_inf_aff(rx, ry)); - } else { - MP_CHECKOK(mp_copy(&x2, rx)); - MP_CHECKOK(mp_copy(&z2, ry)); - } - - CLEANUP: - mp_clear(&x1); - mp_clear(&x2); - mp_clear(&z1); - mp_clear(&z2); - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ec_naf.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ec_naf.c deleted file mode 100644 index bb26a02642854..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ec_naf.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stephen Fung , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "ecl-priv.h" - -/* Returns 2^e as an integer. This is meant to be used for small powers of - * two. */ -int -ec_twoTo(int e) -{ - int a = 1; - int i; - - for (i = 0; i < e; i++) { - a *= 2; - } - return a; -} - -/* Computes the windowed non-adjacent-form (NAF) of a scalar. Out should - * be an array of signed char's to output to, bitsize should be the number - * of bits of out, in is the original scalar, and w is the window size. - * NAF is discussed in the paper: D. Hankerson, J. Hernandez and A. - * Menezes, "Software implementation of elliptic curve cryptography over - * binary fields", Proc. CHES 2000. */ -mp_err -ec_compute_wNAF(signed char *out, int bitsize, const mp_int *in, int w) -{ - mp_int k; - mp_err res = MP_OKAY; - int i, twowm1, mask; - - twowm1 = ec_twoTo(w - 1); - mask = 2 * twowm1 - 1; - - MP_DIGITS(&k) = 0; - MP_CHECKOK(mp_init_copy(&k, in)); - - i = 0; - /* Compute wNAF form */ - while (mp_cmp_z(&k) > 0) { - if (mp_isodd(&k)) { - out[i] = MP_DIGIT(&k, 0) & mask; - if (out[i] >= twowm1) - out[i] -= 2 * twowm1; - - /* Subtract off out[i]. Note mp_sub_d only works with - * unsigned digits */ - if (out[i] >= 0) { - mp_sub_d(&k, out[i], &k); - } else { - mp_add_d(&k, -(out[i]), &k); - } - } else { - out[i] = 0; - } - mp_div_2(&k, &k); - i++; - } - /* Zero out the remaining elements of the out array. */ - for (; i < bitsize + 1; i++) { - out[i] = 0; - } - CLEANUP: - mp_clear(&k); - return res; - -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecc_impl.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecc_impl.h deleted file mode 100644 index 48aa13a4b0041..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecc_impl.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1994-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta and - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#ifndef _ECC_IMPL_H -#define _ECC_IMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "ecl-exp.h" - -/* - * Multi-platform definitions - */ -#ifdef __linux__ -#define B_FALSE FALSE -#define B_TRUE TRUE -typedef unsigned char uint8_t; -typedef unsigned long ulong_t; -typedef enum { B_FALSE, B_TRUE } boolean_t; -#endif /* __linux__ */ - -#ifdef _ALLBSD_SOURCE -#include -#define B_FALSE FALSE -#define B_TRUE TRUE -typedef unsigned long ulong_t; -typedef enum boolean { B_FALSE, B_TRUE } boolean_t; -#endif /* _ALLBSD_SOURCE */ - -#ifdef AIX -#define B_FALSE FALSE -#define B_TRUE TRUE -typedef unsigned char uint8_t; -typedef unsigned long ulong_t; -#endif /* AIX */ - -#ifdef _WIN32 -typedef unsigned char uint8_t; -typedef unsigned long ulong_t; -typedef enum boolean { B_FALSE, B_TRUE } boolean_t; -#define strdup _strdup /* Replace POSIX name with ISO C++ name */ -#endif /* _WIN32 */ - -#ifndef _KERNEL -#include -#endif /* _KERNEL */ - -#define EC_MAX_DIGEST_LEN 1024 /* max digest that can be signed */ -#define EC_MAX_POINT_LEN 145 /* max len of DER encoded Q */ -#define EC_MAX_VALUE_LEN 72 /* max len of ANSI X9.62 private value d */ -#define EC_MAX_SIG_LEN 144 /* max signature len for supported curves */ -#define EC_MIN_KEY_LEN 112 /* min key length in bits */ -#define EC_MAX_KEY_LEN 571 /* max key length in bits */ -#define EC_MAX_OID_LEN 10 /* max length of OID buffer */ - -/* - * Various structures and definitions from NSS are here. - */ - -#ifdef _KERNEL -#define PORT_ArenaAlloc(a, n, f) kmem_alloc((n), (f)) -#define PORT_ArenaZAlloc(a, n, f) kmem_zalloc((n), (f)) -#define PORT_ArenaGrow(a, b, c, d) NULL -#define PORT_ZAlloc(n, f) kmem_zalloc((n), (f)) -#define PORT_Alloc(n, f) kmem_alloc((n), (f)) -#else -#define PORT_ArenaAlloc(a, n, f) malloc((n)) -#define PORT_ArenaZAlloc(a, n, f) calloc(1, (n)) -#define PORT_ArenaGrow(a, b, c, d) NULL -#define PORT_ZAlloc(n, f) calloc(1, (n)) -#define PORT_Alloc(n, f) malloc((n)) -#endif - -#define PORT_NewArena(b) (char *)12345 -#define PORT_ArenaMark(a) NULL -#define PORT_ArenaUnmark(a, b) -#define PORT_ArenaRelease(a, m) -#define PORT_FreeArena(a, b) -#define PORT_Strlen(s) strlen((s)) -#define PORT_SetError(e) - -#define PRBool boolean_t -#define PR_TRUE B_TRUE -#define PR_FALSE B_FALSE - -#ifdef _KERNEL -#define PORT_Assert ASSERT -#define PORT_Memcpy(t, f, l) bcopy((f), (t), (l)) -#else -#define PORT_Assert assert -#define PORT_Memcpy(t, f, l) memcpy((t), (f), (l)) -#endif - -#define CHECK_OK(func) if (func == NULL) goto cleanup -#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup - -typedef enum { - siBuffer = 0, - siClearDataBuffer = 1, - siCipherDataBuffer = 2, - siDERCertBuffer = 3, - siEncodedCertBuffer = 4, - siDERNameBuffer = 5, - siEncodedNameBuffer = 6, - siAsciiNameString = 7, - siAsciiString = 8, - siDEROID = 9, - siUnsignedInteger = 10, - siUTCTime = 11, - siGeneralizedTime = 12 -} SECItemType; - -typedef struct SECItemStr SECItem; - -struct SECItemStr { - SECItemType type; - unsigned char *data; - unsigned int len; -}; - -typedef SECItem SECKEYECParams; - -typedef enum { ec_params_explicit, - ec_params_named -} ECParamsType; - -typedef enum { ec_field_GFp = 1, - ec_field_GF2m -} ECFieldType; - -struct ECFieldIDStr { - int size; /* field size in bits */ - ECFieldType type; - union { - SECItem prime; /* prime p for (GFp) */ - SECItem poly; /* irreducible binary polynomial for (GF2m) */ - } u; - int k1; /* first coefficient of pentanomial or - * the only coefficient of trinomial - */ - int k2; /* two remaining coefficients of pentanomial */ - int k3; -}; -typedef struct ECFieldIDStr ECFieldID; - -struct ECCurveStr { - SECItem a; /* contains octet stream encoding of - * field element (X9.62 section 4.3.3) - */ - SECItem b; - SECItem seed; -}; -typedef struct ECCurveStr ECCurve; - -typedef void PRArenaPool; - -struct ECParamsStr { - PRArenaPool * arena; - ECParamsType type; - ECFieldID fieldID; - ECCurve curve; - SECItem base; - SECItem order; - int cofactor; - SECItem DEREncoding; - ECCurveName name; - SECItem curveOID; -}; -typedef struct ECParamsStr ECParams; - -struct ECPublicKeyStr { - ECParams ecParams; - SECItem publicValue; /* elliptic curve point encoded as - * octet stream. - */ -}; -typedef struct ECPublicKeyStr ECPublicKey; - -struct ECPrivateKeyStr { - ECParams ecParams; - SECItem publicValue; /* encoded ec point */ - SECItem privateValue; /* private big integer */ - SECItem version; /* As per SEC 1, Appendix C, Section C.4 */ -}; -typedef struct ECPrivateKeyStr ECPrivateKey; - -typedef enum _SECStatus { - SECBufferTooSmall = -3, - SECWouldBlock = -2, - SECFailure = -1, - SECSuccess = 0 -} SECStatus; - -#ifdef _KERNEL -#define RNG_GenerateGlobalRandomBytes(p,l) ecc_knzero_random_generator((p), (l)) -#else -/* - This function is no longer required because the random bytes are now - supplied by the caller. Force a failure. -*/ -#define RNG_GenerateGlobalRandomBytes(p,l) SECFailure -#endif -#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup -#define MP_TO_SEC_ERROR(err) - -#define SECITEM_TO_MPINT(it, mp) \ - CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len)) - -extern int ecc_knzero_random_generator(uint8_t *, size_t); -extern ulong_t soft_nzero_random_generator(uint8_t *, ulong_t); - -extern SECStatus EC_DecodeParams(const SECItem *, ECParams **, int); -extern SECItem * SECITEM_AllocItem(PRArenaPool *, SECItem *, unsigned int, int); -extern SECStatus SECITEM_CopyItem(PRArenaPool *, SECItem *, const SECItem *, - int); -extern void SECITEM_FreeItem(SECItem *, boolean_t); -/* This function has been modified to accept an array of random bytes */ -extern SECStatus EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey, - const unsigned char* random, int randomlen, int); -/* This function has been modified to accept an array of random bytes */ -extern SECStatus ECDSA_SignDigest(ECPrivateKey *, SECItem *, const SECItem *, - const unsigned char* random, int randomlen, int, int timing); -extern SECStatus ECDSA_VerifyDigest(ECPublicKey *, const SECItem *, - const SECItem *, int); -extern SECStatus ECDH_Derive(SECItem *, ECParams *, SECItem *, boolean_t, - SECItem *, int); - -#ifdef __cplusplus -} -#endif - -#endif /* _ECC_IMPL_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c deleted file mode 100644 index 7667ac3215279..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c +++ /dev/null @@ -1,642 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Elliptic Curve Cryptography library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta and - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: Nov 2016 - *********************************************************************** */ - -#include - -#ifndef _WIN32 -#if !defined(__linux__) && !defined(_ALLBSD_SOURCE) -#include -#endif /* __linux__ || _ALLBSD_SOURCE */ -#include -#endif /* _WIN32 */ - -#ifdef _KERNEL -#include -#else -#include -#include -#endif -#include "ec.h" -#include "ecl-curve.h" -#include "ecc_impl.h" - -#define MAX_ECKEY_LEN 72 -#define SEC_ASN1_OBJECT_ID 0x06 - -/* - * Initializes a SECItem from a hexadecimal string - * - * Warning: This function ignores leading 00's, so any leading 00's - * in the hexadecimal string must be optional. - */ -static SECItem * -hexString2SECItem(PRArenaPool *arena, SECItem *item, const char *str, - int kmflag) -{ - int i = 0; - int byteval = 0; - int tmp = (int)strlen(str); - - if ((tmp % 2) != 0) return NULL; - - /* skip leading 00's unless the hex string is "00" */ - while ((tmp > 2) && (str[0] == '0') && (str[1] == '0')) { - str += 2; - tmp -= 2; - } - - item->data = (unsigned char *) PORT_ArenaAlloc(arena, tmp/2, kmflag); - if (item->data == NULL) return NULL; - item->len = tmp/2; - - while (str[i]) { - if ((str[i] >= '0') && (str[i] <= '9')) - tmp = str[i] - '0'; - else if ((str[i] >= 'a') && (str[i] <= 'f')) - tmp = str[i] - 'a' + 10; - else if ((str[i] >= 'A') && (str[i] <= 'F')) - tmp = str[i] - 'A' + 10; - else - return NULL; - - byteval = byteval * 16 + tmp; - if ((i % 2) != 0) { - item->data[i/2] = byteval; - byteval = 0; - } - i++; - } - - return item; -} - -static SECStatus -gf_populate_params(ECCurveName name, ECFieldType field_type, ECParams *params, - int kmflag) -{ - SECStatus rv = SECFailure; - const ECCurveParams *curveParams; - /* 2 ['0'+'4'] + MAX_ECKEY_LEN * 2 [x,y] * 2 [hex string] + 1 ['\0'] */ - char genenc[3 + 2 * 2 * MAX_ECKEY_LEN]; - - if (((int)name < ECCurve_noName) || (name > ECCurve_pastLastCurve)) - goto cleanup; - params->name = name; - curveParams = ecCurve_map[params->name]; - CHECK_OK(curveParams); - if ((strlen(curveParams->genx) + strlen(curveParams->geny)) > 2 * 2 * MAX_ECKEY_LEN) { - goto cleanup; - } - params->fieldID.size = curveParams->size; - params->fieldID.type = field_type; - if (field_type == ec_field_GFp) { - CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.prime, - curveParams->irr, kmflag)); - } else { - CHECK_OK(hexString2SECItem(NULL, ¶ms->fieldID.u.poly, - curveParams->irr, kmflag)); - } - CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.a, - curveParams->curvea, kmflag)); - CHECK_OK(hexString2SECItem(NULL, ¶ms->curve.b, - curveParams->curveb, kmflag)); - genenc[0] = '0'; - genenc[1] = '4'; - genenc[2] = '\0'; - strcat(genenc, curveParams->genx); - strcat(genenc, curveParams->geny); - CHECK_OK(hexString2SECItem(NULL, ¶ms->base, genenc, kmflag)); - CHECK_OK(hexString2SECItem(NULL, ¶ms->order, - curveParams->order, kmflag)); - params->cofactor = curveParams->cofactor; - - rv = SECSuccess; - -cleanup: - return rv; -} - -ECCurveName SECOID_FindOIDTag(const SECItem *); - -SECStatus -EC_FillParams(PRArenaPool *arena, const SECItem *encodedParams, - ECParams *params, int kmflag) -{ - SECStatus rv = SECFailure; - ECCurveName tag; - SECItem oid = { siBuffer, NULL, 0}; - -#if EC_DEBUG - int i; - - printf("Encoded params in EC_DecodeParams: "); - for (i = 0; i < encodedParams->len; i++) { - printf("%02x:", encodedParams->data[i]); - } - printf("\n"); -#endif - - if ((encodedParams->len != ANSI_X962_CURVE_OID_TOTAL_LEN) && - (encodedParams->len != SECG_CURVE_OID_TOTAL_LEN) && - (encodedParams->len != BRAINPOOL_CURVE_OID_TOTAL_LEN)) { - PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE); - return SECFailure; - }; - - oid.len = encodedParams->len - 2; - oid.data = encodedParams->data + 2; - if ((encodedParams->data[0] != SEC_ASN1_OBJECT_ID) || - ((tag = SECOID_FindOIDTag(&oid)) == ECCurve_noName)) { - PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE); - return SECFailure; - } - - params->arena = arena; - params->cofactor = 0; - params->type = ec_params_named; - params->name = ECCurve_noName; - - /* For named curves, fill out curveOID */ - params->curveOID.len = oid.len; - params->curveOID.data = (unsigned char *) PORT_ArenaAlloc(NULL, oid.len, - kmflag); - if (params->curveOID.data == NULL) goto cleanup; - memcpy(params->curveOID.data, oid.data, oid.len); - -#if EC_DEBUG -#ifndef SECOID_FindOIDTagDescription - printf("Curve: %s\n", ecCurve_map[tag]->text); -#else - printf("Curve: %s\n", SECOID_FindOIDTagDescription(tag)); -#endif -#endif - - switch (tag) { - - /* Binary curves */ - - case ECCurve_X9_62_CHAR2_PNB163V1: - /* Populate params for c2pnb163v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB163V2: - /* Populate params for c2pnb163v2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB163V3: - /* Populate params for c2pnb163v3 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB163V3, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB176V1: - /* Populate params for c2pnb176v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB176V1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB191V1: - /* Populate params for c2tnb191v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB191V2: - /* Populate params for c2tnb191v2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB191V3: - /* Populate params for c2tnb191v3 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB191V3, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB208W1: - /* Populate params for c2pnb208w1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB208W1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB239V1: - /* Populate params for c2tnb239v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB239V2: - /* Populate params for c2tnb239v2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB239V3: - /* Populate params for c2tnb239v3 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB239V3, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB272W1: - /* Populate params for c2pnb272w1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB272W1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB304W1: - /* Populate params for c2pnb304w1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB304W1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB359V1: - /* Populate params for c2tnb359v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB359V1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_PNB368W1: - /* Populate params for c2pnb368w1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_PNB368W1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_X9_62_CHAR2_TNB431R1: - /* Populate params for c2tnb431r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_CHAR2_TNB431R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_113R1: - /* Populate params for sect113r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_113R2: - /* Populate params for sect113r2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_113R2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_131R1: - /* Populate params for sect131r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_131R2: - /* Populate params for sect131r2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_131R2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_163K1: - /* Populate params for sect163k1 - * (the NIST K-163 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_163R1: - /* Populate params for sect163r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_163R2: - /* Populate params for sect163r2 - * (the NIST B-163 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_163R2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_193R1: - /* Populate params for sect193r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_193R2: - /* Populate params for sect193r2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_193R2, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_233K1: - /* Populate params for sect233k1 - * (the NIST K-233 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_233R1: - /* Populate params for sect233r1 - * (the NIST B-233 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_233R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_239K1: - /* Populate params for sect239k1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_239K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_283K1: - /* Populate params for sect283k1 - * (the NIST K-283 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_283R1: - /* Populate params for sect283r1 - * (the NIST B-283 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_283R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_409K1: - /* Populate params for sect409k1 - * (the NIST K-409 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_409R1: - /* Populate params for sect409r1 - * (the NIST B-409 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_409R1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_571K1: - /* Populate params for sect571k1 - * (the NIST K-571 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571K1, ec_field_GF2m, - params, kmflag) ); - break; - - case ECCurve_SECG_CHAR2_571R1: - /* Populate params for sect571r1 - * (the NIST B-571 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_CHAR2_571R1, ec_field_GF2m, - params, kmflag) ); - break; - - /* Prime curves */ - - case ECCurve_X9_62_PRIME_192V1: - /* Populate params for prime192v1 aka secp192r1 - * (the NIST P-192 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_192V2: - /* Populate params for prime192v2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V2, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_192V3: - /* Populate params for prime192v3 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_192V3, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_239V1: - /* Populate params for prime239v1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_239V2: - /* Populate params for prime239v2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V2, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_239V3: - /* Populate params for prime239v3 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_239V3, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_X9_62_PRIME_256V1: - /* Populate params for prime256v1 aka secp256r1 - * (the NIST P-256 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_X9_62_PRIME_256V1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_112R1: - /* Populate params for secp112r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_112R2: - /* Populate params for secp112r2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_112R2, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_128R1: - /* Populate params for secp128r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_128R2: - /* Populate params for secp128r2 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_128R2, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_160K1: - /* Populate params for secp160k1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160K1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_160R1: - /* Populate params for secp160r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_160R2: - /* Populate params for secp160r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_160R2, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_192K1: - /* Populate params for secp192k1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_192K1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_224K1: - /* Populate params for secp224k1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224K1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_224R1: - /* Populate params for secp224r1 - * (the NIST P-224 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_224R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_256K1: - /* Populate params for secp256k1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_256K1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_384R1: - /* Populate params for secp384r1 - * (the NIST P-384 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_384R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_SECG_PRIME_521R1: - /* Populate params for secp521r1 - * (the NIST P-521 curve) - */ - CHECK_SEC_OK( gf_populate_params(ECCurve_SECG_PRIME_521R1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_BrainpoolP256r1: - /* Populate params for brainpoolP256r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_BrainpoolP256r1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_BrainpoolP320r1: - /* Populate params for brainpoolP320r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_BrainpoolP320r1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_BrainpoolP384r1: - /* Populate params for brainpoolP384r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_BrainpoolP384r1, ec_field_GFp, - params, kmflag) ); - break; - - case ECCurve_BrainpoolP512r1: - /* Populate params for brainpoolP512r1 */ - CHECK_SEC_OK( gf_populate_params(ECCurve_BrainpoolP512r1, ec_field_GFp, - params, kmflag) ); - break; - - default: - break; - }; - -cleanup: - if (!params->cofactor) { - PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE); -#if EC_DEBUG - printf("Unrecognized curve, returning NULL params\n"); -#endif - } - - return rv; -} - -SECStatus -EC_DecodeParams(const SECItem *encodedParams, ECParams **ecparams, int kmflag) -{ - PRArenaPool *arena; - ECParams *params; - SECStatus rv = SECFailure; - - /* Initialize an arena for the ECParams structure */ - if (!(arena = PORT_NewArena(NSS_FREEBL_DEFAULT_CHUNKSIZE))) - return SECFailure; - - params = (ECParams *)PORT_ArenaZAlloc(NULL, sizeof(ECParams), kmflag); - if (!params) { - PORT_FreeArena(NULL, B_TRUE); - return SECFailure; - } - - /* Copy the encoded params */ - SECITEM_AllocItem(arena, &(params->DEREncoding), encodedParams->len, - kmflag); - memcpy(params->DEREncoding.data, encodedParams->data, encodedParams->len); - - /* Fill out the rest of the ECParams structure based on - * the encoded params - */ - rv = EC_FillParams(NULL, encodedParams, params, kmflag); - if (rv == SECFailure) { - PORT_FreeArena(NULL, B_TRUE); - return SECFailure; - } else { - *ecparams = params;; - return SECSuccess; - } -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-curve.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-curve.h deleted file mode 100644 index aaa75e5d2d300..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-curve.h +++ /dev/null @@ -1,733 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#ifndef _ECL_CURVE_H -#define _ECL_CURVE_H - -#include "ecl-exp.h" -#ifndef _KERNEL -#include -#endif - -/* NIST prime curves */ -static const ECCurveParams ecCurve_NIST_P192 = { - "NIST-P192", ECField_GFp, 192, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", - "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", - "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", - "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811", - "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", 1 -}; - -static const ECCurveParams ecCurve_NIST_P224 = { - "NIST-P224", ECField_GFp, 224, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", - "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", - "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", - "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", 1 -}; - -static const ECCurveParams ecCurve_NIST_P256 = { - "NIST-P256", ECField_GFp, 256, - "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", - "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", - "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", - "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", - "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", - "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 1 -}; - -static const ECCurveParams ecCurve_NIST_P384 = { - "NIST-P384", ECField_GFp, 384, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", - "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", - "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", - "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", - 1 -}; - -static const ECCurveParams ecCurve_NIST_P521 = { - "NIST-P521", ECField_GFp, 521, - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", - "0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", - "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", - "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", - 1 -}; - -/* NIST binary curves */ -static const ECCurveParams ecCurve_NIST_K163 = { - "NIST-K163", ECField_GF2m, 163, - "0800000000000000000000000000000000000000C9", - "000000000000000000000000000000000000000001", - "000000000000000000000000000000000000000001", - "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8", - "0289070FB05D38FF58321F2E800536D538CCDAA3D9", - "04000000000000000000020108A2E0CC0D99F8A5EF", 2 -}; - -static const ECCurveParams ecCurve_NIST_B163 = { - "NIST-B163", ECField_GF2m, 163, - "0800000000000000000000000000000000000000C9", - "000000000000000000000000000000000000000001", - "020A601907B8C953CA1481EB10512F78744A3205FD", - "03F0EBA16286A2D57EA0991168D4994637E8343E36", - "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", - "040000000000000000000292FE77E70C12A4234C33", 2 -}; - -static const ECCurveParams ecCurve_NIST_K233 = { - "NIST-K233", ECField_GF2m, 233, - "020000000000000000000000000000000000000004000000000000000001", - "000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000001", - "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126", - "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3", - "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", 4 -}; - -static const ECCurveParams ecCurve_NIST_B233 = { - "NIST-B233", ECField_GF2m, 233, - "020000000000000000000000000000000000000004000000000000000001", - "000000000000000000000000000000000000000000000000000000000001", - "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD", - "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B", - "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052", - "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", 2 -}; - -static const ECCurveParams ecCurve_NIST_K283 = { - "NIST-K283", ECField_GF2m, 283, - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "000000000000000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000000000000000001", - "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836", - "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259", - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", 4 -}; - -static const ECCurveParams ecCurve_NIST_B283 = { - "NIST-B283", ECField_GF2m, 283, - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "000000000000000000000000000000000000000000000000000000000000000000000001", - "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", - "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053", - "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4", - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", 2 -}; - -static const ECCurveParams ecCurve_NIST_K409 = { - "NIST-K409", ECField_GF2m, 409, - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746", - "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B", - "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", 4 -}; - -static const ECCurveParams ecCurve_NIST_B409 = { - "NIST-B409", ECField_GF2m, 409, - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F", - "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7", - "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706", - "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", 2 -}; - -static const ECCurveParams ecCurve_NIST_K571 = { - "NIST-K571", ECField_GF2m, 571, - "080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972", - "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3", - "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", 4 -}; - -static const ECCurveParams ecCurve_NIST_B571 = { - "NIST-B571", ECField_GF2m, 571, - "080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A", - "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19", - "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B", - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", 2 -}; - -/* ANSI X9.62 prime curves */ -static const ECCurveParams ecCurve_X9_62_PRIME_192V2 = { - "X9.62 P-192V2", ECField_GFp, 192, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", - "CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953", - "EEA2BAE7E1497842F2DE7769CFE9C989C072AD696F48034A", - "6574D11D69B6EC7A672BB82A083DF2F2B0847DE970B2DE15", - "FFFFFFFFFFFFFFFFFFFFFFFE5FB1A724DC80418648D8DD31", 1 -}; - -static const ECCurveParams ecCurve_X9_62_PRIME_192V3 = { - "X9.62 P-192V3", ECField_GFp, 192, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", - "22123DC2395A05CAA7423DAECCC94760A7D462256BD56916", - "7D29778100C65A1DA1783716588DCE2B8B4AEE8E228F1896", - "38A90F22637337334B49DCB66A6DC8F9978ACA7648A943B0", - "FFFFFFFFFFFFFFFFFFFFFFFF7A62D031C83F4294F640EC13", 1 -}; - -static const ECCurveParams ecCurve_X9_62_PRIME_239V1 = { - "X9.62 P-239V1", ECField_GFp, 239, - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", - "6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A", - "0FFA963CDCA8816CCC33B8642BEDF905C3D358573D3F27FBBD3B3CB9AAAF", - "7DEBE8E4E90A5DAE6E4054CA530BA04654B36818CE226B39FCCB7B02F1AE", - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF9E5E9A9F5D9071FBD1522688909D0B", 1 -}; - -static const ECCurveParams ecCurve_X9_62_PRIME_239V2 = { - "X9.62 P-239V2", ECField_GFp, 239, - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", - "617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C", - "38AF09D98727705120C921BB5E9E26296A3CDCF2F35757A0EAFD87B830E7", - "5B0125E4DBEA0EC7206DA0FC01D9B081329FB555DE6EF460237DFF8BE4BA", - "7FFFFFFFFFFFFFFFFFFFFFFF800000CFA7E8594377D414C03821BC582063", 1 -}; - -static const ECCurveParams ecCurve_X9_62_PRIME_239V3 = { - "X9.62 P-239V3", ECField_GFp, 239, - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF", - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC", - "255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E", - "6768AE8E18BB92CFCF005C949AA2C6D94853D0E660BBF854B1C9505FE95A", - "1607E6898F390C06BC1D552BAD226F3B6FCFE48B6E818499AF18E3ED6CF3", - "7FFFFFFFFFFFFFFFFFFFFFFF7FFFFF975DEB41B3A6057C3C432146526551", 1 -}; - -/* ANSI X9.62 binary curves */ -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V1 = { - "X9.62 C2-PNB163V1", ECField_GF2m, 163, - "080000000000000000000000000000000000000107", - "072546B5435234A422E0789675F432C89435DE5242", - "00C9517D06D5240D3CFF38C74B20B6CD4D6F9DD4D9", - "07AF69989546103D79329FCC3D74880F33BBE803CB", - "01EC23211B5966ADEA1D3F87F7EA5848AEF0B7CA9F", - "0400000000000000000001E60FC8821CC74DAEAFC1", 2 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V2 = { - "X9.62 C2-PNB163V2", ECField_GF2m, 163, - "080000000000000000000000000000000000000107", - "0108B39E77C4B108BED981ED0E890E117C511CF072", - "0667ACEB38AF4E488C407433FFAE4F1C811638DF20", - "0024266E4EB5106D0A964D92C4860E2671DB9B6CC5", - "079F684DDF6684C5CD258B3890021B2386DFD19FC5", - "03FFFFFFFFFFFFFFFFFFFDF64DE1151ADBB78F10A7", 2 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB163V3 = { - "X9.62 C2-PNB163V3", ECField_GF2m, 163, - "080000000000000000000000000000000000000107", - "07A526C63D3E25A256A007699F5447E32AE456B50E", - "03F7061798EB99E238FD6F1BF95B48FEEB4854252B", - "02F9F87B7C574D0BDECF8A22E6524775F98CDEBDCB", - "05B935590C155E17EA48EB3FF3718B893DF59A05D0", - "03FFFFFFFFFFFFFFFFFFFE1AEE140F110AFF961309", 2 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB176V1 = { - "X9.62 C2-PNB176V1", ECField_GF2m, 176, - "0100000000000000000000000000000000080000000007", - "E4E6DB2995065C407D9D39B8D0967B96704BA8E9C90B", - "5DDA470ABE6414DE8EC133AE28E9BBD7FCEC0AE0FFF2", - "8D16C2866798B600F9F08BB4A8E860F3298CE04A5798", - "6FA4539C2DADDDD6BAB5167D61B436E1D92BB16A562C", - "00010092537397ECA4F6145799D62B0A19CE06FE26AD", 0xFF6E -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V1 = { - "X9.62 C2-TNB191V1", ECField_GF2m, 191, - "800000000000000000000000000000000000000000000201", - "2866537B676752636A68F56554E12640276B649EF7526267", - "2E45EF571F00786F67B0081B9495A3D95462F5DE0AA185EC", - "36B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D", - "765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB", - "40000000000000000000000004A20E90C39067C893BBB9A5", 2 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V2 = { - "X9.62 C2-TNB191V2", ECField_GF2m, 191, - "800000000000000000000000000000000000000000000201", - "401028774D7777C7B7666D1366EA432071274F89FF01E718", - "0620048D28BCBD03B6249C99182B7C8CD19700C362C46A01", - "3809B2B7CC1B28CC5A87926AAD83FD28789E81E2C9E3BF10", - "17434386626D14F3DBF01760D9213A3E1CF37AEC437D668A", - "20000000000000000000000050508CB89F652824E06B8173", 4 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB191V3 = { - "X9.62 C2-TNB191V3", ECField_GF2m, 191, - "800000000000000000000000000000000000000000000201", - "6C01074756099122221056911C77D77E77A777E7E7E77FCB", - "71FE1AF926CF847989EFEF8DB459F66394D90F32AD3F15E8", - "375D4CE24FDE434489DE8746E71786015009E66E38A926DD", - "545A39176196575D985999366E6AD34CE0A77CD7127B06BE", - "155555555555555555555555610C0B196812BFB6288A3EA3", 6 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB208W1 = { - "X9.62 C2-PNB208W1", ECField_GF2m, 208, - "010000000000000000000000000000000800000000000000000007", - "0000000000000000000000000000000000000000000000000000", - "C8619ED45A62E6212E1160349E2BFA844439FAFC2A3FD1638F9E", - "89FDFBE4ABE193DF9559ECF07AC0CE78554E2784EB8C1ED1A57A", - "0F55B51A06E78E9AC38A035FF520D8B01781BEB1A6BB08617DE3", - "000101BAF95C9723C57B6C21DA2EFF2D5ED588BDD5717E212F9D", 0xFE48 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V1 = { - "X9.62 C2-TNB239V1", ECField_GF2m, 239, - "800000000000000000000000000000000000000000000000001000000001", - "32010857077C5431123A46B808906756F543423E8D27877578125778AC76", - "790408F2EEDAF392B012EDEFB3392F30F4327C0CA3F31FC383C422AA8C16", - "57927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D", - "61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305", - "2000000000000000000000000000000F4D42FFE1492A4993F1CAD666E447", 4 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V2 = { - "X9.62 C2-TNB239V2", ECField_GF2m, 239, - "800000000000000000000000000000000000000000000000001000000001", - "4230017757A767FAE42398569B746325D45313AF0766266479B75654E65F", - "5037EA654196CFF0CD82B2C14A2FCF2E3FF8775285B545722F03EACDB74B", - "28F9D04E900069C8DC47A08534FE76D2B900B7D7EF31F5709F200C4CA205", - "5667334C45AFF3B5A03BAD9DD75E2C71A99362567D5453F7FA6E227EC833", - "1555555555555555555555555555553C6F2885259C31E3FCDF154624522D", 6 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB239V3 = { - "X9.62 C2-TNB239V3", ECField_GF2m, 239, - "800000000000000000000000000000000000000000000000001000000001", - "01238774666A67766D6676F778E676B66999176666E687666D8766C66A9F", - "6A941977BA9F6A435199ACFC51067ED587F519C5ECB541B8E44111DE1D40", - "70F6E9D04D289C4E89913CE3530BFDE903977D42B146D539BF1BDE4E9C92", - "2E5A0EAF6E5E1305B9004DCE5C0ED7FE59A35608F33837C816D80B79F461", - "0CCCCCCCCCCCCCCCCCCCCCCCCCCCCCAC4912D2D9DF903EF9888B8A0E4CFF", 0xA -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB272W1 = { - "X9.62 C2-PNB272W1", ECField_GF2m, 272, - "010000000000000000000000000000000000000000000000000000010000000000000B", - "91A091F03B5FBA4AB2CCF49C4EDD220FB028712D42BE752B2C40094DBACDB586FB20", - "7167EFC92BB2E3CE7C8AAAFF34E12A9C557003D7C73A6FAF003F99F6CC8482E540F7", - "6108BABB2CEEBCF787058A056CBE0CFE622D7723A289E08A07AE13EF0D10D171DD8D", - "10C7695716851EEF6BA7F6872E6142FBD241B830FF5EFCACECCAB05E02005DDE9D23", - "000100FAF51354E0E39E4892DF6E319C72C8161603FA45AA7B998A167B8F1E629521", - 0xFF06 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB304W1 = { - "X9.62 C2-PNB304W1", ECField_GF2m, 304, - "010000000000000000000000000000000000000000000000000000000000000000000000000807", - "FD0D693149A118F651E6DCE6802085377E5F882D1B510B44160074C1288078365A0396C8E681", - "BDDB97E555A50A908E43B01C798EA5DAA6788F1EA2794EFCF57166B8C14039601E55827340BE", - "197B07845E9BE2D96ADB0F5F3C7F2CFFBD7A3EB8B6FEC35C7FD67F26DDF6285A644F740A2614", - "E19FBEB76E0DA171517ECF401B50289BF014103288527A9B416A105E80260B549FDC1B92C03B", - "000101D556572AABAC800101D556572AABAC8001022D5C91DD173F8FB561DA6899164443051D", 0xFE2E -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB359V1 = { - "X9.62 C2-TNB359V1", ECField_GF2m, 359, - "800000000000000000000000000000000000000000000000000000000000000000000000100000000000000001", - "5667676A654B20754F356EA92017D946567C46675556F19556A04616B567D223A5E05656FB549016A96656A557", - "2472E2D0197C49363F1FE7F5B6DB075D52B6947D135D8CA445805D39BC345626089687742B6329E70680231988", - "3C258EF3047767E7EDE0F1FDAA79DAEE3841366A132E163ACED4ED2401DF9C6BDCDE98E8E707C07A2239B1B097", - "53D7E08529547048121E9C95F3791DD804963948F34FAE7BF44EA82365DC7868FE57E4AE2DE211305A407104BD", - "01AF286BCA1AF286BCA1AF286BCA1AF286BCA1AF286BC9FB8F6B85C556892C20A7EB964FE7719E74F490758D3B", 0x4C -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_PNB368W1 = { - "X9.62 C2-PNB368W1", ECField_GF2m, 368, - "0100000000000000000000000000000000000000000000000000000000000000000000002000000000000000000007", - "E0D2EE25095206F5E2A4F9ED229F1F256E79A0E2B455970D8D0D865BD94778C576D62F0AB7519CCD2A1A906AE30D", - "FC1217D4320A90452C760A58EDCD30C8DD069B3C34453837A34ED50CB54917E1C2112D84D164F444F8F74786046A", - "1085E2755381DCCCE3C1557AFA10C2F0C0C2825646C5B34A394CBCFA8BC16B22E7E789E927BE216F02E1FB136A5F", - "7B3EB1BDDCBA62D5D8B2059B525797FC73822C59059C623A45FF3843CEE8F87CD1855ADAA81E2A0750B80FDA2310", - "00010090512DA9AF72B08349D98A5DD4C7B0532ECA51CE03E2D10F3B7AC579BD87E909AE40A6F131E9CFCE5BD967", 0xFF70 -}; - -static const ECCurveParams ecCurve_X9_62_CHAR2_TNB431R1 = { - "X9.62 C2-TNB431R1", ECField_GF2m, 431, - "800000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000001", - "1A827EF00DD6FC0E234CAF046C6A5D8A85395B236CC4AD2CF32A0CADBDC9DDF620B0EB9906D0957F6C6FEACD615468DF104DE296CD8F", - "10D9B4A3D9047D8B154359ABFB1B7F5485B04CEB868237DDC9DEDA982A679A5A919B626D4E50A8DD731B107A9962381FB5D807BF2618", - "120FC05D3C67A99DE161D2F4092622FECA701BE4F50F4758714E8A87BBF2A658EF8C21E7C5EFE965361F6C2999C0C247B0DBD70CE6B7", - "20D0AF8903A96F8D5FA2C255745D3C451B302C9346D9B7E485E7BCE41F6B591F3E8F6ADDCBB0BC4C2F947A7DE1A89B625D6A598B3760", - "0340340340340340340340340340340340340340340340340340340323C313FAB50589703B5EC68D3587FEC60D161CC149C1AD4A91", 0x2760 -}; - -/* SEC2 prime curves */ -static const ECCurveParams ecCurve_SECG_PRIME_112R1 = { - "SECP-112R1", ECField_GFp, 112, - "DB7C2ABF62E35E668076BEAD208B", - "DB7C2ABF62E35E668076BEAD2088", - "659EF8BA043916EEDE8911702B22", - "09487239995A5EE76B55F9C2F098", - "A89CE5AF8724C0A23E0E0FF77500", - "DB7C2ABF62E35E7628DFAC6561C5", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_112R2 = { - "SECP-112R2", ECField_GFp, 112, - "DB7C2ABF62E35E668076BEAD208B", - "6127C24C05F38A0AAAF65C0EF02C", - "51DEF1815DB5ED74FCC34C85D709", - "4BA30AB5E892B4E1649DD0928643", - "adcd46f5882e3747def36e956e97", - "36DF0AAFD8B8D7597CA10520D04B", 4 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_128R1 = { - "SECP-128R1", ECField_GFp, 128, - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", - "E87579C11079F43DD824993C2CEE5ED3", - "161FF7528B899B2D0C28607CA52C5B86", - "CF5AC8395BAFEB13C02DA292DDED7A83", - "FFFFFFFE0000000075A30D1B9038A115", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_128R2 = { - "SECP-128R2", ECField_GFp, 128, - "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", - "D6031998D1B3BBFEBF59CC9BBFF9AEE1", - "5EEEFCA380D02919DC2C6558BB6D8A5D", - "7B6AA5D85E572983E6FB32A7CDEBC140", - "27B6916A894D3AEE7106FE805FC34B44", - "3FFFFFFF7FFFFFFFBE0024720613B5A3", 4 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_160K1 = { - "SECP-160K1", ECField_GFp, 160, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", - "0000000000000000000000000000000000000000", - "0000000000000000000000000000000000000007", - "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB", - "938CF935318FDCED6BC28286531733C3F03C4FEE", - "0100000000000000000001B8FA16DFAB9ACA16B6B3", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_160R1 = { - "SECP-160R1", ECField_GFp, 160, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", - "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", - "4A96B5688EF573284664698968C38BB913CBFC82", - "23A628553168947D59DCC912042351377AC5FB32", - "0100000000000000000001F4C8F927AED3CA752257", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_160R2 = { - "SECP-160R2", ECField_GFp, 160, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC70", - "B4E134D3FB59EB8BAB57274904664D5AF50388BA", - "52DCB034293A117E1F4FF11B30F7199D3144CE6D", - "FEAFFEF2E331F296E071FA0DF9982CFEA7D43F2E", - "0100000000000000000000351EE786A818F3A1A16B", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_192K1 = { - "SECP-192K1", ECField_GFp, 192, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", - "000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000003", - "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", - "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", - "FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_224K1 = { - "SECP-224K1", ECField_GFp, 224, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFE56D", - "00000000000000000000000000000000000000000000000000000000", - "00000000000000000000000000000000000000000000000000000005", - "A1455B334DF099DF30FC28A169A467E9E47075A90F7E650EB6B7A45C", - "7E089FED7FBA344282CAFBD6F7E319F7C0B0BD59E2CA4BDB556D61A5", - "010000000000000000000000000001DCE8D2EC6184CAF0A971769FB1F7", 1 -}; - -static const ECCurveParams ecCurve_SECG_PRIME_256K1 = { - "SECP-256K1", ECField_GFp, 256, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", - "0000000000000000000000000000000000000000000000000000000000000000", - "0000000000000000000000000000000000000000000000000000000000000007", - "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", - "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 1 -}; - -/* SEC2 binary curves */ -static const ECCurveParams ecCurve_SECG_CHAR2_113R1 = { - "SECT-113R1", ECField_GF2m, 113, - "020000000000000000000000000201", - "003088250CA6E7C7FE649CE85820F7", - "00E8BEE4D3E2260744188BE0E9C723", - "009D73616F35F4AB1407D73562C10F", - "00A52830277958EE84D1315ED31886", - "0100000000000000D9CCEC8A39E56F", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_113R2 = { - "SECT-113R2", ECField_GF2m, 113, - "020000000000000000000000000201", - "00689918DBEC7E5A0DD6DFC0AA55C7", - "0095E9A9EC9B297BD4BF36E059184F", - "01A57A6A7B26CA5EF52FCDB8164797", - "00B3ADC94ED1FE674C06E695BABA1D", - "010000000000000108789B2496AF93", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_131R1 = { - "SECT-131R1", ECField_GF2m, 131, - "080000000000000000000000000000010D", - "07A11B09A76B562144418FF3FF8C2570B8", - "0217C05610884B63B9C6C7291678F9D341", - "0081BAF91FDF9833C40F9C181343638399", - "078C6E7EA38C001F73C8134B1B4EF9E150", - "0400000000000000023123953A9464B54D", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_131R2 = { - "SECT-131R2", ECField_GF2m, 131, - "080000000000000000000000000000010D", - "03E5A88919D7CAFCBF415F07C2176573B2", - "04B8266A46C55657AC734CE38F018F2192", - "0356DCD8F2F95031AD652D23951BB366A8", - "0648F06D867940A5366D9E265DE9EB240F", - "0400000000000000016954A233049BA98F", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_163R1 = { - "SECT-163R1", ECField_GF2m, 163, - "0800000000000000000000000000000000000000C9", - "07B6882CAAEFA84F9554FF8428BD88E246D2782AE2", - "0713612DCDDCB40AAB946BDA29CA91F73AF958AFD9", - "0369979697AB43897789566789567F787A7876A654", - "00435EDB42EFAFB2989D51FEFCE3C80988F41FF883", - "03FFFFFFFFFFFFFFFFFFFF48AAB689C29CA710279B", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_193R1 = { - "SECT-193R1", ECField_GF2m, 193, - "02000000000000000000000000000000000000000000008001", - "0017858FEB7A98975169E171F77B4087DE098AC8A911DF7B01", - "00FDFB49BFE6C3A89FACADAA7A1E5BBC7CC1C2E5D831478814", - "01F481BC5F0FF84A74AD6CDF6FDEF4BF6179625372D8C0C5E1", - "0025E399F2903712CCF3EA9E3A1AD17FB0B3201B6AF7CE1B05", - "01000000000000000000000000C7F34A778F443ACC920EBA49", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_193R2 = { - "SECT-193R2", ECField_GF2m, 193, - "02000000000000000000000000000000000000000000008001", - "0163F35A5137C2CE3EA6ED8667190B0BC43ECD69977702709B", - "00C9BB9E8927D4D64C377E2AB2856A5B16E3EFB7F61D4316AE", - "00D9B67D192E0367C803F39E1A7E82CA14A651350AAE617E8F", - "01CE94335607C304AC29E7DEFBD9CA01F596F927224CDECF6C", - "010000000000000000000000015AAB561B005413CCD4EE99D5", 2 -}; - -static const ECCurveParams ecCurve_SECG_CHAR2_239K1 = { - "SECT-239K1", ECField_GF2m, 239, - "800000000000000000004000000000000000000000000000000000000001", - "000000000000000000000000000000000000000000000000000000000000", - "000000000000000000000000000000000000000000000000000000000001", - "29A0B6A887A983E9730988A68727A8B2D126C44CC2CC7B2A6555193035DC", - "76310804F12E549BDB011C103089E73510ACB275FC312A5DC6B76553F0CA", - "2000000000000000000000000000005A79FEC67CB6E91F1C1DA800E478A5", 4 -}; - -/* WTLS curves */ -static const ECCurveParams ecCurve_WTLS_1 = { - "WTLS-1", ECField_GF2m, 113, - "020000000000000000000000000201", - "000000000000000000000000000001", - "000000000000000000000000000001", - "01667979A40BA497E5D5C270780617", - "00F44B4AF1ECC2630E08785CEBCC15", - "00FFFFFFFFFFFFFFFDBF91AF6DEA73", 2 -}; - -static const ECCurveParams ecCurve_WTLS_8 = { - "WTLS-8", ECField_GFp, 112, - "FFFFFFFFFFFFFFFFFFFFFFFFFDE7", - "0000000000000000000000000000", - "0000000000000000000000000003", - "0000000000000000000000000001", - "0000000000000000000000000002", - "0100000000000001ECEA551AD837E9", 1 -}; - -static const ECCurveParams ecCurve_WTLS_9 = { - "WTLS-9", ECField_GFp, 160, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC808F", - "0000000000000000000000000000000000000000", - "0000000000000000000000000000000000000003", - "0000000000000000000000000000000000000001", - "0000000000000000000000000000000000000002", - "0100000000000000000001CDC98AE0E2DE574ABF33", 1 -}; - -static const ECCurveParams ecCurve_BrainpoolP256r1 = { - "brainpoolP256r1", ECField_GFp, 256, - "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", - "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", - "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", - "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", - "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", - "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", 1 -}; - -static const ECCurveParams ecCurve_BrainpoolP320r1 = { - "brainpoolP320r1", ECField_GFp, 320, - "D35E472036BC4FB7E13C785ED201E065F98FCFA6F6F40DEF4F92B9EC7893EC28FCD412B1F1B32E27", - "3EE30B568FBAB0F883CCEBD46D3F3BB8A2A73513F5EB79DA66190EB085FFA9F492F375A97D860EB4", - "520883949DFDBC42D3AD198640688A6FE13F41349554B49ACC31DCCD884539816F5EB4AC8FB1F1A6", - "43BD7E9AFB53D8B85289BCC48EE5BFE6F20137D10A087EB6E7871E2A10A599C710AF8D0D39E20611", - "14FDD05545EC1CC8AB4093247F77275E0743FFED117182EAA9C77877AAAC6AC7D35245D1692E8EE1", - "D35E472036BC4FB7E13C785ED201E065F98FCFA5B68F12A32D482EC7EE8658E98691555B44C59311", 1 -}; - -static const ECCurveParams ecCurve_BrainpoolP384r1 = { - "brainpoolP384r1", ECField_GFp, 384, - "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53", - "7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503AD4EB04A8C7DD22CE2826", - "04A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DBC9943AB78696FA504C11", - "1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D646AAEF87B2E247D4AF1E", - "8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E4646217791811142820341263C5315", - "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565", 1 -}; - -static const ECCurveParams ecCurve_BrainpoolP512r1 = { - "brainpoolP512r1", ECField_GFp, 512, - "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3", - "7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA", - "3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723", - "81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822", - "7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892", - "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069", 1 -}; - -/* mapping between ECCurveName enum and pointers to ECCurveParams */ -static const ECCurveParams *ecCurve_map[] = { - NULL, /* ECCurve_noName */ - &ecCurve_NIST_P192, /* ECCurve_NIST_P192 */ - &ecCurve_NIST_P224, /* ECCurve_NIST_P224 */ - &ecCurve_NIST_P256, /* ECCurve_NIST_P256 */ - &ecCurve_NIST_P384, /* ECCurve_NIST_P384 */ - &ecCurve_NIST_P521, /* ECCurve_NIST_P521 */ - &ecCurve_NIST_K163, /* ECCurve_NIST_K163 */ - &ecCurve_NIST_B163, /* ECCurve_NIST_B163 */ - &ecCurve_NIST_K233, /* ECCurve_NIST_K233 */ - &ecCurve_NIST_B233, /* ECCurve_NIST_B233 */ - &ecCurve_NIST_K283, /* ECCurve_NIST_K283 */ - &ecCurve_NIST_B283, /* ECCurve_NIST_B283 */ - &ecCurve_NIST_K409, /* ECCurve_NIST_K409 */ - &ecCurve_NIST_B409, /* ECCurve_NIST_B409 */ - &ecCurve_NIST_K571, /* ECCurve_NIST_K571 */ - &ecCurve_NIST_B571, /* ECCurve_NIST_B571 */ - &ecCurve_X9_62_PRIME_192V2, /* ECCurve_X9_62_PRIME_192V2 */ - &ecCurve_X9_62_PRIME_192V3, /* ECCurve_X9_62_PRIME_192V3 */ - &ecCurve_X9_62_PRIME_239V1, /* ECCurve_X9_62_PRIME_239V1 */ - &ecCurve_X9_62_PRIME_239V2, /* ECCurve_X9_62_PRIME_239V2 */ - &ecCurve_X9_62_PRIME_239V3, /* ECCurve_X9_62_PRIME_239V3 */ - &ecCurve_X9_62_CHAR2_PNB163V1, /* ECCurve_X9_62_CHAR2_PNB163V1 */ - &ecCurve_X9_62_CHAR2_PNB163V2, /* ECCurve_X9_62_CHAR2_PNB163V2 */ - &ecCurve_X9_62_CHAR2_PNB163V3, /* ECCurve_X9_62_CHAR2_PNB163V3 */ - &ecCurve_X9_62_CHAR2_PNB176V1, /* ECCurve_X9_62_CHAR2_PNB176V1 */ - &ecCurve_X9_62_CHAR2_TNB191V1, /* ECCurve_X9_62_CHAR2_TNB191V1 */ - &ecCurve_X9_62_CHAR2_TNB191V2, /* ECCurve_X9_62_CHAR2_TNB191V2 */ - &ecCurve_X9_62_CHAR2_TNB191V3, /* ECCurve_X9_62_CHAR2_TNB191V3 */ - &ecCurve_X9_62_CHAR2_PNB208W1, /* ECCurve_X9_62_CHAR2_PNB208W1 */ - &ecCurve_X9_62_CHAR2_TNB239V1, /* ECCurve_X9_62_CHAR2_TNB239V1 */ - &ecCurve_X9_62_CHAR2_TNB239V2, /* ECCurve_X9_62_CHAR2_TNB239V2 */ - &ecCurve_X9_62_CHAR2_TNB239V3, /* ECCurve_X9_62_CHAR2_TNB239V3 */ - &ecCurve_X9_62_CHAR2_PNB272W1, /* ECCurve_X9_62_CHAR2_PNB272W1 */ - &ecCurve_X9_62_CHAR2_PNB304W1, /* ECCurve_X9_62_CHAR2_PNB304W1 */ - &ecCurve_X9_62_CHAR2_TNB359V1, /* ECCurve_X9_62_CHAR2_TNB359V1 */ - &ecCurve_X9_62_CHAR2_PNB368W1, /* ECCurve_X9_62_CHAR2_PNB368W1 */ - &ecCurve_X9_62_CHAR2_TNB431R1, /* ECCurve_X9_62_CHAR2_TNB431R1 */ - &ecCurve_SECG_PRIME_112R1, /* ECCurve_SECG_PRIME_112R1 */ - &ecCurve_SECG_PRIME_112R2, /* ECCurve_SECG_PRIME_112R2 */ - &ecCurve_SECG_PRIME_128R1, /* ECCurve_SECG_PRIME_128R1 */ - &ecCurve_SECG_PRIME_128R2, /* ECCurve_SECG_PRIME_128R2 */ - &ecCurve_SECG_PRIME_160K1, /* ECCurve_SECG_PRIME_160K1 */ - &ecCurve_SECG_PRIME_160R1, /* ECCurve_SECG_PRIME_160R1 */ - &ecCurve_SECG_PRIME_160R2, /* ECCurve_SECG_PRIME_160R2 */ - &ecCurve_SECG_PRIME_192K1, /* ECCurve_SECG_PRIME_192K1 */ - &ecCurve_SECG_PRIME_224K1, /* ECCurve_SECG_PRIME_224K1 */ - &ecCurve_SECG_PRIME_256K1, /* ECCurve_SECG_PRIME_256K1 */ - &ecCurve_SECG_CHAR2_113R1, /* ECCurve_SECG_CHAR2_113R1 */ - &ecCurve_SECG_CHAR2_113R2, /* ECCurve_SECG_CHAR2_113R2 */ - &ecCurve_SECG_CHAR2_131R1, /* ECCurve_SECG_CHAR2_131R1 */ - &ecCurve_SECG_CHAR2_131R2, /* ECCurve_SECG_CHAR2_131R2 */ - &ecCurve_SECG_CHAR2_163R1, /* ECCurve_SECG_CHAR2_163R1 */ - &ecCurve_SECG_CHAR2_193R1, /* ECCurve_SECG_CHAR2_193R1 */ - &ecCurve_SECG_CHAR2_193R2, /* ECCurve_SECG_CHAR2_193R2 */ - &ecCurve_SECG_CHAR2_239K1, /* ECCurve_SECG_CHAR2_239K1 */ - &ecCurve_WTLS_1, /* ECCurve_WTLS_1 */ - &ecCurve_WTLS_8, /* ECCurve_WTLS_8 */ - &ecCurve_WTLS_9, /* ECCurve_WTLS_9 */ - &ecCurve_BrainpoolP256r1, /* ECCurve_BrainpoolP256r1 */ - &ecCurve_BrainpoolP320r1, /* ECCurve_BrainpoolP320r1 */ - &ecCurve_BrainpoolP384r1, /* ECCurve_brainpoolP384r1 */ - &ecCurve_BrainpoolP512r1, /* ECCurve_brainpoolP512r1 */ - NULL /* ECCurve_pastLastCurve */ -}; - -#endif /* _ECL_CURVE_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-exp.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-exp.h deleted file mode 100644 index 8b442c603e01f..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-exp.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#ifndef _ECL_EXP_H -#define _ECL_EXP_H - -/* Curve field type */ -typedef enum { - ECField_GFp, - ECField_GF2m -} ECField; - -/* Hexadecimal encoding of curve parameters */ -struct ECCurveParamsStr { - char *text; - ECField field; - unsigned int size; - char *irr; - char *curvea; - char *curveb; - char *genx; - char *geny; - char *order; - int cofactor; -}; -typedef struct ECCurveParamsStr ECCurveParams; - -/* Named curve parameters */ -typedef enum { - - ECCurve_noName = 0, - - /* NIST prime curves */ - ECCurve_NIST_P192, - ECCurve_NIST_P224, - ECCurve_NIST_P256, - ECCurve_NIST_P384, - ECCurve_NIST_P521, - - /* NIST binary curves */ - ECCurve_NIST_K163, - ECCurve_NIST_B163, - ECCurve_NIST_K233, - ECCurve_NIST_B233, - ECCurve_NIST_K283, - ECCurve_NIST_B283, - ECCurve_NIST_K409, - ECCurve_NIST_B409, - ECCurve_NIST_K571, - ECCurve_NIST_B571, - - /* ANSI X9.62 prime curves */ - /* ECCurve_X9_62_PRIME_192V1 == ECCurve_NIST_P192 */ - ECCurve_X9_62_PRIME_192V2, - ECCurve_X9_62_PRIME_192V3, - ECCurve_X9_62_PRIME_239V1, - ECCurve_X9_62_PRIME_239V2, - ECCurve_X9_62_PRIME_239V3, - /* ECCurve_X9_62_PRIME_256V1 == ECCurve_NIST_P256 */ - - /* ANSI X9.62 binary curves */ - ECCurve_X9_62_CHAR2_PNB163V1, - ECCurve_X9_62_CHAR2_PNB163V2, - ECCurve_X9_62_CHAR2_PNB163V3, - ECCurve_X9_62_CHAR2_PNB176V1, - ECCurve_X9_62_CHAR2_TNB191V1, - ECCurve_X9_62_CHAR2_TNB191V2, - ECCurve_X9_62_CHAR2_TNB191V3, - ECCurve_X9_62_CHAR2_PNB208W1, - ECCurve_X9_62_CHAR2_TNB239V1, - ECCurve_X9_62_CHAR2_TNB239V2, - ECCurve_X9_62_CHAR2_TNB239V3, - ECCurve_X9_62_CHAR2_PNB272W1, - ECCurve_X9_62_CHAR2_PNB304W1, - ECCurve_X9_62_CHAR2_TNB359V1, - ECCurve_X9_62_CHAR2_PNB368W1, - ECCurve_X9_62_CHAR2_TNB431R1, - - /* SEC2 prime curves */ - ECCurve_SECG_PRIME_112R1, - ECCurve_SECG_PRIME_112R2, - ECCurve_SECG_PRIME_128R1, - ECCurve_SECG_PRIME_128R2, - ECCurve_SECG_PRIME_160K1, - ECCurve_SECG_PRIME_160R1, - ECCurve_SECG_PRIME_160R2, - ECCurve_SECG_PRIME_192K1, - /* ECCurve_SECG_PRIME_192R1 == ECCurve_NIST_P192 */ - ECCurve_SECG_PRIME_224K1, - /* ECCurve_SECG_PRIME_224R1 == ECCurve_NIST_P224 */ - ECCurve_SECG_PRIME_256K1, - /* ECCurve_SECG_PRIME_256R1 == ECCurve_NIST_P256 */ - /* ECCurve_SECG_PRIME_384R1 == ECCurve_NIST_P384 */ - /* ECCurve_SECG_PRIME_521R1 == ECCurve_NIST_P521 */ - - /* SEC2 binary curves */ - ECCurve_SECG_CHAR2_113R1, - ECCurve_SECG_CHAR2_113R2, - ECCurve_SECG_CHAR2_131R1, - ECCurve_SECG_CHAR2_131R2, - /* ECCurve_SECG_CHAR2_163K1 == ECCurve_NIST_K163 */ - ECCurve_SECG_CHAR2_163R1, - /* ECCurve_SECG_CHAR2_163R2 == ECCurve_NIST_B163 */ - ECCurve_SECG_CHAR2_193R1, - ECCurve_SECG_CHAR2_193R2, - /* ECCurve_SECG_CHAR2_233K1 == ECCurve_NIST_K233 */ - /* ECCurve_SECG_CHAR2_233R1 == ECCurve_NIST_B233 */ - ECCurve_SECG_CHAR2_239K1, - /* ECCurve_SECG_CHAR2_283K1 == ECCurve_NIST_K283 */ - /* ECCurve_SECG_CHAR2_283R1 == ECCurve_NIST_B283 */ - /* ECCurve_SECG_CHAR2_409K1 == ECCurve_NIST_K409 */ - /* ECCurve_SECG_CHAR2_409R1 == ECCurve_NIST_B409 */ - /* ECCurve_SECG_CHAR2_571K1 == ECCurve_NIST_K571 */ - /* ECCurve_SECG_CHAR2_571R1 == ECCurve_NIST_B571 */ - - /* WTLS curves */ - ECCurve_WTLS_1, - /* there is no WTLS 2 curve */ - /* ECCurve_WTLS_3 == ECCurve_NIST_K163 */ - /* ECCurve_WTLS_4 == ECCurve_SECG_CHAR2_113R1 */ - /* ECCurve_WTLS_5 == ECCurve_X9_62_CHAR2_PNB163V1 */ - /* ECCurve_WTLS_6 == ECCurve_SECG_PRIME_112R1 */ - /* ECCurve_WTLS_7 == ECCurve_SECG_PRIME_160R1 */ - ECCurve_WTLS_8, - ECCurve_WTLS_9, - /* ECCurve_WTLS_10 == ECCurve_NIST_K233 */ - /* ECCurve_WTLS_11 == ECCurve_NIST_B233 */ - /* ECCurve_WTLS_12 == ECCurve_NIST_P224 */ - - /* ECC Brainpool prime curves in RFC 5639*/ - ECCurve_BrainpoolP256r1, - ECCurve_BrainpoolP320r1, - ECCurve_BrainpoolP384r1, - ECCurve_BrainpoolP512r1, - - ECCurve_pastLastCurve -} ECCurveName; - -/* Aliased named curves */ - -#define ECCurve_X9_62_PRIME_192V1 ECCurve_NIST_P192 -#define ECCurve_X9_62_PRIME_256V1 ECCurve_NIST_P256 -#define ECCurve_SECG_PRIME_192R1 ECCurve_NIST_P192 -#define ECCurve_SECG_PRIME_224R1 ECCurve_NIST_P224 -#define ECCurve_SECG_PRIME_256R1 ECCurve_NIST_P256 -#define ECCurve_SECG_PRIME_384R1 ECCurve_NIST_P384 -#define ECCurve_SECG_PRIME_521R1 ECCurve_NIST_P521 -#define ECCurve_SECG_CHAR2_163K1 ECCurve_NIST_K163 -#define ECCurve_SECG_CHAR2_163R2 ECCurve_NIST_B163 -#define ECCurve_SECG_CHAR2_233K1 ECCurve_NIST_K233 -#define ECCurve_SECG_CHAR2_233R1 ECCurve_NIST_B233 -#define ECCurve_SECG_CHAR2_283K1 ECCurve_NIST_K283 -#define ECCurve_SECG_CHAR2_283R1 ECCurve_NIST_B283 -#define ECCurve_SECG_CHAR2_409K1 ECCurve_NIST_K409 -#define ECCurve_SECG_CHAR2_409R1 ECCurve_NIST_B409 -#define ECCurve_SECG_CHAR2_571K1 ECCurve_NIST_K571 -#define ECCurve_SECG_CHAR2_571R1 ECCurve_NIST_B571 -#define ECCurve_WTLS_3 ECCurve_NIST_K163 -#define ECCurve_WTLS_4 ECCurve_SECG_CHAR2_113R1 -#define ECCurve_WTLS_5 ECCurve_X9_62_CHAR2_PNB163V1 -#define ECCurve_WTLS_6 ECCurve_SECG_PRIME_112R1 -#define ECCurve_WTLS_7 ECCurve_SECG_PRIME_160R1 -#define ECCurve_WTLS_10 ECCurve_NIST_K233 -#define ECCurve_WTLS_11 ECCurve_NIST_B233 -#define ECCurve_WTLS_12 ECCurve_NIST_P224 - -#endif /* _ECL_EXP_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-priv.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-priv.h deleted file mode 100644 index bdfe61547b275..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl-priv.h +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stephen Fung and - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#ifndef _ECL_PRIV_H -#define _ECL_PRIV_H - -#include "ecl.h" -#include "mpi.h" -#include "mplogic.h" - -/* MAX_FIELD_SIZE_DIGITS is the maximum size of field element supported */ -/* the following needs to go away... */ -#if defined(MP_USE_LONG_LONG_DIGIT) || defined(MP_USE_LONG_DIGIT) -#define ECL_SIXTY_FOUR_BIT -#else -#define ECL_THIRTY_TWO_BIT -#endif - -#define ECL_CURVE_DIGITS(curve_size_in_bits) \ - (((curve_size_in_bits)+(sizeof(mp_digit)*8-1))/(sizeof(mp_digit)*8)) -#define ECL_BITS (sizeof(mp_digit)*8) -#define ECL_MAX_FIELD_SIZE_DIGITS (80/sizeof(mp_digit)) - -/* Gets the i'th bit in the binary representation of a. If i >= length(a), - * then return 0. (The above behaviour differs from mpl_get_bit, which - * causes an error if i >= length(a).) */ -#define MP_GET_BIT(a, i) \ - ((i) >= mpl_significant_bits((a))) ? 0 : mpl_get_bit((a), (i)) - -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) -#define MP_ADD_CARRY(a1, a2, s, cin, cout) \ - { mp_word w; \ - w = ((mp_word)(cin)) + (a1) + (a2); \ - s = ACCUM(w); \ - cout = CARRYOUT(w); } - -/* Handle case when carry-in value is zero */ -#define MP_ADD_CARRY_ZERO(a1, a2, s, cout) \ - MP_ADD_CARRY(a1, a2, s, 0, cout); - -#define MP_SUB_BORROW(a1, a2, s, bin, bout) \ - { mp_word w; \ - w = ((mp_word)(a1)) - (a2) - (bin); \ - s = ACCUM(w); \ - bout = (w >> MP_DIGIT_BIT) & 1; } - -#else -/* NOTE, - * cin and cout could be the same variable. - * bin and bout could be the same variable. - * a1 or a2 and s could be the same variable. - * don't trash those outputs until their respective inputs have - * been read. */ -#define MP_ADD_CARRY(a1, a2, s, cin, cout) \ - { mp_digit tmp,sum; \ - tmp = (a1); \ - sum = tmp + (a2); \ - tmp = (sum < tmp); /* detect overflow */ \ - s = sum += (cin); \ - cout = tmp + (sum < (cin)); } - -/* Handle case when carry-in value is zero */ -#define MP_ADD_CARRY_ZERO(a1, a2, s, cout) \ - { mp_digit tmp,sum; \ - tmp = (a1); \ - sum = tmp + (a2); \ - tmp = (sum < tmp); /* detect overflow */ \ - s = sum; \ - cout = tmp; } - -#define MP_SUB_BORROW(a1, a2, s, bin, bout) \ - { mp_digit tmp; \ - tmp = (a1); \ - s = tmp - (a2); \ - tmp = (s > tmp); /* detect borrow */ \ - if ((bin) && !s--) tmp++; \ - bout = tmp; } -#endif - - -struct GFMethodStr; -typedef struct GFMethodStr GFMethod; -struct GFMethodStr { - /* Indicates whether the structure was constructed from dynamic memory - * or statically created. */ - int constructed; - /* Irreducible that defines the field. For prime fields, this is the - * prime p. For binary polynomial fields, this is the bitstring - * representation of the irreducible polynomial. */ - mp_int irr; - /* For prime fields, the value irr_arr[0] is the number of bits in the - * field. For binary polynomial fields, the irreducible polynomial - * f(t) is represented as an array of unsigned int[], where f(t) is - * of the form: f(t) = t^p[0] + t^p[1] + ... + t^p[4] where m = p[0] - * > p[1] > ... > p[4] = 0. */ - unsigned int irr_arr[5]; - /* Field arithmetic methods. All methods (except field_enc and - * field_dec) are assumed to take field-encoded parameters and return - * field-encoded values. All methods (except field_enc and field_dec) - * are required to be implemented. */ - mp_err (*field_add) (const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - mp_err (*field_neg) (const mp_int *a, mp_int *r, const GFMethod *meth); - mp_err (*field_sub) (const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - mp_err (*field_mod) (const mp_int *a, mp_int *r, const GFMethod *meth); - mp_err (*field_mul) (const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - mp_err (*field_sqr) (const mp_int *a, mp_int *r, const GFMethod *meth); - mp_err (*field_div) (const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - mp_err (*field_enc) (const mp_int *a, mp_int *r, const GFMethod *meth); - mp_err (*field_dec) (const mp_int *a, mp_int *r, const GFMethod *meth); - /* Extra storage for implementation-specific data. Any memory - * allocated to these extra fields will be cleared by extra_free. */ - void *extra1; - void *extra2; - void (*extra_free) (GFMethod *meth); -}; - -/* Construct generic GFMethods. */ -GFMethod *GFMethod_consGFp(const mp_int *irr); -GFMethod *GFMethod_consGFp_mont(const mp_int *irr); -GFMethod *GFMethod_consGF2m(const mp_int *irr, - const unsigned int irr_arr[5]); -/* Free the memory allocated (if any) to a GFMethod object. */ -void GFMethod_free(GFMethod *meth); - -struct ECGroupStr { - /* Indicates whether the structure was constructed from dynamic memory - * or statically created. */ - int constructed; - /* Field definition and arithmetic. */ - GFMethod *meth; - /* Textual representation of curve name, if any. */ - char *text; -#ifdef _KERNEL - int text_len; -#endif - /* Curve parameters, field-encoded. */ - mp_int curvea, curveb; - /* x and y coordinates of the base point, field-encoded. */ - mp_int genx, geny; - /* Order and cofactor of the base point. */ - mp_int order; - int cofactor; - /* Point arithmetic methods. All methods are assumed to take - * field-encoded parameters and return field-encoded values. All - * methods (except base_point_mul and points_mul) are required to be - * implemented. */ - mp_err (*point_add) (const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - mp_err (*point_sub) (const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - mp_err (*point_dbl) (const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group); - mp_err (*point_mul) (const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing); - mp_err (*base_point_mul) (const mp_int *n, mp_int *rx, mp_int *ry, - const ECGroup *group); - mp_err (*points_mul) (const mp_int *k1, const mp_int *k2, - const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group, - int timing); - mp_err (*validate_point) (const mp_int *px, const mp_int *py, const ECGroup *group); - /* Extra storage for implementation-specific data. Any memory - * allocated to these extra fields will be cleared by extra_free. */ - void *extra1; - void *extra2; - void (*extra_free) (ECGroup *group); -}; - -/* Wrapper functions for generic prime field arithmetic. */ -mp_err ec_GFp_add(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GFp_sub(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - -/* fixed length in-line adds. Count is in words */ -mp_err ec_GFp_add_3(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_add_4(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_add_5(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_add_6(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sub_3(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sub_4(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sub_5(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sub_6(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - -mp_err ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GFp_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GFp_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -/* Wrapper functions for generic binary polynomial field arithmetic. */ -mp_err ec_GF2m_add(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GF2m_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GF2m_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); - -/* Montgomery prime field arithmetic. */ -mp_err ec_GFp_mul_mont(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_sqr_mont(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GFp_div_mont(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth); -mp_err ec_GFp_enc_mont(const mp_int *a, mp_int *r, const GFMethod *meth); -mp_err ec_GFp_dec_mont(const mp_int *a, mp_int *r, const GFMethod *meth); -void ec_GFp_extra_free_mont(GFMethod *meth); - -/* point multiplication */ -mp_err ec_pts_mul_basic(const mp_int *k1, const mp_int *k2, - const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group, - int timing); -mp_err ec_pts_mul_simul_w2(const mp_int *k1, const mp_int *k2, - const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group, - int timing); - -/* Computes the windowed non-adjacent-form (NAF) of a scalar. Out should - * be an array of signed char's to output to, bitsize should be the number - * of bits of out, in is the original scalar, and w is the window size. - * NAF is discussed in the paper: D. Hankerson, J. Hernandez and A. - * Menezes, "Software implementation of elliptic curve cryptography over - * binary fields", Proc. CHES 2000. */ -mp_err ec_compute_wNAF(signed char *out, int bitsize, const mp_int *in, - int w); - -/* Optimized field arithmetic */ -mp_err ec_group_set_gfp192(ECGroup *group, ECCurveName); -mp_err ec_group_set_gfp224(ECGroup *group, ECCurveName); -mp_err ec_group_set_gfp256(ECGroup *group, ECCurveName); -mp_err ec_group_set_gfp384(ECGroup *group, ECCurveName); -mp_err ec_group_set_gfp521(ECGroup *group, ECCurveName); -mp_err ec_group_set_gf2m163(ECGroup *group, ECCurveName name); -mp_err ec_group_set_gf2m193(ECGroup *group, ECCurveName name); -mp_err ec_group_set_gf2m233(ECGroup *group, ECCurveName name); - -/* Optimized floating-point arithmetic */ -#ifdef ECL_USE_FP -mp_err ec_group_set_secp160r1_fp(ECGroup *group); -mp_err ec_group_set_nistp192_fp(ECGroup *group); -mp_err ec_group_set_nistp224_fp(ECGroup *group); -#endif - -#endif /* _ECL_PRIV_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.c deleted file mode 100644 index 49f407a28b417..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.c +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "mpi.h" -#include "mplogic.h" -#include "ecl.h" -#include "ecl-priv.h" -#include "ec2.h" -#include "ecp.h" -#ifndef _KERNEL -#include -#include -#endif - -/* Allocate memory for a new ECGroup object. */ -ECGroup * -ECGroup_new(int kmflag) -{ - mp_err res = MP_OKAY; - ECGroup *group; -#ifdef _KERNEL - group = (ECGroup *) kmem_alloc(sizeof(ECGroup), kmflag); -#else - group = (ECGroup *) malloc(sizeof(ECGroup)); -#endif - if (group == NULL) - return NULL; - group->constructed = MP_YES; - group->meth = NULL; - group->text = NULL; - MP_DIGITS(&group->curvea) = 0; - MP_DIGITS(&group->curveb) = 0; - MP_DIGITS(&group->genx) = 0; - MP_DIGITS(&group->geny) = 0; - MP_DIGITS(&group->order) = 0; - group->base_point_mul = NULL; - group->points_mul = NULL; - group->validate_point = NULL; - group->extra1 = NULL; - group->extra2 = NULL; - group->extra_free = NULL; - MP_CHECKOK(mp_init(&group->curvea, kmflag)); - MP_CHECKOK(mp_init(&group->curveb, kmflag)); - MP_CHECKOK(mp_init(&group->genx, kmflag)); - MP_CHECKOK(mp_init(&group->geny, kmflag)); - MP_CHECKOK(mp_init(&group->order, kmflag)); - - CLEANUP: - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} - -/* Construct a generic ECGroup for elliptic curves over prime fields. */ -ECGroup * -ECGroup_consGFp(const mp_int *irr, const mp_int *curvea, - const mp_int *curveb, const mp_int *genx, - const mp_int *geny, const mp_int *order, int cofactor) -{ - mp_err res = MP_OKAY; - ECGroup *group = NULL; - - group = ECGroup_new(FLAG(irr)); - if (group == NULL) - return NULL; - - group->meth = GFMethod_consGFp(irr); - if (group->meth == NULL) { - res = MP_MEM; - goto CLEANUP; - } - MP_CHECKOK(mp_copy(curvea, &group->curvea)); - MP_CHECKOK(mp_copy(curveb, &group->curveb)); - MP_CHECKOK(mp_copy(genx, &group->genx)); - MP_CHECKOK(mp_copy(geny, &group->geny)); - MP_CHECKOK(mp_copy(order, &group->order)); - group->cofactor = cofactor; - group->point_add = &ec_GFp_pt_add_aff; - group->point_sub = &ec_GFp_pt_sub_aff; - group->point_dbl = &ec_GFp_pt_dbl_aff; - group->point_mul = &ec_GFp_pt_mul_jm_wNAF; - group->base_point_mul = NULL; - group->points_mul = &ec_GFp_pts_mul_jac; - group->validate_point = &ec_GFp_validate_point; - - CLEANUP: - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} - -/* Construct a generic ECGroup for elliptic curves over prime fields with - * field arithmetic implemented in Montgomery coordinates. */ -ECGroup * -ECGroup_consGFp_mont(const mp_int *irr, const mp_int *curvea, - const mp_int *curveb, const mp_int *genx, - const mp_int *geny, const mp_int *order, int cofactor) -{ - mp_err res = MP_OKAY; - ECGroup *group = NULL; - - group = ECGroup_new(FLAG(irr)); - if (group == NULL) - return NULL; - - group->meth = GFMethod_consGFp_mont(irr); - if (group->meth == NULL) { - res = MP_MEM; - goto CLEANUP; - } - MP_CHECKOK(group->meth-> - field_enc(curvea, &group->curvea, group->meth)); - MP_CHECKOK(group->meth-> - field_enc(curveb, &group->curveb, group->meth)); - MP_CHECKOK(group->meth->field_enc(genx, &group->genx, group->meth)); - MP_CHECKOK(group->meth->field_enc(geny, &group->geny, group->meth)); - MP_CHECKOK(mp_copy(order, &group->order)); - group->cofactor = cofactor; - group->point_add = &ec_GFp_pt_add_aff; - group->point_sub = &ec_GFp_pt_sub_aff; - group->point_dbl = &ec_GFp_pt_dbl_aff; - group->point_mul = &ec_GFp_pt_mul_jm_wNAF; - group->base_point_mul = NULL; - group->points_mul = &ec_GFp_pts_mul_jac; - group->validate_point = &ec_GFp_validate_point; - - CLEANUP: - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} - -#ifdef NSS_ECC_MORE_THAN_SUITE_B -/* Construct a generic ECGroup for elliptic curves over binary polynomial - * fields. */ -ECGroup * -ECGroup_consGF2m(const mp_int *irr, const unsigned int irr_arr[5], - const mp_int *curvea, const mp_int *curveb, - const mp_int *genx, const mp_int *geny, - const mp_int *order, int cofactor) -{ - mp_err res = MP_OKAY; - ECGroup *group = NULL; - - group = ECGroup_new(FLAG(irr)); - if (group == NULL) - return NULL; - - group->meth = GFMethod_consGF2m(irr, irr_arr); - if (group->meth == NULL) { - res = MP_MEM; - goto CLEANUP; - } - MP_CHECKOK(mp_copy(curvea, &group->curvea)); - MP_CHECKOK(mp_copy(curveb, &group->curveb)); - MP_CHECKOK(mp_copy(genx, &group->genx)); - MP_CHECKOK(mp_copy(geny, &group->geny)); - MP_CHECKOK(mp_copy(order, &group->order)); - group->cofactor = cofactor; - group->point_add = &ec_GF2m_pt_add_aff; - group->point_sub = &ec_GF2m_pt_sub_aff; - group->point_dbl = &ec_GF2m_pt_dbl_aff; - group->point_mul = &ec_GF2m_pt_mul_mont; - group->base_point_mul = NULL; - group->points_mul = &ec_pts_mul_basic; - group->validate_point = &ec_GF2m_validate_point; - - CLEANUP: - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} -#endif - -/* Construct ECGroup from hex parameters and name, if any. Called by - * ECGroup_fromHex and ECGroup_fromName. */ -ECGroup * -ecgroup_fromNameAndHex(const ECCurveName name, - const ECCurveParams * params, int kmflag) -{ - mp_int irr, curvea, curveb, genx, geny, order; - int bits; - ECGroup *group = NULL; - mp_err res = MP_OKAY; - - /* initialize values */ - MP_DIGITS(&irr) = 0; - MP_DIGITS(&curvea) = 0; - MP_DIGITS(&curveb) = 0; - MP_DIGITS(&genx) = 0; - MP_DIGITS(&geny) = 0; - MP_DIGITS(&order) = 0; - MP_CHECKOK(mp_init(&irr, kmflag)); - MP_CHECKOK(mp_init(&curvea, kmflag)); - MP_CHECKOK(mp_init(&curveb, kmflag)); - MP_CHECKOK(mp_init(&genx, kmflag)); - MP_CHECKOK(mp_init(&geny, kmflag)); - MP_CHECKOK(mp_init(&order, kmflag)); - MP_CHECKOK(mp_read_radix(&irr, params->irr, 16)); - MP_CHECKOK(mp_read_radix(&curvea, params->curvea, 16)); - MP_CHECKOK(mp_read_radix(&curveb, params->curveb, 16)); - MP_CHECKOK(mp_read_radix(&genx, params->genx, 16)); - MP_CHECKOK(mp_read_radix(&geny, params->geny, 16)); - MP_CHECKOK(mp_read_radix(&order, params->order, 16)); - - /* determine number of bits */ - bits = mpl_significant_bits(&irr) - 1; - if (bits < MP_OKAY) { - res = bits; - goto CLEANUP; - } - - /* determine which optimizations (if any) to use */ - if (params->field == ECField_GFp) { -#ifdef NSS_ECC_MORE_THAN_SUITE_B - switch (name) { -#ifdef ECL_USE_FP - case ECCurve_SECG_PRIME_160R1: - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_secp160r1_fp(group)); - break; -#endif - case ECCurve_SECG_PRIME_192R1: -#ifdef ECL_USE_FP - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_nistp192_fp(group)); -#else - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_gfp192(group, name)); -#endif - break; - case ECCurve_SECG_PRIME_224R1: -#ifdef ECL_USE_FP - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_nistp224_fp(group)); -#else - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_gfp224(group, name)); -#endif - break; - case ECCurve_SECG_PRIME_256R1: - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_gfp256(group, name)); - break; - case ECCurve_SECG_PRIME_521R1: - group = - ECGroup_consGFp(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - MP_CHECKOK(ec_group_set_gfp521(group, name)); - break; - default: - /* use generic arithmetic */ -#endif - group = - ECGroup_consGFp_mont(&irr, &curvea, &curveb, &genx, &geny, - &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } -#ifdef NSS_ECC_MORE_THAN_SUITE_B - } - } else if (params->field == ECField_GF2m) { - group = ECGroup_consGF2m(&irr, NULL, &curvea, &curveb, &genx, &geny, &order, params->cofactor); - if (group == NULL) { res = MP_UNDEF; goto CLEANUP; } - if ((name == ECCurve_NIST_K163) || - (name == ECCurve_NIST_B163) || - (name == ECCurve_SECG_CHAR2_163R1)) { - MP_CHECKOK(ec_group_set_gf2m163(group, name)); - } else if ((name == ECCurve_SECG_CHAR2_193R1) || - (name == ECCurve_SECG_CHAR2_193R2)) { - MP_CHECKOK(ec_group_set_gf2m193(group, name)); - } else if ((name == ECCurve_NIST_K233) || - (name == ECCurve_NIST_B233)) { - MP_CHECKOK(ec_group_set_gf2m233(group, name)); - } -#endif - } else { - res = MP_UNDEF; - goto CLEANUP; - } - - /* set name, if any */ - if ((group != NULL) && (params->text != NULL)) { -#ifdef _KERNEL - int n = strlen(params->text) + 1; - - group->text = kmem_alloc(n, kmflag); - if (group->text == NULL) { - res = MP_MEM; - goto CLEANUP; - } - bcopy(params->text, group->text, n); - group->text_len = n; -#else - group->text = strdup(params->text); - if (group->text == NULL) { - res = MP_MEM; - } -#endif - } - - CLEANUP: - mp_clear(&irr); - mp_clear(&curvea); - mp_clear(&curveb); - mp_clear(&genx); - mp_clear(&geny); - mp_clear(&order); - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} - -/* Construct ECGroup from hexadecimal representations of parameters. */ -ECGroup * -ECGroup_fromHex(const ECCurveParams * params, int kmflag) -{ - return ecgroup_fromNameAndHex(ECCurve_noName, params, kmflag); -} - -/* Construct ECGroup from named parameters. */ -ECGroup * -ECGroup_fromName(const ECCurveName name, int kmflag) -{ - ECGroup *group = NULL; - ECCurveParams *params = NULL; - mp_err res = MP_OKAY; - - params = EC_GetNamedCurveParams(name, kmflag); - if (params == NULL) { - res = MP_UNDEF; - goto CLEANUP; - } - - /* construct actual group */ - group = ecgroup_fromNameAndHex(name, params, kmflag); - if (group == NULL) { - res = MP_UNDEF; - goto CLEANUP; - } - - CLEANUP: - EC_FreeCurveParams(params); - if (res != MP_OKAY) { - ECGroup_free(group); - return NULL; - } - return group; -} - -/* Validates an EC public key as described in Section 5.2.2 of X9.62. */ -mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const - mp_int *py) -{ - /* 1: Verify that publicValue is not the point at infinity */ - /* 2: Verify that the coordinates of publicValue are elements - * of the field. - */ - /* 3: Verify that publicValue is on the curve. */ - /* 4: Verify that the order of the curve times the publicValue - * is the point at infinity. - */ - return group->validate_point(px, py, group); -} - -/* Free the memory allocated (if any) to an ECGroup object. */ -void -ECGroup_free(ECGroup *group) -{ - if (group == NULL) - return; - GFMethod_free(group->meth); - if (group->constructed == MP_NO) - return; - mp_clear(&group->curvea); - mp_clear(&group->curveb); - mp_clear(&group->genx); - mp_clear(&group->geny); - mp_clear(&group->order); - if (group->text != NULL) -#ifdef _KERNEL - kmem_free(group->text, group->text_len); -#else - free(group->text); -#endif - if (group->extra_free != NULL) - group->extra_free(group); -#ifdef _KERNEL - kmem_free(group, sizeof (ECGroup)); -#else - free(group); -#endif -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.h deleted file mode 100644 index deff0aa1191d0..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#ifndef _ECL_H -#define _ECL_H - -/* Although this is not an exported header file, code which uses elliptic - * curve point operations will need to include it. */ - -#include "ecl-exp.h" -#include "mpi.h" - -struct ECGroupStr; -typedef struct ECGroupStr ECGroup; - -/* Construct ECGroup from hexadecimal representations of parameters. */ -ECGroup *ECGroup_fromHex(const ECCurveParams * params, int kmflag); - -/* Construct ECGroup from named parameters. */ -ECGroup *ECGroup_fromName(const ECCurveName name, int kmflag); - -/* Free an allocated ECGroup. */ -void ECGroup_free(ECGroup *group); - -/* Construct ECCurveParams from an ECCurveName */ -ECCurveParams *EC_GetNamedCurveParams(const ECCurveName name, int kmflag); - -/* Duplicates an ECCurveParams */ -ECCurveParams *ECCurveParams_dup(const ECCurveParams * params, int kmflag); - -/* Free an allocated ECCurveParams */ -void EC_FreeCurveParams(ECCurveParams * params); - -/* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k * P(x, - * y). If x, y = NULL, then P is assumed to be the generator (base point) - * of the group of points on the elliptic curve. Input and output values - * are assumed to be NOT field-encoded. */ -mp_err ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px, - const mp_int *py, mp_int *qx, mp_int *qy, - int timing); - -/* Elliptic curve scalar-point multiplication. Computes Q(x, y) = k1 * G + - * k2 * P(x, y), where G is the generator (base point) of the group of - * points on the elliptic curve. Input and output values are assumed to - * be NOT field-encoded. */ -mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1, - const mp_int *k2, const mp_int *px, const mp_int *py, - mp_int *qx, mp_int *qy, int timing); - -/* Validates an EC public key as described in Section 5.2.2 of X9.62. - * Returns MP_YES if the public key is valid, MP_NO if the public key - * is invalid, or an error code if the validation could not be - * performed. */ -mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const - mp_int *py); - -#endif /* _ECL_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_curve.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_curve.c deleted file mode 100644 index fe883242988ff..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_curve.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "ecl.h" -#include "ecl-curve.h" -#include "ecl-priv.h" -#ifndef _KERNEL -#include -#include -#endif - -#define CHECK(func) if ((func) == NULL) { res = 0; goto CLEANUP; } - -/* Duplicates an ECCurveParams */ -ECCurveParams * -ECCurveParams_dup(const ECCurveParams * params, int kmflag) -{ - int res = 1; - ECCurveParams *ret = NULL; - -#ifdef _KERNEL - ret = (ECCurveParams *) kmem_zalloc(sizeof(ECCurveParams), kmflag); -#else - CHECK(ret = (ECCurveParams *) calloc(1, sizeof(ECCurveParams))); -#endif - if (params->text != NULL) { -#ifdef _KERNEL - ret->text = kmem_alloc(strlen(params->text) + 1, kmflag); - bcopy(params->text, ret->text, strlen(params->text) + 1); -#else - CHECK(ret->text = strdup(params->text)); -#endif - } - ret->field = params->field; - ret->size = params->size; - if (params->irr != NULL) { -#ifdef _KERNEL - ret->irr = kmem_alloc(strlen(params->irr) + 1, kmflag); - bcopy(params->irr, ret->irr, strlen(params->irr) + 1); -#else - CHECK(ret->irr = strdup(params->irr)); -#endif - } - if (params->curvea != NULL) { -#ifdef _KERNEL - ret->curvea = kmem_alloc(strlen(params->curvea) + 1, kmflag); - bcopy(params->curvea, ret->curvea, strlen(params->curvea) + 1); -#else - CHECK(ret->curvea = strdup(params->curvea)); -#endif - } - if (params->curveb != NULL) { -#ifdef _KERNEL - ret->curveb = kmem_alloc(strlen(params->curveb) + 1, kmflag); - bcopy(params->curveb, ret->curveb, strlen(params->curveb) + 1); -#else - CHECK(ret->curveb = strdup(params->curveb)); -#endif - } - if (params->genx != NULL) { -#ifdef _KERNEL - ret->genx = kmem_alloc(strlen(params->genx) + 1, kmflag); - bcopy(params->genx, ret->genx, strlen(params->genx) + 1); -#else - CHECK(ret->genx = strdup(params->genx)); -#endif - } - if (params->geny != NULL) { -#ifdef _KERNEL - ret->geny = kmem_alloc(strlen(params->geny) + 1, kmflag); - bcopy(params->geny, ret->geny, strlen(params->geny) + 1); -#else - CHECK(ret->geny = strdup(params->geny)); -#endif - } - if (params->order != NULL) { -#ifdef _KERNEL - ret->order = kmem_alloc(strlen(params->order) + 1, kmflag); - bcopy(params->order, ret->order, strlen(params->order) + 1); -#else - CHECK(ret->order = strdup(params->order)); -#endif - } - ret->cofactor = params->cofactor; - - CLEANUP: - if (res != 1) { - EC_FreeCurveParams(ret); - return NULL; - } - return ret; -} - -#undef CHECK - -/* Construct ECCurveParams from an ECCurveName */ -ECCurveParams * -EC_GetNamedCurveParams(const ECCurveName name, int kmflag) -{ - if ((name <= ECCurve_noName) || (ECCurve_pastLastCurve <= name) || - (ecCurve_map[name] == NULL)) { - return NULL; - } else { - return ECCurveParams_dup(ecCurve_map[name], kmflag); - } -} - -/* Free the memory allocated (if any) to an ECCurveParams object. */ -void -EC_FreeCurveParams(ECCurveParams * params) -{ - if (params == NULL) - return; - if (params->text != NULL) -#ifdef _KERNEL - kmem_free(params->text, strlen(params->text) + 1); -#else - free(params->text); -#endif - if (params->irr != NULL) -#ifdef _KERNEL - kmem_free(params->irr, strlen(params->irr) + 1); -#else - free(params->irr); -#endif - if (params->curvea != NULL) -#ifdef _KERNEL - kmem_free(params->curvea, strlen(params->curvea) + 1); -#else - free(params->curvea); -#endif - if (params->curveb != NULL) -#ifdef _KERNEL - kmem_free(params->curveb, strlen(params->curveb) + 1); -#else - free(params->curveb); -#endif - if (params->genx != NULL) -#ifdef _KERNEL - kmem_free(params->genx, strlen(params->genx) + 1); -#else - free(params->genx); -#endif - if (params->geny != NULL) -#ifdef _KERNEL - kmem_free(params->geny, strlen(params->geny) + 1); -#else - free(params->geny); -#endif - if (params->order != NULL) -#ifdef _KERNEL - kmem_free(params->order, strlen(params->order) + 1); -#else - free(params->order); -#endif -#ifdef _KERNEL - kmem_free(params, sizeof(ECCurveParams)); -#else - free(params); -#endif -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_gf.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_gf.c deleted file mode 100644 index 3723925e25593..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_gf.c +++ /dev/null @@ -1,1043 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stephen Fung and - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "mpi.h" -#include "mp_gf2m.h" -#include "ecl-priv.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Allocate memory for a new GFMethod object. */ -GFMethod * -GFMethod_new(int kmflag) -{ - mp_err res = MP_OKAY; - GFMethod *meth; -#ifdef _KERNEL - meth = (GFMethod *) kmem_alloc(sizeof(GFMethod), kmflag); -#else - meth = (GFMethod *) malloc(sizeof(GFMethod)); - if (meth == NULL) - return NULL; -#endif - meth->constructed = MP_YES; - MP_DIGITS(&meth->irr) = 0; - meth->extra_free = NULL; - MP_CHECKOK(mp_init(&meth->irr, kmflag)); - - CLEANUP: - if (res != MP_OKAY) { - GFMethod_free(meth); - return NULL; - } - return meth; -} - -/* Construct a generic GFMethod for arithmetic over prime fields with - * irreducible irr. */ -GFMethod * -GFMethod_consGFp(const mp_int *irr) -{ - mp_err res = MP_OKAY; - GFMethod *meth = NULL; - - meth = GFMethod_new(FLAG(irr)); - if (meth == NULL) - return NULL; - - MP_CHECKOK(mp_copy(irr, &meth->irr)); - meth->irr_arr[0] = mpl_significant_bits(irr); - meth->irr_arr[1] = meth->irr_arr[2] = meth->irr_arr[3] = - meth->irr_arr[4] = 0; - switch(MP_USED(&meth->irr)) { - /* maybe we need 1 and 2 words here as well?*/ - case 3: - meth->field_add = &ec_GFp_add_3; - meth->field_sub = &ec_GFp_sub_3; - break; - case 4: - meth->field_add = &ec_GFp_add_4; - meth->field_sub = &ec_GFp_sub_4; - break; - case 5: - meth->field_add = &ec_GFp_add_5; - meth->field_sub = &ec_GFp_sub_5; - break; - case 6: - meth->field_add = &ec_GFp_add_6; - meth->field_sub = &ec_GFp_sub_6; - break; - default: - meth->field_add = &ec_GFp_add; - meth->field_sub = &ec_GFp_sub; - } - meth->field_neg = &ec_GFp_neg; - meth->field_mod = &ec_GFp_mod; - meth->field_mul = &ec_GFp_mul; - meth->field_sqr = &ec_GFp_sqr; - meth->field_div = &ec_GFp_div; - meth->field_enc = NULL; - meth->field_dec = NULL; - meth->extra1 = NULL; - meth->extra2 = NULL; - meth->extra_free = NULL; - - CLEANUP: - if (res != MP_OKAY) { - GFMethod_free(meth); - return NULL; - } - return meth; -} - -/* Construct a generic GFMethod for arithmetic over binary polynomial - * fields with irreducible irr that has array representation irr_arr (see - * ecl-priv.h for description of the representation). If irr_arr is NULL, - * then it is constructed from the bitstring representation. */ -GFMethod * -GFMethod_consGF2m(const mp_int *irr, const unsigned int irr_arr[5]) -{ - mp_err res = MP_OKAY; - int ret; - GFMethod *meth = NULL; - - meth = GFMethod_new(FLAG(irr)); - if (meth == NULL) - return NULL; - - MP_CHECKOK(mp_copy(irr, &meth->irr)); - if (irr_arr != NULL) { - /* Irreducible polynomials are either trinomials or pentanomials. */ - meth->irr_arr[0] = irr_arr[0]; - meth->irr_arr[1] = irr_arr[1]; - meth->irr_arr[2] = irr_arr[2]; - if (irr_arr[2] > 0) { - meth->irr_arr[3] = irr_arr[3]; - meth->irr_arr[4] = irr_arr[4]; - } else { - meth->irr_arr[3] = meth->irr_arr[4] = 0; - } - } else { - ret = mp_bpoly2arr(irr, meth->irr_arr, 5); - /* Irreducible polynomials are either trinomials or pentanomials. */ - if ((ret != 5) && (ret != 3)) { - res = MP_UNDEF; - goto CLEANUP; - } - } - meth->field_add = &ec_GF2m_add; - meth->field_neg = &ec_GF2m_neg; - meth->field_sub = &ec_GF2m_add; - meth->field_mod = &ec_GF2m_mod; - meth->field_mul = &ec_GF2m_mul; - meth->field_sqr = &ec_GF2m_sqr; - meth->field_div = &ec_GF2m_div; - meth->field_enc = NULL; - meth->field_dec = NULL; - meth->extra1 = NULL; - meth->extra2 = NULL; - meth->extra_free = NULL; - - CLEANUP: - if (res != MP_OKAY) { - GFMethod_free(meth); - return NULL; - } - return meth; -} - -/* Free the memory allocated (if any) to a GFMethod object. */ -void -GFMethod_free(GFMethod *meth) -{ - if (meth == NULL) - return; - if (meth->constructed == MP_NO) - return; - mp_clear(&meth->irr); - if (meth->extra_free != NULL) - meth->extra_free(meth); -#ifdef _KERNEL - kmem_free(meth, sizeof(GFMethod)); -#else - free(meth); -#endif -} - -/* Wrapper functions for generic prime field arithmetic. */ - -/* Add two field elements. Assumes that 0 <= a, b < meth->irr */ -mp_err -ec_GFp_add(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a + b (mod p) */ - mp_err res; - - if ((res = mp_add(a, b, r)) != MP_OKAY) { - return res; - } - if (mp_cmp(r, &meth->irr) >= 0) { - return mp_sub(r, &meth->irr, r); - } - return res; -} - -/* Negates a field element. Assumes that 0 <= a < meth->irr */ -mp_err -ec_GFp_neg(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - /* PRE: 0 <= a < p = meth->irr POST: 0 <= r < p, r = -a (mod p) */ - - if (mp_cmp_z(a) == 0) { - mp_zero(r); - return MP_OKAY; - } - return mp_sub(&meth->irr, a, r); -} - -/* Subtracts two field elements. Assumes that 0 <= a, b < meth->irr */ -mp_err -ec_GFp_sub(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - /* PRE: 0 <= a, b < p = meth->irr POST: 0 <= r < p, r = a - b (mod p) */ - res = mp_sub(a, b, r); - if (res == MP_RANGE) { - MP_CHECKOK(mp_sub(b, a, r)); - if (mp_cmp_z(r) < 0) { - MP_CHECKOK(mp_add(r, &meth->irr, r)); - } - MP_CHECKOK(ec_GFp_neg(r, r, meth)); - } - if (mp_cmp_z(r) < 0) { - MP_CHECKOK(mp_add(r, &meth->irr, r)); - } - CLEANUP: - return res; -} -/* - * Inline adds for small curve lengths. - */ -/* 3 words */ -mp_err -ec_GFp_add_3(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a0 = 0, a1 = 0, a2 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0; - mp_digit carry; - - switch(MP_USED(a)) { - case 3: - a2 = MP_DIGIT(a,2); - case 2: - a1 = MP_DIGIT(a,1); - case 1: - a0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 3: - r2 = MP_DIGIT(b,2); - case 2: - r1 = MP_DIGIT(b,1); - case 1: - r0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(a0, r0, r0, carry); - MP_ADD_CARRY(a1, r1, r1, carry, carry); - MP_ADD_CARRY(a2, r2, r2, carry, carry); -#else - __asm__ ( - "xorq %3,%3 \n\t" - "addq %4,%0 \n\t" - "adcq %5,%1 \n\t" - "adcq %6,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(carry) - : "r" (a0), "r" (a1), "r" (a2), - "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - - MP_CHECKOK(s_mp_pad(r, 3)); - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 3; - - /* Do quick 'subract' if we've gone over - * (add the 2's complement of the curve field) */ - a2 = MP_DIGIT(&meth->irr,2); - if (carry || r2 > a2 || - ((r2 == a2) && mp_cmp(r,&meth->irr) != MP_LT)) { - a1 = MP_DIGIT(&meth->irr,1); - a0 = MP_DIGIT(&meth->irr,0); -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, a0, r0, 0, carry); - MP_SUB_BORROW(r1, a1, r1, carry, carry); - MP_SUB_BORROW(r2, a2, r2, carry, carry); -#else - __asm__ ( - "subq %3,%0 \n\t" - "sbbq %4,%1 \n\t" - "sbbq %5,%2 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2) - : "r" (a0), "r" (a1), "r" (a2), - "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - } - - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 4 words */ -mp_err -ec_GFp_add_4(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0; - mp_digit carry; - - switch(MP_USED(a)) { - case 4: - a3 = MP_DIGIT(a,3); - case 3: - a2 = MP_DIGIT(a,2); - case 2: - a1 = MP_DIGIT(a,1); - case 1: - a0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 4: - r3 = MP_DIGIT(b,3); - case 3: - r2 = MP_DIGIT(b,2); - case 2: - r1 = MP_DIGIT(b,1); - case 1: - r0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(a0, r0, r0, carry); - MP_ADD_CARRY(a1, r1, r1, carry, carry); - MP_ADD_CARRY(a2, r2, r2, carry, carry); - MP_ADD_CARRY(a3, r3, r3, carry, carry); -#else - __asm__ ( - "xorq %4,%4 \n\t" - "addq %5,%0 \n\t" - "adcq %6,%1 \n\t" - "adcq %7,%2 \n\t" - "adcq %8,%3 \n\t" - "adcq $0,%4 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(carry) - : "r" (a0), "r" (a1), "r" (a2), "r" (a3), - "0" (r0), "1" (r1), "2" (r2), "3" (r3) - : "%cc" ); -#endif - - MP_CHECKOK(s_mp_pad(r, 4)); - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 4; - - /* Do quick 'subract' if we've gone over - * (add the 2's complement of the curve field) */ - a3 = MP_DIGIT(&meth->irr,3); - if (carry || r3 > a3 || - ((r3 == a3) && mp_cmp(r,&meth->irr) != MP_LT)) { - a2 = MP_DIGIT(&meth->irr,2); - a1 = MP_DIGIT(&meth->irr,1); - a0 = MP_DIGIT(&meth->irr,0); -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, a0, r0, 0, carry); - MP_SUB_BORROW(r1, a1, r1, carry, carry); - MP_SUB_BORROW(r2, a2, r2, carry, carry); - MP_SUB_BORROW(r3, a3, r3, carry, carry); -#else - __asm__ ( - "subq %4,%0 \n\t" - "sbbq %5,%1 \n\t" - "sbbq %6,%2 \n\t" - "sbbq %7,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3) - : "r" (a0), "r" (a1), "r" (a2), "r" (a3), - "0" (r0), "1" (r1), "2" (r2), "3" (r3) - : "%cc" ); -#endif - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - } - - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 5 words */ -mp_err -ec_GFp_add_5(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; - mp_digit carry; - - switch(MP_USED(a)) { - case 5: - a4 = MP_DIGIT(a,4); - case 4: - a3 = MP_DIGIT(a,3); - case 3: - a2 = MP_DIGIT(a,2); - case 2: - a1 = MP_DIGIT(a,1); - case 1: - a0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 5: - r4 = MP_DIGIT(b,4); - case 4: - r3 = MP_DIGIT(b,3); - case 3: - r2 = MP_DIGIT(b,2); - case 2: - r1 = MP_DIGIT(b,1); - case 1: - r0 = MP_DIGIT(b,0); - } - - MP_ADD_CARRY_ZERO(a0, r0, r0, carry); - MP_ADD_CARRY(a1, r1, r1, carry, carry); - MP_ADD_CARRY(a2, r2, r2, carry, carry); - MP_ADD_CARRY(a3, r3, r3, carry, carry); - MP_ADD_CARRY(a4, r4, r4, carry, carry); - - MP_CHECKOK(s_mp_pad(r, 5)); - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 5; - - /* Do quick 'subract' if we've gone over - * (add the 2's complement of the curve field) */ - a4 = MP_DIGIT(&meth->irr,4); - if (carry || r4 > a4 || - ((r4 == a4) && mp_cmp(r,&meth->irr) != MP_LT)) { - a3 = MP_DIGIT(&meth->irr,3); - a2 = MP_DIGIT(&meth->irr,2); - a1 = MP_DIGIT(&meth->irr,1); - a0 = MP_DIGIT(&meth->irr,0); - MP_SUB_BORROW(r0, a0, r0, 0, carry); - MP_SUB_BORROW(r1, a1, r1, carry, carry); - MP_SUB_BORROW(r2, a2, r2, carry, carry); - MP_SUB_BORROW(r3, a3, r3, carry, carry); - MP_SUB_BORROW(r4, a4, r4, carry, carry); - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - } - - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 6 words */ -mp_err -ec_GFp_add_6(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0; - mp_digit carry; - - switch(MP_USED(a)) { - case 6: - a5 = MP_DIGIT(a,5); - case 5: - a4 = MP_DIGIT(a,4); - case 4: - a3 = MP_DIGIT(a,3); - case 3: - a2 = MP_DIGIT(a,2); - case 2: - a1 = MP_DIGIT(a,1); - case 1: - a0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 6: - r5 = MP_DIGIT(b,5); - case 5: - r4 = MP_DIGIT(b,4); - case 4: - r3 = MP_DIGIT(b,3); - case 3: - r2 = MP_DIGIT(b,2); - case 2: - r1 = MP_DIGIT(b,1); - case 1: - r0 = MP_DIGIT(b,0); - } - - MP_ADD_CARRY_ZERO(a0, r0, r0, carry); - MP_ADD_CARRY(a1, r1, r1, carry, carry); - MP_ADD_CARRY(a2, r2, r2, carry, carry); - MP_ADD_CARRY(a3, r3, r3, carry, carry); - MP_ADD_CARRY(a4, r4, r4, carry, carry); - MP_ADD_CARRY(a5, r5, r5, carry, carry); - - MP_CHECKOK(s_mp_pad(r, 6)); - MP_DIGIT(r, 5) = r5; - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 6; - - /* Do quick 'subract' if we've gone over - * (add the 2's complement of the curve field) */ - a5 = MP_DIGIT(&meth->irr,5); - if (carry || r5 > a5 || - ((r5 == a5) && mp_cmp(r,&meth->irr) != MP_LT)) { - a4 = MP_DIGIT(&meth->irr,4); - a3 = MP_DIGIT(&meth->irr,3); - a2 = MP_DIGIT(&meth->irr,2); - a1 = MP_DIGIT(&meth->irr,1); - a0 = MP_DIGIT(&meth->irr,0); - MP_SUB_BORROW(r0, a0, r0, 0, carry); - MP_SUB_BORROW(r1, a1, r1, carry, carry); - MP_SUB_BORROW(r2, a2, r2, carry, carry); - MP_SUB_BORROW(r3, a3, r3, carry, carry); - MP_SUB_BORROW(r4, a4, r4, carry, carry); - MP_SUB_BORROW(r5, a5, r5, carry, carry); - MP_DIGIT(r, 5) = r5; - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - } - - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* - * The following subraction functions do in-line subractions based - * on our curve size. - * - * ... 3 words - */ -mp_err -ec_GFp_sub_3(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit b0 = 0, b1 = 0, b2 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0; - mp_digit borrow; - - switch(MP_USED(a)) { - case 3: - r2 = MP_DIGIT(a,2); - case 2: - r1 = MP_DIGIT(a,1); - case 1: - r0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 3: - b2 = MP_DIGIT(b,2); - case 2: - b1 = MP_DIGIT(b,1); - case 1: - b0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, b0, r0, 0, borrow); - MP_SUB_BORROW(r1, b1, r1, borrow, borrow); - MP_SUB_BORROW(r2, b2, r2, borrow, borrow); -#else - __asm__ ( - "xorq %3,%3 \n\t" - "subq %4,%0 \n\t" - "sbbq %5,%1 \n\t" - "sbbq %6,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r" (borrow) - : "r" (b0), "r" (b1), "r" (b2), - "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - - /* Do quick 'add' if we've gone under 0 - * (subtract the 2's complement of the curve field) */ - if (borrow) { - b2 = MP_DIGIT(&meth->irr,2); - b1 = MP_DIGIT(&meth->irr,1); - b0 = MP_DIGIT(&meth->irr,0); -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(b0, r0, r0, borrow); - MP_ADD_CARRY(b1, r1, r1, borrow, borrow); - MP_ADD_CARRY(b2, r2, r2, borrow, borrow); -#else - __asm__ ( - "addq %3,%0 \n\t" - "adcq %4,%1 \n\t" - "adcq %5,%2 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2) - : "r" (b0), "r" (b1), "r" (b2), - "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - } - -#ifdef MPI_AMD64_ADD - /* compiler fakeout? */ - if ((r2 == b0) && (r1 == b0) && (r0 == b0)) { - MP_CHECKOK(s_mp_pad(r, 4)); - } -#endif - MP_CHECKOK(s_mp_pad(r, 3)); - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 3; - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 4 words */ -mp_err -ec_GFp_sub_4(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0; - mp_digit borrow; - - switch(MP_USED(a)) { - case 4: - r3 = MP_DIGIT(a,3); - case 3: - r2 = MP_DIGIT(a,2); - case 2: - r1 = MP_DIGIT(a,1); - case 1: - r0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 4: - b3 = MP_DIGIT(b,3); - case 3: - b2 = MP_DIGIT(b,2); - case 2: - b1 = MP_DIGIT(b,1); - case 1: - b0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, b0, r0, 0, borrow); - MP_SUB_BORROW(r1, b1, r1, borrow, borrow); - MP_SUB_BORROW(r2, b2, r2, borrow, borrow); - MP_SUB_BORROW(r3, b3, r3, borrow, borrow); -#else - __asm__ ( - "xorq %4,%4 \n\t" - "subq %5,%0 \n\t" - "sbbq %6,%1 \n\t" - "sbbq %7,%2 \n\t" - "sbbq %8,%3 \n\t" - "adcq $0,%4 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r" (borrow) - : "r" (b0), "r" (b1), "r" (b2), "r" (b3), - "0" (r0), "1" (r1), "2" (r2), "3" (r3) - : "%cc" ); -#endif - - /* Do quick 'add' if we've gone under 0 - * (subtract the 2's complement of the curve field) */ - if (borrow) { - b3 = MP_DIGIT(&meth->irr,3); - b2 = MP_DIGIT(&meth->irr,2); - b1 = MP_DIGIT(&meth->irr,1); - b0 = MP_DIGIT(&meth->irr,0); -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(b0, r0, r0, borrow); - MP_ADD_CARRY(b1, r1, r1, borrow, borrow); - MP_ADD_CARRY(b2, r2, r2, borrow, borrow); - MP_ADD_CARRY(b3, r3, r3, borrow, borrow); -#else - __asm__ ( - "addq %4,%0 \n\t" - "adcq %5,%1 \n\t" - "adcq %6,%2 \n\t" - "adcq %7,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3) - : "r" (b0), "r" (b1), "r" (b2), "r" (b3), - "0" (r0), "1" (r1), "2" (r2), "3" (r3) - : "%cc" ); -#endif - } -#ifdef MPI_AMD64_ADD - /* compiler fakeout? */ - if ((r3 == b0) && (r1 == b0) && (r0 == b0)) { - MP_CHECKOK(s_mp_pad(r, 4)); - } -#endif - MP_CHECKOK(s_mp_pad(r, 4)); - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 4; - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 5 words */ -mp_err -ec_GFp_sub_5(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; - mp_digit borrow; - - switch(MP_USED(a)) { - case 5: - r4 = MP_DIGIT(a,4); - case 4: - r3 = MP_DIGIT(a,3); - case 3: - r2 = MP_DIGIT(a,2); - case 2: - r1 = MP_DIGIT(a,1); - case 1: - r0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 5: - b4 = MP_DIGIT(b,4); - case 4: - b3 = MP_DIGIT(b,3); - case 3: - b2 = MP_DIGIT(b,2); - case 2: - b1 = MP_DIGIT(b,1); - case 1: - b0 = MP_DIGIT(b,0); - } - - MP_SUB_BORROW(r0, b0, r0, 0, borrow); - MP_SUB_BORROW(r1, b1, r1, borrow, borrow); - MP_SUB_BORROW(r2, b2, r2, borrow, borrow); - MP_SUB_BORROW(r3, b3, r3, borrow, borrow); - MP_SUB_BORROW(r4, b4, r4, borrow, borrow); - - /* Do quick 'add' if we've gone under 0 - * (subtract the 2's complement of the curve field) */ - if (borrow) { - b4 = MP_DIGIT(&meth->irr,4); - b3 = MP_DIGIT(&meth->irr,3); - b2 = MP_DIGIT(&meth->irr,2); - b1 = MP_DIGIT(&meth->irr,1); - b0 = MP_DIGIT(&meth->irr,0); - MP_ADD_CARRY_ZERO(b0, r0, r0, borrow); - MP_ADD_CARRY(b1, r1, r1, borrow, borrow); - MP_ADD_CARRY(b2, r2, r2, borrow, borrow); - MP_ADD_CARRY(b3, r3, r3, borrow, borrow); - MP_ADD_CARRY(b4, r4, r4, borrow, borrow); - } - MP_CHECKOK(s_mp_pad(r, 5)); - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 5; - s_mp_clamp(r); - - CLEANUP: - return res; -} - -/* 6 words */ -mp_err -ec_GFp_sub_6(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0; - mp_digit borrow; - - switch(MP_USED(a)) { - case 6: - r5 = MP_DIGIT(a,5); - case 5: - r4 = MP_DIGIT(a,4); - case 4: - r3 = MP_DIGIT(a,3); - case 3: - r2 = MP_DIGIT(a,2); - case 2: - r1 = MP_DIGIT(a,1); - case 1: - r0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 6: - b5 = MP_DIGIT(b,5); - case 5: - b4 = MP_DIGIT(b,4); - case 4: - b3 = MP_DIGIT(b,3); - case 3: - b2 = MP_DIGIT(b,2); - case 2: - b1 = MP_DIGIT(b,1); - case 1: - b0 = MP_DIGIT(b,0); - } - - MP_SUB_BORROW(r0, b0, r0, 0, borrow); - MP_SUB_BORROW(r1, b1, r1, borrow, borrow); - MP_SUB_BORROW(r2, b2, r2, borrow, borrow); - MP_SUB_BORROW(r3, b3, r3, borrow, borrow); - MP_SUB_BORROW(r4, b4, r4, borrow, borrow); - MP_SUB_BORROW(r5, b5, r5, borrow, borrow); - - /* Do quick 'add' if we've gone under 0 - * (subtract the 2's complement of the curve field) */ - if (borrow) { - b5 = MP_DIGIT(&meth->irr,5); - b4 = MP_DIGIT(&meth->irr,4); - b3 = MP_DIGIT(&meth->irr,3); - b2 = MP_DIGIT(&meth->irr,2); - b1 = MP_DIGIT(&meth->irr,1); - b0 = MP_DIGIT(&meth->irr,0); - MP_ADD_CARRY_ZERO(b0, r0, r0, borrow); - MP_ADD_CARRY(b1, r1, r1, borrow, borrow); - MP_ADD_CARRY(b2, r2, r2, borrow, borrow); - MP_ADD_CARRY(b3, r3, r3, borrow, borrow); - MP_ADD_CARRY(b4, r4, r4, borrow, borrow); - MP_ADD_CARRY(b5, r5, r5, borrow, borrow); - } - - MP_CHECKOK(s_mp_pad(r, 6)); - MP_DIGIT(r, 5) = r5; - MP_DIGIT(r, 4) = r4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 6; - s_mp_clamp(r); - - CLEANUP: - return res; -} - - -/* Reduces an integer to a field element. */ -mp_err -ec_GFp_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - return mp_mod(a, &meth->irr, r); -} - -/* Multiplies two field elements. */ -mp_err -ec_GFp_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - return mp_mulmod(a, b, &meth->irr, r); -} - -/* Squares a field element. */ -mp_err -ec_GFp_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - return mp_sqrmod(a, &meth->irr, r); -} - -/* Divides two field elements. If a is NULL, then returns the inverse of - * b. */ -mp_err -ec_GFp_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_int t; - - /* If a is NULL, then return the inverse of b, otherwise return a/b. */ - if (a == NULL) { - return mp_invmod(b, &meth->irr, r); - } else { - /* MPI doesn't support divmod, so we implement it using invmod and - * mulmod. */ - MP_CHECKOK(mp_init(&t, FLAG(b))); - MP_CHECKOK(mp_invmod(b, &meth->irr, &t)); - MP_CHECKOK(mp_mulmod(a, &t, &meth->irr, r)); - CLEANUP: - mp_clear(&t); - return res; - } -} - -/* Wrapper functions for generic binary polynomial field arithmetic. */ - -/* Adds two field elements. */ -mp_err -ec_GF2m_add(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - return mp_badd(a, b, r); -} - -/* Negates a field element. Note that for binary polynomial fields, the - * negation of a field element is the field element itself. */ -mp_err -ec_GF2m_neg(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - if (a == r) { - return MP_OKAY; - } else { - return mp_copy(a, r); - } -} - -/* Reduces a binary polynomial to a field element. */ -mp_err -ec_GF2m_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - return mp_bmod(a, meth->irr_arr, r); -} - -/* Multiplies two field elements. */ -mp_err -ec_GF2m_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - return mp_bmulmod(a, b, meth->irr_arr, r); -} - -/* Squares a field element. */ -mp_err -ec_GF2m_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - return mp_bsqrmod(a, meth->irr_arr, r); -} - -/* Divides two field elements. If a is NULL, then returns the inverse of - * b. */ -mp_err -ec_GF2m_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_int t; - - /* If a is NULL, then return the inverse of b, otherwise return a/b. */ - if (a == NULL) { - /* The GF(2^m) portion of MPI doesn't support invmod, so we - * compute 1/b. */ - MP_CHECKOK(mp_init(&t, FLAG(b))); - MP_CHECKOK(mp_set_int(&t, 1)); - MP_CHECKOK(mp_bdivmod(&t, b, &meth->irr, meth->irr_arr, r)); - CLEANUP: - mp_clear(&t); - return res; - } else { - return mp_bdivmod(a, b, &meth->irr, meth->irr_arr, r); - } -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c deleted file mode 100644 index 316dd0c9d56b1..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecl_mult.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "mpi.h" -#include "mplogic.h" -#include "ecl.h" -#include "ecl-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k * P(x, - * y). If x, y = NULL, then P is assumed to be the generator (base point) - * of the group of points on the elliptic curve. Input and output values - * are assumed to be NOT field-encoded. */ -mp_err -ECPoint_mul(const ECGroup *group, const mp_int *k, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - int timing) -{ - mp_err res = MP_OKAY; - mp_int kt; - - ARGCHK((k != NULL) && (group != NULL), MP_BADARG); - MP_DIGITS(&kt) = 0; - - /* want scalar to be less than or equal to group order */ - if (mp_cmp(k, &group->order) > 0) { - MP_CHECKOK(mp_init(&kt, FLAG(k))); - MP_CHECKOK(mp_mod(k, &group->order, &kt)); - } else { - MP_SIGN(&kt) = MP_ZPOS; - MP_USED(&kt) = MP_USED(k); - MP_ALLOC(&kt) = MP_ALLOC(k); - MP_DIGITS(&kt) = MP_DIGITS(k); - } - - if ((px == NULL) || (py == NULL)) { - if (group->base_point_mul) { - MP_CHECKOK(group->base_point_mul(&kt, rx, ry, group)); - } else { - kt.flag = (mp_sign)0; - MP_CHECKOK(group-> - point_mul(&kt, &group->genx, &group->geny, rx, ry, - group, timing)); - } - } else { - kt.flag = (mp_sign)0; - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(px, rx, group->meth)); - MP_CHECKOK(group->meth->field_enc(py, ry, group->meth)); - MP_CHECKOK(group->point_mul(&kt, rx, ry, rx, ry, group, timing)); - } else { - MP_CHECKOK(group->point_mul(&kt, px, py, rx, ry, group, timing)); - } - } - if (group->meth->field_dec) { - MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth)); - } - - CLEANUP: - if (MP_DIGITS(&kt) != MP_DIGITS(k)) { - mp_clear(&kt); - } - return res; -} - -/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G + - * k2 * P(x, y), where G is the generator (base point) of the group of - * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL. - * Input and output values are assumed to be NOT field-encoded. */ -mp_err -ec_pts_mul_basic(const mp_int *k1, const mp_int *k2, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing) -{ - mp_err res = MP_OKAY; - mp_int sx, sy; - - ARGCHK(group != NULL, MP_BADARG); - ARGCHK(!((k1 == NULL) - && ((k2 == NULL) || (px == NULL) - || (py == NULL))), MP_BADARG); - - /* if some arguments are not defined used ECPoint_mul */ - if (k1 == NULL) { - return ECPoint_mul(group, k2, px, py, rx, ry, timing); - } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) { - return ECPoint_mul(group, k1, NULL, NULL, rx, ry, timing); - } - - MP_DIGITS(&sx) = 0; - MP_DIGITS(&sy) = 0; - MP_CHECKOK(mp_init(&sx, FLAG(k1))); - MP_CHECKOK(mp_init(&sy, FLAG(k1))); - - MP_CHECKOK(ECPoint_mul(group, k1, NULL, NULL, &sx, &sy, timing)); - MP_CHECKOK(ECPoint_mul(group, k2, px, py, rx, ry, timing)); - - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(&sx, &sx, group->meth)); - MP_CHECKOK(group->meth->field_enc(&sy, &sy, group->meth)); - MP_CHECKOK(group->meth->field_enc(rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_enc(ry, ry, group->meth)); - } - - MP_CHECKOK(group->point_add(&sx, &sy, rx, ry, rx, ry, group)); - - if (group->meth->field_dec) { - MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth)); - } - - CLEANUP: - mp_clear(&sx); - mp_clear(&sy); - return res; -} - -/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G + - * k2 * P(x, y), where G is the generator (base point) of the group of - * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL. - * Input and output values are assumed to be NOT field-encoded. Uses - * algorithm 15 (simultaneous multiple point multiplication) from Brown, - * Hankerson, Lopez, Menezes. Software Implementation of the NIST - * Elliptic Curves over Prime Fields. */ -mp_err -ec_pts_mul_simul_w2(const mp_int *k1, const mp_int *k2, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing) -{ - mp_err res = MP_OKAY; - mp_int precomp[4][4][2]; - const mp_int *a, *b; - int i, j; - int ai, bi, d; - - ARGCHK(group != NULL, MP_BADARG); - ARGCHK(!((k1 == NULL) - && ((k2 == NULL) || (px == NULL) - || (py == NULL))), MP_BADARG); - - /* if some arguments are not defined used ECPoint_mul */ - if (k1 == NULL) { - return ECPoint_mul(group, k2, px, py, rx, ry, timing); - } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) { - return ECPoint_mul(group, k1, NULL, NULL, rx, ry, timing); - } - - /* initialize precomputation table */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - MP_DIGITS(&precomp[i][j][0]) = 0; - MP_DIGITS(&precomp[i][j][1]) = 0; - } - } - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - MP_CHECKOK( mp_init_size(&precomp[i][j][0], - ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) ); - MP_CHECKOK( mp_init_size(&precomp[i][j][1], - ECL_MAX_FIELD_SIZE_DIGITS, FLAG(k1)) ); - } - } - - /* fill precomputation table */ - /* assign {k1, k2} = {a, b} such that len(a) >= len(b) */ - if (mpl_significant_bits(k1) < mpl_significant_bits(k2)) { - a = k2; - b = k1; - if (group->meth->field_enc) { - MP_CHECKOK(group->meth-> - field_enc(px, &precomp[1][0][0], group->meth)); - MP_CHECKOK(group->meth-> - field_enc(py, &precomp[1][0][1], group->meth)); - } else { - MP_CHECKOK(mp_copy(px, &precomp[1][0][0])); - MP_CHECKOK(mp_copy(py, &precomp[1][0][1])); - } - MP_CHECKOK(mp_copy(&group->genx, &precomp[0][1][0])); - MP_CHECKOK(mp_copy(&group->geny, &precomp[0][1][1])); - } else { - a = k1; - b = k2; - MP_CHECKOK(mp_copy(&group->genx, &precomp[1][0][0])); - MP_CHECKOK(mp_copy(&group->geny, &precomp[1][0][1])); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth-> - field_enc(px, &precomp[0][1][0], group->meth)); - MP_CHECKOK(group->meth-> - field_enc(py, &precomp[0][1][1], group->meth)); - } else { - MP_CHECKOK(mp_copy(px, &precomp[0][1][0])); - MP_CHECKOK(mp_copy(py, &precomp[0][1][1])); - } - } - /* precompute [*][0][*] */ - mp_zero(&precomp[0][0][0]); - mp_zero(&precomp[0][0][1]); - MP_CHECKOK(group-> - point_dbl(&precomp[1][0][0], &precomp[1][0][1], - &precomp[2][0][0], &precomp[2][0][1], group)); - MP_CHECKOK(group-> - point_add(&precomp[1][0][0], &precomp[1][0][1], - &precomp[2][0][0], &precomp[2][0][1], - &precomp[3][0][0], &precomp[3][0][1], group)); - /* precompute [*][1][*] */ - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][1][0], &precomp[0][1][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][1][0], &precomp[i][1][1], group)); - } - /* precompute [*][2][*] */ - MP_CHECKOK(group-> - point_dbl(&precomp[0][1][0], &precomp[0][1][1], - &precomp[0][2][0], &precomp[0][2][1], group)); - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][2][0], &precomp[0][2][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][2][0], &precomp[i][2][1], group)); - } - /* precompute [*][3][*] */ - MP_CHECKOK(group-> - point_add(&precomp[0][1][0], &precomp[0][1][1], - &precomp[0][2][0], &precomp[0][2][1], - &precomp[0][3][0], &precomp[0][3][1], group)); - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][3][0], &precomp[0][3][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][3][0], &precomp[i][3][1], group)); - } - - d = (mpl_significant_bits(a) + 1) / 2; - - /* R = inf */ - mp_zero(rx); - mp_zero(ry); - - for (i = d - 1; i >= 0; i--) { - ai = MP_GET_BIT(a, 2 * i + 1); - ai <<= 1; - ai |= MP_GET_BIT(a, 2 * i); - bi = MP_GET_BIT(b, 2 * i + 1); - bi <<= 1; - bi |= MP_GET_BIT(b, 2 * i); - /* R = 2^2 * R */ - MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group)); - MP_CHECKOK(group->point_dbl(rx, ry, rx, ry, group)); - /* R = R + (ai * A + bi * B) */ - MP_CHECKOK(group-> - point_add(rx, ry, &precomp[ai][bi][0], - &precomp[ai][bi][1], rx, ry, group)); - } - - if (group->meth->field_dec) { - MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth)); - } - - CLEANUP: - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - mp_clear(&precomp[i][j][0]); - mp_clear(&precomp[i][j][1]); - } - } - return res; -} - -/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G + - * k2 * P(x, y), where G is the generator (base point) of the group of - * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL. - * Input and output values are assumed to be NOT field-encoded. */ -mp_err -ECPoints_mul(const ECGroup *group, const mp_int *k1, const mp_int *k2, - const mp_int *px, const mp_int *py, mp_int *rx, mp_int *ry, - int timing) -{ - mp_err res = MP_OKAY; - mp_int k1t, k2t; - const mp_int *k1p, *k2p; - - MP_DIGITS(&k1t) = 0; - MP_DIGITS(&k2t) = 0; - - ARGCHK(group != NULL, MP_BADARG); - - /* want scalar to be less than or equal to group order */ - if (k1 != NULL) { - if (mp_cmp(k1, &group->order) >= 0) { - MP_CHECKOK(mp_init(&k1t, FLAG(k1))); - MP_CHECKOK(mp_mod(k1, &group->order, &k1t)); - k1p = &k1t; - } else { - k1p = k1; - } - } else { - k1p = k1; - } - if (k2 != NULL) { - if (mp_cmp(k2, &group->order) >= 0) { - MP_CHECKOK(mp_init(&k2t, FLAG(k2))); - MP_CHECKOK(mp_mod(k2, &group->order, &k2t)); - k2p = &k2t; - } else { - k2p = k2; - } - } else { - k2p = k2; - } - - /* if points_mul is defined, then use it */ - if (group->points_mul) { - res = group->points_mul(k1p, k2p, px, py, rx, ry, group, timing); - } else { - res = ec_pts_mul_simul_w2(k1p, k2p, px, py, rx, ry, group, timing); - } - - CLEANUP: - mp_clear(&k1t); - mp_clear(&k2t); - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp.h b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp.h deleted file mode 100644 index b367b909e80b0..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#ifndef _ECP_H -#define _ECP_H - -#include "ecl-priv.h" - -/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ -mp_err ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py); - -/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ -mp_err ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py); - -/* Computes R = P + Q where R is (rx, ry), P is (px, py) and Q is (qx, - * qy). Uses affine coordinates. */ -mp_err ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Computes R = P - Q. Uses affine coordinates. */ -mp_err ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Computes R = 2P. Uses affine coordinates. */ -mp_err ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group); - -/* Validates a point on a GFp curve. */ -mp_err ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group); - -#ifdef ECL_ENABLE_GFP_PT_MUL_AFF -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the prime that - * determines the field GFp. Uses affine coordinates. */ -mp_err ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group); -#endif - -/* Converts a point P(px, py) from affine coordinates to Jacobian - * projective coordinates R(rx, ry, rz). */ -mp_err ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, mp_int *rz, const ECGroup *group); - -/* Converts a point P(px, py, pz) from Jacobian projective coordinates to - * affine coordinates R(rx, ry). */ -mp_err ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py, - const mp_int *pz, mp_int *rx, mp_int *ry, - const ECGroup *group); - -/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian - * coordinates. */ -mp_err ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py, - const mp_int *pz); - -/* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian - * coordinates. */ -mp_err ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz); - -/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is - * (qx, qy, qz). Uses Jacobian coordinates. */ -mp_err ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, - const mp_int *pz, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - mp_int *rz, const ECGroup *group); - -/* Computes R = 2P. Uses Jacobian coordinates. */ -mp_err ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py, - const mp_int *pz, mp_int *rx, mp_int *ry, - mp_int *rz, const ECGroup *group); - -#ifdef ECL_ENABLE_GFP_PT_MUL_JAC -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the prime that - * determines the field GFp. Uses Jacobian coordinates. */ -mp_err ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group); -#endif - -/* Computes R(x, y) = k1 * G + k2 * P(x, y), where G is the generator - * (base point) of the group of points on the elliptic curve. Allows k1 = - * NULL or { k2, P } = NULL. Implemented using mixed Jacobian-affine - * coordinates. Input and output values are assumed to be NOT - * field-encoded and are in affine form. */ -mp_err - ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing); - -/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic - * curve points P and R can be identical. Uses mixed Modified-Jacobian - * co-ordinates for doubling and Chudnovsky Jacobian coordinates for - * additions. Assumes input is already field-encoded using field_enc, and - * returns output that is still field-encoded. Uses 5-bit window NAF - * method (algorithm 11) for scalar-point multiplication from Brown, - * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic - * Curves Over Prime Fields. The implementation includes a countermeasure - * that attempts to hide the size of n from timing channels. This counter- - * measure is enabled using the timing argument. The high-rder bits of timing - * must be uniformly random in order for this countermeasure to work. */ -mp_err - ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group, - int timing); - -#endif /* _ECP_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_192.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_192.c deleted file mode 100644 index 69b0d8571c0f0..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_192.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "ecp.h" -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -#define ECP192_DIGITS ECL_CURVE_DIGITS(192) - -/* Fast modular reduction for p192 = 2^192 - 2^64 - 1. a can be r. Uses - * algorithm 7 from Brown, Hankerson, Lopez, Menezes. Software - * Implementation of the NIST Elliptic Curves over Prime Fields. */ -mp_err -ec_GFp_nistp192_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_size a_used = MP_USED(a); - mp_digit r3; -#ifndef MPI_AMD64_ADD - mp_digit carry; -#endif -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a5a = 0, a5b = 0, a4a = 0, a4b = 0, a3a = 0, a3b = 0; - mp_digit r0a, r0b, r1a, r1b, r2a, r2b; -#else - mp_digit a5 = 0, a4 = 0, a3 = 0; - mp_digit r0, r1, r2; -#endif - - /* reduction not needed if a is not larger than field size */ - if (a_used < ECP192_DIGITS) { - if (a == r) { - return MP_OKAY; - } - return mp_copy(a, r); - } - - /* for polynomials larger than twice the field size, use regular - * reduction */ - if (a_used > ECP192_DIGITS*2) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { - /* copy out upper words of a */ - -#ifdef ECL_THIRTY_TWO_BIT - - /* in all the math below, - * nXb is most signifiant, nXa is least significant */ - switch (a_used) { - case 12: - a5b = MP_DIGIT(a, 11); - case 11: - a5a = MP_DIGIT(a, 10); - case 10: - a4b = MP_DIGIT(a, 9); - case 9: - a4a = MP_DIGIT(a, 8); - case 8: - a3b = MP_DIGIT(a, 7); - case 7: - a3a = MP_DIGIT(a, 6); - } - - - r2b= MP_DIGIT(a, 5); - r2a= MP_DIGIT(a, 4); - r1b = MP_DIGIT(a, 3); - r1a = MP_DIGIT(a, 2); - r0b = MP_DIGIT(a, 1); - r0a = MP_DIGIT(a, 0); - - /* implement r = (a2,a1,a0)+(a5,a5,a5)+(a4,a4,0)+(0,a3,a3) */ - MP_ADD_CARRY(r0a, a3a, r0a, 0, carry); - MP_ADD_CARRY(r0b, a3b, r0b, carry, carry); - MP_ADD_CARRY(r1a, a3a, r1a, carry, carry); - MP_ADD_CARRY(r1b, a3b, r1b, carry, carry); - MP_ADD_CARRY(r2a, a4a, r2a, carry, carry); - MP_ADD_CARRY(r2b, a4b, r2b, carry, carry); - r3 = carry; carry = 0; - MP_ADD_CARRY(r0a, a5a, r0a, 0, carry); - MP_ADD_CARRY(r0b, a5b, r0b, carry, carry); - MP_ADD_CARRY(r1a, a5a, r1a, carry, carry); - MP_ADD_CARRY(r1b, a5b, r1b, carry, carry); - MP_ADD_CARRY(r2a, a5a, r2a, carry, carry); - MP_ADD_CARRY(r2b, a5b, r2b, carry, carry); - r3 += carry; - MP_ADD_CARRY(r1a, a4a, r1a, 0, carry); - MP_ADD_CARRY(r1b, a4b, r1b, carry, carry); - MP_ADD_CARRY(r2a, 0, r2a, carry, carry); - MP_ADD_CARRY(r2b, 0, r2b, carry, carry); - r3 += carry; - - /* reduce out the carry */ - while (r3) { - MP_ADD_CARRY(r0a, r3, r0a, 0, carry); - MP_ADD_CARRY(r0b, 0, r0b, carry, carry); - MP_ADD_CARRY(r1a, r3, r1a, carry, carry); - MP_ADD_CARRY(r1b, 0, r1b, carry, carry); - MP_ADD_CARRY(r2a, 0, r2a, carry, carry); - MP_ADD_CARRY(r2b, 0, r2b, carry, carry); - r3 = carry; - } - - /* check for final reduction */ - /* - * our field is 0xffffffffffffffff, 0xfffffffffffffffe, - * 0xffffffffffffffff. That means we can only be over and need - * one more reduction - * if r2 == 0xffffffffffffffffff (same as r2+1 == 0) - * and - * r1 == 0xffffffffffffffffff or - * r1 == 0xfffffffffffffffffe and r0 = 0xfffffffffffffffff - * In all cases, we subtract the field (or add the 2's - * complement value (1,1,0)). (r0, r1, r2) - */ - if (((r2b == 0xffffffff) && (r2a == 0xffffffff) - && (r1b == 0xffffffff) ) && - ((r1a == 0xffffffff) || - (r1a == 0xfffffffe) && (r0a == 0xffffffff) && - (r0b == 0xffffffff)) ) { - /* do a quick subtract */ - MP_ADD_CARRY(r0a, 1, r0a, 0, carry); - r0b += carry; - r1a = r1b = r2a = r2b = 0; - } - - /* set the lower words of r */ - if (a != r) { - MP_CHECKOK(s_mp_pad(r, 6)); - } - MP_DIGIT(r, 5) = r2b; - MP_DIGIT(r, 4) = r2a; - MP_DIGIT(r, 3) = r1b; - MP_DIGIT(r, 2) = r1a; - MP_DIGIT(r, 1) = r0b; - MP_DIGIT(r, 0) = r0a; - MP_USED(r) = 6; -#else - switch (a_used) { - case 6: - a5 = MP_DIGIT(a, 5); - case 5: - a4 = MP_DIGIT(a, 4); - case 4: - a3 = MP_DIGIT(a, 3); - } - - r2 = MP_DIGIT(a, 2); - r1 = MP_DIGIT(a, 1); - r0 = MP_DIGIT(a, 0); - - /* implement r = (a2,a1,a0)+(a5,a5,a5)+(a4,a4,0)+(0,a3,a3) */ -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(r0, a3, r0, carry); - MP_ADD_CARRY(r1, a3, r1, carry, carry); - MP_ADD_CARRY(r2, a4, r2, carry, carry); - r3 = carry; - MP_ADD_CARRY_ZERO(r0, a5, r0, carry); - MP_ADD_CARRY(r1, a5, r1, carry, carry); - MP_ADD_CARRY(r2, a5, r2, carry, carry); - r3 += carry; - MP_ADD_CARRY_ZERO(r1, a4, r1, carry); - MP_ADD_CARRY(r2, 0, r2, carry, carry); - r3 += carry; - -#else - r2 = MP_DIGIT(a, 2); - r1 = MP_DIGIT(a, 1); - r0 = MP_DIGIT(a, 0); - - /* set the lower words of r */ - __asm__ ( - "xorq %3,%3 \n\t" - "addq %4,%0 \n\t" - "adcq %4,%1 \n\t" - "adcq %5,%2 \n\t" - "adcq $0,%3 \n\t" - "addq %6,%0 \n\t" - "adcq %6,%1 \n\t" - "adcq %6,%2 \n\t" - "adcq $0,%3 \n\t" - "addq %5,%1 \n\t" - "adcq $0,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(a3), - "=r"(a4), "=r"(a5) - : "0" (r0), "1" (r1), "2" (r2), "3" (r3), - "4" (a3), "5" (a4), "6"(a5) - : "%cc" ); -#endif - - /* reduce out the carry */ - while (r3) { -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(r0, r3, r0, carry); - MP_ADD_CARRY(r1, r3, r1, carry, carry); - MP_ADD_CARRY(r2, 0, r2, carry, carry); - r3 = carry; -#else - a3=r3; - __asm__ ( - "xorq %3,%3 \n\t" - "addq %4,%0 \n\t" - "adcq %4,%1 \n\t" - "adcq $0,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(r3), "=r"(a3) - : "0" (r0), "1" (r1), "2" (r2), "3" (r3), "4"(a3) - : "%cc" ); -#endif - } - - /* check for final reduction */ - /* - * our field is 0xffffffffffffffff, 0xfffffffffffffffe, - * 0xffffffffffffffff. That means we can only be over and need - * one more reduction - * if r2 == 0xffffffffffffffffff (same as r2+1 == 0) - * and - * r1 == 0xffffffffffffffffff or - * r1 == 0xfffffffffffffffffe and r0 = 0xfffffffffffffffff - * In all cases, we subtract the field (or add the 2's - * complement value (1,1,0)). (r0, r1, r2) - */ - if (r3 || ((r2 == MP_DIGIT_MAX) && - ((r1 == MP_DIGIT_MAX) || - ((r1 == (MP_DIGIT_MAX-1)) && (r0 == MP_DIGIT_MAX))))) { - /* do a quick subtract */ - r0++; - r1 = r2 = 0; - } - /* set the lower words of r */ - if (a != r) { - MP_CHECKOK(s_mp_pad(r, 3)); - } - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_USED(r) = 3; -#endif - } - - CLEANUP: - return res; -} - -#ifndef ECL_THIRTY_TWO_BIT -/* Compute the sum of 192 bit curves. Do the work in-line since the - * number of words are so small, we don't want to overhead of mp function - * calls. Uses optimized modular reduction for p192. - */ -mp_err -ec_GFp_nistp192_add(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit a0 = 0, a1 = 0, a2 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0; - mp_digit carry; - - switch(MP_USED(a)) { - case 3: - a2 = MP_DIGIT(a,2); - case 2: - a1 = MP_DIGIT(a,1); - case 1: - a0 = MP_DIGIT(a,0); - } - switch(MP_USED(b)) { - case 3: - r2 = MP_DIGIT(b,2); - case 2: - r1 = MP_DIGIT(b,1); - case 1: - r0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(a0, r0, r0, carry); - MP_ADD_CARRY(a1, r1, r1, carry, carry); - MP_ADD_CARRY(a2, r2, r2, carry, carry); -#else - __asm__ ( - "xorq %3,%3 \n\t" - "addq %4,%0 \n\t" - "adcq %5,%1 \n\t" - "adcq %6,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(carry) - : "r" (a0), "r" (a1), "r" (a2), "0" (r0), - "1" (r1), "2" (r2) - : "%cc" ); -#endif - - /* Do quick 'subract' if we've gone over - * (add the 2's complement of the curve field) */ - if (carry || ((r2 == MP_DIGIT_MAX) && - ((r1 == MP_DIGIT_MAX) || - ((r1 == (MP_DIGIT_MAX-1)) && (r0 == MP_DIGIT_MAX))))) { -#ifndef MPI_AMD64_ADD - MP_ADD_CARRY_ZERO(r0, 1, r0, carry); - MP_ADD_CARRY(r1, 1, r1, carry, carry); - MP_ADD_CARRY(r2, 0, r2, carry, carry); -#else - __asm__ ( - "addq $1,%0 \n\t" - "adcq $1,%1 \n\t" - "adcq $0,%2 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2) - : "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - } - - - MP_CHECKOK(s_mp_pad(r, 3)); - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 3; - s_mp_clamp(r); - - - CLEANUP: - return res; -} - -/* Compute the diff of 192 bit curves. Do the work in-line since the - * number of words are so small, we don't want to overhead of mp function - * calls. Uses optimized modular reduction for p192. - */ -mp_err -ec_GFp_nistp192_sub(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_digit b0 = 0, b1 = 0, b2 = 0; - mp_digit r0 = 0, r1 = 0, r2 = 0; - mp_digit borrow; - - switch(MP_USED(a)) { - case 3: - r2 = MP_DIGIT(a,2); - case 2: - r1 = MP_DIGIT(a,1); - case 1: - r0 = MP_DIGIT(a,0); - } - - switch(MP_USED(b)) { - case 3: - b2 = MP_DIGIT(b,2); - case 2: - b1 = MP_DIGIT(b,1); - case 1: - b0 = MP_DIGIT(b,0); - } - -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, b0, r0, 0, borrow); - MP_SUB_BORROW(r1, b1, r1, borrow, borrow); - MP_SUB_BORROW(r2, b2, r2, borrow, borrow); -#else - __asm__ ( - "xorq %3,%3 \n\t" - "subq %4,%0 \n\t" - "sbbq %5,%1 \n\t" - "sbbq %6,%2 \n\t" - "adcq $0,%3 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2), "=r"(borrow) - : "r" (b0), "r" (b1), "r" (b2), "0" (r0), - "1" (r1), "2" (r2) - : "%cc" ); -#endif - - /* Do quick 'add' if we've gone under 0 - * (subtract the 2's complement of the curve field) */ - if (borrow) { -#ifndef MPI_AMD64_ADD - MP_SUB_BORROW(r0, 1, r0, 0, borrow); - MP_SUB_BORROW(r1, 1, r1, borrow, borrow); - MP_SUB_BORROW(r2, 0, r2, borrow, borrow); -#else - __asm__ ( - "subq $1,%0 \n\t" - "sbbq $1,%1 \n\t" - "sbbq $0,%2 \n\t" - : "=r"(r0), "=r"(r1), "=r"(r2) - : "0" (r0), "1" (r1), "2" (r2) - : "%cc" ); -#endif - } - - MP_CHECKOK(s_mp_pad(r, 3)); - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 3; - s_mp_clamp(r); - - CLEANUP: - return res; -} - -#endif - -/* Compute the square of polynomial a, reduce modulo p192. Store the - * result in r. r could be a. Uses optimized modular reduction for p192. - */ -mp_err -ec_GFp_nistp192_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_sqr(a, r)); - MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p192. - * Store the result in r. r could be a or b; a could be b. Uses - * optimized modular reduction for p192. */ -mp_err -ec_GFp_nistp192_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Divides two field elements. If a is NULL, then returns the inverse of - * b. */ -mp_err -ec_GFp_nistp192_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_int t; - - /* If a is NULL, then return the inverse of b, otherwise return a/b. */ - if (a == NULL) { - return mp_invmod(b, &meth->irr, r); - } else { - /* MPI doesn't support divmod, so we implement it using invmod and - * mulmod. */ - MP_CHECKOK(mp_init(&t, FLAG(b))); - MP_CHECKOK(mp_invmod(b, &meth->irr, &t)); - MP_CHECKOK(mp_mul(a, &t, r)); - MP_CHECKOK(ec_GFp_nistp192_mod(r, r, meth)); - CLEANUP: - mp_clear(&t); - return res; - } -} - -/* Wire in fast field arithmetic and precomputation of base point for - * named curves. */ -mp_err -ec_group_set_gfp192(ECGroup *group, ECCurveName name) -{ - if (name == ECCurve_NIST_P192) { - group->meth->field_mod = &ec_GFp_nistp192_mod; - group->meth->field_mul = &ec_GFp_nistp192_mul; - group->meth->field_sqr = &ec_GFp_nistp192_sqr; - group->meth->field_div = &ec_GFp_nistp192_div; -#ifndef ECL_THIRTY_TWO_BIT - group->meth->field_add = &ec_GFp_nistp192_add; - group->meth->field_sub = &ec_GFp_nistp192_sub; -#endif - } - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_224.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_224.c deleted file mode 100644 index b2901e062667f..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_224.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#include "ecp.h" -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -#define ECP224_DIGITS ECL_CURVE_DIGITS(224) - -/* Fast modular reduction for p224 = 2^224 - 2^96 + 1. a can be r. Uses - * algorithm 7 from Brown, Hankerson, Lopez, Menezes. Software - * Implementation of the NIST Elliptic Curves over Prime Fields. */ -mp_err -ec_GFp_nistp224_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_size a_used = MP_USED(a); - - int r3b; - mp_digit carry; -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a6a = 0, a6b = 0, - a5a = 0, a5b = 0, a4a = 0, a4b = 0, a3a = 0, a3b = 0; - mp_digit r0a, r0b, r1a, r1b, r2a, r2b, r3a; -#else - mp_digit a6 = 0, a5 = 0, a4 = 0, a3b = 0, a5a = 0; - mp_digit a6b = 0, a6a_a5b = 0, a5b = 0, a5a_a4b = 0, a4a_a3b = 0; - mp_digit r0, r1, r2, r3; -#endif - - /* reduction not needed if a is not larger than field size */ - if (a_used < ECP224_DIGITS) { - if (a == r) return MP_OKAY; - return mp_copy(a, r); - } - /* for polynomials larger than twice the field size, use regular - * reduction */ - if (a_used > ECL_CURVE_DIGITS(224*2)) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { -#ifdef ECL_THIRTY_TWO_BIT - /* copy out upper words of a */ - switch (a_used) { - case 14: - a6b = MP_DIGIT(a, 13); - case 13: - a6a = MP_DIGIT(a, 12); - case 12: - a5b = MP_DIGIT(a, 11); - case 11: - a5a = MP_DIGIT(a, 10); - case 10: - a4b = MP_DIGIT(a, 9); - case 9: - a4a = MP_DIGIT(a, 8); - case 8: - a3b = MP_DIGIT(a, 7); - } - r3a = MP_DIGIT(a, 6); - r2b= MP_DIGIT(a, 5); - r2a= MP_DIGIT(a, 4); - r1b = MP_DIGIT(a, 3); - r1a = MP_DIGIT(a, 2); - r0b = MP_DIGIT(a, 1); - r0a = MP_DIGIT(a, 0); - - - /* implement r = (a3a,a2,a1,a0) - +(a5a, a4,a3b, 0) - +( 0, a6,a5b, 0) - -( 0 0, 0|a6b, a6a|a5b ) - -( a6b, a6a|a5b, a5a|a4b, a4a|a3b ) */ - MP_ADD_CARRY (r1b, a3b, r1b, 0, carry); - MP_ADD_CARRY (r2a, a4a, r2a, carry, carry); - MP_ADD_CARRY (r2b, a4b, r2b, carry, carry); - MP_ADD_CARRY (r3a, a5a, r3a, carry, carry); - r3b = carry; - MP_ADD_CARRY (r1b, a5b, r1b, 0, carry); - MP_ADD_CARRY (r2a, a6a, r2a, carry, carry); - MP_ADD_CARRY (r2b, a6b, r2b, carry, carry); - MP_ADD_CARRY (r3a, 0, r3a, carry, carry); - r3b += carry; - MP_SUB_BORROW(r0a, a3b, r0a, 0, carry); - MP_SUB_BORROW(r0b, a4a, r0b, carry, carry); - MP_SUB_BORROW(r1a, a4b, r1a, carry, carry); - MP_SUB_BORROW(r1b, a5a, r1b, carry, carry); - MP_SUB_BORROW(r2a, a5b, r2a, carry, carry); - MP_SUB_BORROW(r2b, a6a, r2b, carry, carry); - MP_SUB_BORROW(r3a, a6b, r3a, carry, carry); - r3b -= carry; - MP_SUB_BORROW(r0a, a5b, r0a, 0, carry); - MP_SUB_BORROW(r0b, a6a, r0b, carry, carry); - MP_SUB_BORROW(r1a, a6b, r1a, carry, carry); - if (carry) { - MP_SUB_BORROW(r1b, 0, r1b, carry, carry); - MP_SUB_BORROW(r2a, 0, r2a, carry, carry); - MP_SUB_BORROW(r2b, 0, r2b, carry, carry); - MP_SUB_BORROW(r3a, 0, r3a, carry, carry); - r3b -= carry; - } - - while (r3b > 0) { - int tmp; - MP_ADD_CARRY(r1b, r3b, r1b, 0, carry); - if (carry) { - MP_ADD_CARRY(r2a, 0, r2a, carry, carry); - MP_ADD_CARRY(r2b, 0, r2b, carry, carry); - MP_ADD_CARRY(r3a, 0, r3a, carry, carry); - } - tmp = carry; - MP_SUB_BORROW(r0a, r3b, r0a, 0, carry); - if (carry) { - MP_SUB_BORROW(r0b, 0, r0b, carry, carry); - MP_SUB_BORROW(r1a, 0, r1a, carry, carry); - MP_SUB_BORROW(r1b, 0, r1b, carry, carry); - MP_SUB_BORROW(r2a, 0, r2a, carry, carry); - MP_SUB_BORROW(r2b, 0, r2b, carry, carry); - MP_SUB_BORROW(r3a, 0, r3a, carry, carry); - tmp -= carry; - } - r3b = tmp; - } - - while (r3b < 0) { - mp_digit maxInt = MP_DIGIT_MAX; - MP_ADD_CARRY (r0a, 1, r0a, 0, carry); - MP_ADD_CARRY (r0b, 0, r0b, carry, carry); - MP_ADD_CARRY (r1a, 0, r1a, carry, carry); - MP_ADD_CARRY (r1b, maxInt, r1b, carry, carry); - MP_ADD_CARRY (r2a, maxInt, r2a, carry, carry); - MP_ADD_CARRY (r2b, maxInt, r2b, carry, carry); - MP_ADD_CARRY (r3a, maxInt, r3a, carry, carry); - r3b += carry; - } - /* check for final reduction */ - /* now the only way we are over is if the top 4 words are all ones */ - if ((r3a == MP_DIGIT_MAX) && (r2b == MP_DIGIT_MAX) - && (r2a == MP_DIGIT_MAX) && (r1b == MP_DIGIT_MAX) && - ((r1a != 0) || (r0b != 0) || (r0a != 0)) ) { - /* one last subraction */ - MP_SUB_BORROW(r0a, 1, r0a, 0, carry); - MP_SUB_BORROW(r0b, 0, r0b, carry, carry); - MP_SUB_BORROW(r1a, 0, r1a, carry, carry); - r1b = r2a = r2b = r3a = 0; - } - - - if (a != r) { - MP_CHECKOK(s_mp_pad(r, 7)); - } - /* set the lower words of r */ - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 7; - MP_DIGIT(r, 6) = r3a; - MP_DIGIT(r, 5) = r2b; - MP_DIGIT(r, 4) = r2a; - MP_DIGIT(r, 3) = r1b; - MP_DIGIT(r, 2) = r1a; - MP_DIGIT(r, 1) = r0b; - MP_DIGIT(r, 0) = r0a; -#else - /* copy out upper words of a */ - switch (a_used) { - case 7: - a6 = MP_DIGIT(a, 6); - a6b = a6 >> 32; - a6a_a5b = a6 << 32; - case 6: - a5 = MP_DIGIT(a, 5); - a5b = a5 >> 32; - a6a_a5b |= a5b; - a5b = a5b << 32; - a5a_a4b = a5 << 32; - a5a = a5 & 0xffffffff; - case 5: - a4 = MP_DIGIT(a, 4); - a5a_a4b |= a4 >> 32; - a4a_a3b = a4 << 32; - case 4: - a3b = MP_DIGIT(a, 3) >> 32; - a4a_a3b |= a3b; - a3b = a3b << 32; - } - - r3 = MP_DIGIT(a, 3) & 0xffffffff; - r2 = MP_DIGIT(a, 2); - r1 = MP_DIGIT(a, 1); - r0 = MP_DIGIT(a, 0); - - /* implement r = (a3a,a2,a1,a0) - +(a5a, a4,a3b, 0) - +( 0, a6,a5b, 0) - -( 0 0, 0|a6b, a6a|a5b ) - -( a6b, a6a|a5b, a5a|a4b, a4a|a3b ) */ - MP_ADD_CARRY_ZERO (r1, a3b, r1, carry); - MP_ADD_CARRY (r2, a4 , r2, carry, carry); - MP_ADD_CARRY (r3, a5a, r3, carry, carry); - MP_ADD_CARRY_ZERO (r1, a5b, r1, carry); - MP_ADD_CARRY (r2, a6 , r2, carry, carry); - MP_ADD_CARRY (r3, 0, r3, carry, carry); - - MP_SUB_BORROW(r0, a4a_a3b, r0, 0, carry); - MP_SUB_BORROW(r1, a5a_a4b, r1, carry, carry); - MP_SUB_BORROW(r2, a6a_a5b, r2, carry, carry); - MP_SUB_BORROW(r3, a6b , r3, carry, carry); - MP_SUB_BORROW(r0, a6a_a5b, r0, 0, carry); - MP_SUB_BORROW(r1, a6b , r1, carry, carry); - if (carry) { - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, 0, r3, carry, carry); - } - - - /* if the value is negative, r3 has a 2's complement - * high value */ - r3b = (int)(r3 >>32); - while (r3b > 0) { - r3 &= 0xffffffff; - MP_ADD_CARRY_ZERO(r1,((mp_digit)r3b) << 32, r1, carry); - if (carry) { - MP_ADD_CARRY(r2, 0, r2, carry, carry); - MP_ADD_CARRY(r3, 0, r3, carry, carry); - } - MP_SUB_BORROW(r0, r3b, r0, 0, carry); - if (carry) { - MP_SUB_BORROW(r1, 0, r1, carry, carry); - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, 0, r3, carry, carry); - } - r3b = (int)(r3 >>32); - } - - while (r3b < 0) { - MP_ADD_CARRY_ZERO (r0, 1, r0, carry); - MP_ADD_CARRY (r1, MP_DIGIT_MAX <<32, r1, carry, carry); - MP_ADD_CARRY (r2, MP_DIGIT_MAX, r2, carry, carry); - MP_ADD_CARRY (r3, MP_DIGIT_MAX >> 32, r3, carry, carry); - r3b = (int)(r3 >>32); - } - /* check for final reduction */ - /* now the only way we are over is if the top 4 words are all ones */ - if ((r3 == (MP_DIGIT_MAX >> 32)) && (r2 == MP_DIGIT_MAX) - && ((r1 & MP_DIGIT_MAX << 32)== MP_DIGIT_MAX << 32) && - ((r1 != MP_DIGIT_MAX << 32 ) || (r0 != 0)) ) { - /* one last subraction */ - MP_SUB_BORROW(r0, 1, r0, 0, carry); - MP_SUB_BORROW(r1, 0, r1, carry, carry); - r2 = r3 = 0; - } - - - if (a != r) { - MP_CHECKOK(s_mp_pad(r, 4)); - } - /* set the lower words of r */ - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 4; - MP_DIGIT(r, 3) = r3; - MP_DIGIT(r, 2) = r2; - MP_DIGIT(r, 1) = r1; - MP_DIGIT(r, 0) = r0; -#endif - } - - CLEANUP: - return res; -} - -/* Compute the square of polynomial a, reduce modulo p224. Store the - * result in r. r could be a. Uses optimized modular reduction for p224. - */ -mp_err -ec_GFp_nistp224_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_sqr(a, r)); - MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p224. - * Store the result in r. r could be a or b; a could be b. Uses - * optimized modular reduction for p224. */ -mp_err -ec_GFp_nistp224_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Divides two field elements. If a is NULL, then returns the inverse of - * b. */ -mp_err -ec_GFp_nistp224_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_int t; - - /* If a is NULL, then return the inverse of b, otherwise return a/b. */ - if (a == NULL) { - return mp_invmod(b, &meth->irr, r); - } else { - /* MPI doesn't support divmod, so we implement it using invmod and - * mulmod. */ - MP_CHECKOK(mp_init(&t, FLAG(b))); - MP_CHECKOK(mp_invmod(b, &meth->irr, &t)); - MP_CHECKOK(mp_mul(a, &t, r)); - MP_CHECKOK(ec_GFp_nistp224_mod(r, r, meth)); - CLEANUP: - mp_clear(&t); - return res; - } -} - -/* Wire in fast field arithmetic and precomputation of base point for - * named curves. */ -mp_err -ec_group_set_gfp224(ECGroup *group, ECCurveName name) -{ - if (name == ECCurve_NIST_P224) { - group->meth->field_mod = &ec_GFp_nistp224_mod; - group->meth->field_mul = &ec_GFp_nistp224_mul; - group->meth->field_sqr = &ec_GFp_nistp224_sqr; - group->meth->field_div = &ec_GFp_nistp224_div; - } - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_256.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_256.c deleted file mode 100644 index a5a5fa37e5872..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_256.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila - * - *********************************************************************** */ - -#include "ecp.h" -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Fast modular reduction for p256 = 2^256 - 2^224 + 2^192+ 2^96 - 1. a can be r. - * Uses algorithm 2.29 from Hankerson, Menezes, Vanstone. Guide to - * Elliptic Curve Cryptography. */ -mp_err -ec_GFp_nistp256_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_size a_used = MP_USED(a); - int a_bits = mpl_significant_bits(a); - mp_digit carry; - -#ifdef ECL_THIRTY_TWO_BIT - mp_digit a8=0, a9=0, a10=0, a11=0, a12=0, a13=0, a14=0, a15=0; - mp_digit r0, r1, r2, r3, r4, r5, r6, r7; - int r8; /* must be a signed value ! */ -#else - mp_digit a4=0, a5=0, a6=0, a7=0; - mp_digit a4h, a4l, a5h, a5l, a6h, a6l, a7h, a7l; - mp_digit r0, r1, r2, r3; - int r4; /* must be a signed value ! */ -#endif - /* for polynomials larger than twice the field size - * use regular reduction */ - if (a_bits < 256) { - if (a == r) return MP_OKAY; - return mp_copy(a,r); - } - if (a_bits > 512) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { - -#ifdef ECL_THIRTY_TWO_BIT - switch (a_used) { - case 16: - a15 = MP_DIGIT(a,15); - case 15: - a14 = MP_DIGIT(a,14); - case 14: - a13 = MP_DIGIT(a,13); - case 13: - a12 = MP_DIGIT(a,12); - case 12: - a11 = MP_DIGIT(a,11); - case 11: - a10 = MP_DIGIT(a,10); - case 10: - a9 = MP_DIGIT(a,9); - case 9: - a8 = MP_DIGIT(a,8); - } - - r0 = MP_DIGIT(a,0); - r1 = MP_DIGIT(a,1); - r2 = MP_DIGIT(a,2); - r3 = MP_DIGIT(a,3); - r4 = MP_DIGIT(a,4); - r5 = MP_DIGIT(a,5); - r6 = MP_DIGIT(a,6); - r7 = MP_DIGIT(a,7); - - /* sum 1 */ - MP_ADD_CARRY(r3, a11, r3, 0, carry); - MP_ADD_CARRY(r4, a12, r4, carry, carry); - MP_ADD_CARRY(r5, a13, r5, carry, carry); - MP_ADD_CARRY(r6, a14, r6, carry, carry); - MP_ADD_CARRY(r7, a15, r7, carry, carry); - r8 = carry; - MP_ADD_CARRY(r3, a11, r3, 0, carry); - MP_ADD_CARRY(r4, a12, r4, carry, carry); - MP_ADD_CARRY(r5, a13, r5, carry, carry); - MP_ADD_CARRY(r6, a14, r6, carry, carry); - MP_ADD_CARRY(r7, a15, r7, carry, carry); - r8 += carry; - /* sum 2 */ - MP_ADD_CARRY(r3, a12, r3, 0, carry); - MP_ADD_CARRY(r4, a13, r4, carry, carry); - MP_ADD_CARRY(r5, a14, r5, carry, carry); - MP_ADD_CARRY(r6, a15, r6, carry, carry); - MP_ADD_CARRY(r7, 0, r7, carry, carry); - r8 += carry; - /* combine last bottom of sum 3 with second sum 2 */ - MP_ADD_CARRY(r0, a8, r0, 0, carry); - MP_ADD_CARRY(r1, a9, r1, carry, carry); - MP_ADD_CARRY(r2, a10, r2, carry, carry); - MP_ADD_CARRY(r3, a12, r3, carry, carry); - MP_ADD_CARRY(r4, a13, r4, carry, carry); - MP_ADD_CARRY(r5, a14, r5, carry, carry); - MP_ADD_CARRY(r6, a15, r6, carry, carry); - MP_ADD_CARRY(r7, a15, r7, carry, carry); /* from sum 3 */ - r8 += carry; - /* sum 3 (rest of it)*/ - MP_ADD_CARRY(r6, a14, r6, 0, carry); - MP_ADD_CARRY(r7, 0, r7, carry, carry); - r8 += carry; - /* sum 4 (rest of it)*/ - MP_ADD_CARRY(r0, a9, r0, 0, carry); - MP_ADD_CARRY(r1, a10, r1, carry, carry); - MP_ADD_CARRY(r2, a11, r2, carry, carry); - MP_ADD_CARRY(r3, a13, r3, carry, carry); - MP_ADD_CARRY(r4, a14, r4, carry, carry); - MP_ADD_CARRY(r5, a15, r5, carry, carry); - MP_ADD_CARRY(r6, a13, r6, carry, carry); - MP_ADD_CARRY(r7, a8, r7, carry, carry); - r8 += carry; - /* diff 5 */ - MP_SUB_BORROW(r0, a11, r0, 0, carry); - MP_SUB_BORROW(r1, a12, r1, carry, carry); - MP_SUB_BORROW(r2, a13, r2, carry, carry); - MP_SUB_BORROW(r3, 0, r3, carry, carry); - MP_SUB_BORROW(r4, 0, r4, carry, carry); - MP_SUB_BORROW(r5, 0, r5, carry, carry); - MP_SUB_BORROW(r6, a8, r6, carry, carry); - MP_SUB_BORROW(r7, a10, r7, carry, carry); - r8 -= carry; - /* diff 6 */ - MP_SUB_BORROW(r0, a12, r0, 0, carry); - MP_SUB_BORROW(r1, a13, r1, carry, carry); - MP_SUB_BORROW(r2, a14, r2, carry, carry); - MP_SUB_BORROW(r3, a15, r3, carry, carry); - MP_SUB_BORROW(r4, 0, r4, carry, carry); - MP_SUB_BORROW(r5, 0, r5, carry, carry); - MP_SUB_BORROW(r6, a9, r6, carry, carry); - MP_SUB_BORROW(r7, a11, r7, carry, carry); - r8 -= carry; - /* diff 7 */ - MP_SUB_BORROW(r0, a13, r0, 0, carry); - MP_SUB_BORROW(r1, a14, r1, carry, carry); - MP_SUB_BORROW(r2, a15, r2, carry, carry); - MP_SUB_BORROW(r3, a8, r3, carry, carry); - MP_SUB_BORROW(r4, a9, r4, carry, carry); - MP_SUB_BORROW(r5, a10, r5, carry, carry); - MP_SUB_BORROW(r6, 0, r6, carry, carry); - MP_SUB_BORROW(r7, a12, r7, carry, carry); - r8 -= carry; - /* diff 8 */ - MP_SUB_BORROW(r0, a14, r0, 0, carry); - MP_SUB_BORROW(r1, a15, r1, carry, carry); - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, a9, r3, carry, carry); - MP_SUB_BORROW(r4, a10, r4, carry, carry); - MP_SUB_BORROW(r5, a11, r5, carry, carry); - MP_SUB_BORROW(r6, 0, r6, carry, carry); - MP_SUB_BORROW(r7, a13, r7, carry, carry); - r8 -= carry; - - /* reduce the overflows */ - while (r8 > 0) { - mp_digit r8_d = r8; - MP_ADD_CARRY(r0, r8_d, r0, 0, carry); - MP_ADD_CARRY(r1, 0, r1, carry, carry); - MP_ADD_CARRY(r2, 0, r2, carry, carry); - MP_ADD_CARRY(r3, -r8_d, r3, carry, carry); - MP_ADD_CARRY(r4, MP_DIGIT_MAX, r4, carry, carry); - MP_ADD_CARRY(r5, MP_DIGIT_MAX, r5, carry, carry); - MP_ADD_CARRY(r6, -(r8_d+1), r6, carry, carry); - MP_ADD_CARRY(r7, (r8_d-1), r7, carry, carry); - r8 = carry; - } - - /* reduce the underflows */ - while (r8 < 0) { - mp_digit r8_d = -r8; - MP_SUB_BORROW(r0, r8_d, r0, 0, carry); - MP_SUB_BORROW(r1, 0, r1, carry, carry); - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, -r8_d, r3, carry, carry); - MP_SUB_BORROW(r4, MP_DIGIT_MAX, r4, carry, carry); - MP_SUB_BORROW(r5, MP_DIGIT_MAX, r5, carry, carry); - MP_SUB_BORROW(r6, -(r8_d+1), r6, carry, carry); - MP_SUB_BORROW(r7, (r8_d-1), r7, carry, carry); - r8 = -carry; - } - if (a != r) { - MP_CHECKOK(s_mp_pad(r,8)); - } - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 8; - - MP_DIGIT(r,7) = r7; - MP_DIGIT(r,6) = r6; - MP_DIGIT(r,5) = r5; - MP_DIGIT(r,4) = r4; - MP_DIGIT(r,3) = r3; - MP_DIGIT(r,2) = r2; - MP_DIGIT(r,1) = r1; - MP_DIGIT(r,0) = r0; - - /* final reduction if necessary */ - if ((r7 == MP_DIGIT_MAX) && - ((r6 > 1) || ((r6 == 1) && - (r5 || r4 || r3 || - ((r2 == MP_DIGIT_MAX) && (r1 == MP_DIGIT_MAX) - && (r0 == MP_DIGIT_MAX)))))) { - MP_CHECKOK(mp_sub(r, &meth->irr, r)); - } -#ifdef notdef - - - /* smooth the negatives */ - while (MP_SIGN(r) != MP_ZPOS) { - MP_CHECKOK(mp_add(r, &meth->irr, r)); - } - while (MP_USED(r) > 8) { - MP_CHECKOK(mp_sub(r, &meth->irr, r)); - } - - /* final reduction if necessary */ - if (MP_DIGIT(r,7) >= MP_DIGIT(&meth->irr,7)) { - if (mp_cmp(r,&meth->irr) != MP_LT) { - MP_CHECKOK(mp_sub(r, &meth->irr, r)); - } - } -#endif - s_mp_clamp(r); -#else - switch (a_used) { - case 8: - a7 = MP_DIGIT(a,7); - case 7: - a6 = MP_DIGIT(a,6); - case 6: - a5 = MP_DIGIT(a,5); - case 5: - a4 = MP_DIGIT(a,4); - } - a7l = a7 << 32; - a7h = a7 >> 32; - a6l = a6 << 32; - a6h = a6 >> 32; - a5l = a5 << 32; - a5h = a5 >> 32; - a4l = a4 << 32; - a4h = a4 >> 32; - r3 = MP_DIGIT(a,3); - r2 = MP_DIGIT(a,2); - r1 = MP_DIGIT(a,1); - r0 = MP_DIGIT(a,0); - - /* sum 1 */ - MP_ADD_CARRY_ZERO(r1, a5h << 32, r1, carry); - MP_ADD_CARRY(r2, a6, r2, carry, carry); - MP_ADD_CARRY(r3, a7, r3, carry, carry); - r4 = carry; - MP_ADD_CARRY_ZERO(r1, a5h << 32, r1, carry); - MP_ADD_CARRY(r2, a6, r2, carry, carry); - MP_ADD_CARRY(r3, a7, r3, carry, carry); - r4 += carry; - /* sum 2 */ - MP_ADD_CARRY_ZERO(r1, a6l, r1, carry); - MP_ADD_CARRY(r2, a6h | a7l, r2, carry, carry); - MP_ADD_CARRY(r3, a7h, r3, carry, carry); - r4 += carry; - MP_ADD_CARRY_ZERO(r1, a6l, r1, carry); - MP_ADD_CARRY(r2, a6h | a7l, r2, carry, carry); - MP_ADD_CARRY(r3, a7h, r3, carry, carry); - r4 += carry; - - /* sum 3 */ - MP_ADD_CARRY_ZERO(r0, a4, r0, carry); - MP_ADD_CARRY(r1, a5l >> 32, r1, carry, carry); - MP_ADD_CARRY(r2, 0, r2, carry, carry); - MP_ADD_CARRY(r3, a7, r3, carry, carry); - r4 += carry; - /* sum 4 */ - MP_ADD_CARRY_ZERO(r0, a4h | a5l, r0, carry); - MP_ADD_CARRY(r1, a5h|(a6h<<32), r1, carry, carry); - MP_ADD_CARRY(r2, a7, r2, carry, carry); - MP_ADD_CARRY(r3, a6h | a4l, r3, carry, carry); - r4 += carry; - /* diff 5 */ - MP_SUB_BORROW(r0, a5h | a6l, r0, 0, carry); - MP_SUB_BORROW(r1, a6h, r1, carry, carry); - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, (a4l>>32)|a5l,r3, carry, carry); - r4 -= carry; - /* diff 6 */ - MP_SUB_BORROW(r0, a6, r0, 0, carry); - MP_SUB_BORROW(r1, a7, r1, carry, carry); - MP_SUB_BORROW(r2, 0, r2, carry, carry); - MP_SUB_BORROW(r3, a4h|(a5h<<32),r3, carry, carry); - r4 -= carry; - /* diff 7 */ - MP_SUB_BORROW(r0, a6h|a7l, r0, 0, carry); - MP_SUB_BORROW(r1, a7h|a4l, r1, carry, carry); - MP_SUB_BORROW(r2, a4h|a5l, r2, carry, carry); - MP_SUB_BORROW(r3, a6l, r3, carry, carry); - r4 -= carry; - /* diff 8 */ - MP_SUB_BORROW(r0, a7, r0, 0, carry); - MP_SUB_BORROW(r1, a4h<<32, r1, carry, carry); - MP_SUB_BORROW(r2, a5, r2, carry, carry); - MP_SUB_BORROW(r3, a6h<<32, r3, carry, carry); - r4 -= carry; - - /* reduce the overflows */ - while (r4 > 0) { - mp_digit r4_long = r4; - mp_digit r4l = (r4_long << 32); - MP_ADD_CARRY_ZERO(r0, r4_long, r0, carry); - MP_ADD_CARRY(r1, -r4l, r1, carry, carry); - MP_ADD_CARRY(r2, MP_DIGIT_MAX, r2, carry, carry); - MP_ADD_CARRY(r3, r4l-r4_long-1,r3, carry, carry); - r4 = carry; - } - - /* reduce the underflows */ - while (r4 < 0) { - mp_digit r4_long = -r4; - mp_digit r4l = (r4_long << 32); - MP_SUB_BORROW(r0, r4_long, r0, 0, carry); - MP_SUB_BORROW(r1, -r4l, r1, carry, carry); - MP_SUB_BORROW(r2, MP_DIGIT_MAX, r2, carry, carry); - MP_SUB_BORROW(r3, r4l-r4_long-1,r3, carry, carry); - r4 = -carry; - } - - if (a != r) { - MP_CHECKOK(s_mp_pad(r,4)); - } - MP_SIGN(r) = MP_ZPOS; - MP_USED(r) = 4; - - MP_DIGIT(r,3) = r3; - MP_DIGIT(r,2) = r2; - MP_DIGIT(r,1) = r1; - MP_DIGIT(r,0) = r0; - - /* final reduction if necessary */ - if ((r3 > 0xFFFFFFFF00000001ULL) || - ((r3 == 0xFFFFFFFF00000001ULL) && - (r2 || (r1 >> 32)|| - (r1 == 0xFFFFFFFFULL && r0 == MP_DIGIT_MAX)))) { - /* very rare, just use mp_sub */ - MP_CHECKOK(mp_sub(r, &meth->irr, r)); - } - - s_mp_clamp(r); -#endif - } - - CLEANUP: - return res; -} - -/* Compute the square of polynomial a, reduce modulo p256. Store the - * result in r. r could be a. Uses optimized modular reduction for p256. - */ -mp_err -ec_GFp_nistp256_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_sqr(a, r)); - MP_CHECKOK(ec_GFp_nistp256_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p256. - * Store the result in r. r could be a or b; a could be b. Uses - * optimized modular reduction for p256. */ -mp_err -ec_GFp_nistp256_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(ec_GFp_nistp256_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Wire in fast field arithmetic and precomputation of base point for - * named curves. */ -mp_err -ec_group_set_gfp256(ECGroup *group, ECCurveName name) -{ - if (name == ECCurve_NIST_P256) { - group->meth->field_mod = &ec_GFp_nistp256_mod; - group->meth->field_mul = &ec_GFp_nistp256_mul; - group->meth->field_sqr = &ec_GFp_nistp256_sqr; - } - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_384.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_384.c deleted file mode 100644 index e40a8f1001760..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_384.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila - * - *********************************************************************** */ - -#include "ecp.h" -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -/* Fast modular reduction for p384 = 2^384 - 2^128 - 2^96 + 2^32 - 1. a can be r. - * Uses algorithm 2.30 from Hankerson, Menezes, Vanstone. Guide to - * Elliptic Curve Cryptography. */ -mp_err -ec_GFp_nistp384_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - int a_bits = mpl_significant_bits(a); - int i; - - /* m1, m2 are statically-allocated mp_int of exactly the size we need */ - mp_int m[10]; - -#ifdef ECL_THIRTY_TWO_BIT - mp_digit s[10][12]; - for (i = 0; i < 10; i++) { - MP_SIGN(&m[i]) = MP_ZPOS; - MP_ALLOC(&m[i]) = 12; - MP_USED(&m[i]) = 12; - MP_DIGITS(&m[i]) = s[i]; - } -#else - mp_digit s[10][6]; - for (i = 0; i < 10; i++) { - MP_SIGN(&m[i]) = MP_ZPOS; - MP_ALLOC(&m[i]) = 6; - MP_USED(&m[i]) = 6; - MP_DIGITS(&m[i]) = s[i]; - } -#endif - -#ifdef ECL_THIRTY_TWO_BIT - /* for polynomials larger than twice the field size or polynomials - * not using all words, use regular reduction */ - if ((a_bits > 768) || (a_bits <= 736)) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { - for (i = 0; i < 12; i++) { - s[0][i] = MP_DIGIT(a, i); - } - s[1][0] = 0; - s[1][1] = 0; - s[1][2] = 0; - s[1][3] = 0; - s[1][4] = MP_DIGIT(a, 21); - s[1][5] = MP_DIGIT(a, 22); - s[1][6] = MP_DIGIT(a, 23); - s[1][7] = 0; - s[1][8] = 0; - s[1][9] = 0; - s[1][10] = 0; - s[1][11] = 0; - for (i = 0; i < 12; i++) { - s[2][i] = MP_DIGIT(a, i+12); - } - s[3][0] = MP_DIGIT(a, 21); - s[3][1] = MP_DIGIT(a, 22); - s[3][2] = MP_DIGIT(a, 23); - for (i = 3; i < 12; i++) { - s[3][i] = MP_DIGIT(a, i+9); - } - s[4][0] = 0; - s[4][1] = MP_DIGIT(a, 23); - s[4][2] = 0; - s[4][3] = MP_DIGIT(a, 20); - for (i = 4; i < 12; i++) { - s[4][i] = MP_DIGIT(a, i+8); - } - s[5][0] = 0; - s[5][1] = 0; - s[5][2] = 0; - s[5][3] = 0; - s[5][4] = MP_DIGIT(a, 20); - s[5][5] = MP_DIGIT(a, 21); - s[5][6] = MP_DIGIT(a, 22); - s[5][7] = MP_DIGIT(a, 23); - s[5][8] = 0; - s[5][9] = 0; - s[5][10] = 0; - s[5][11] = 0; - s[6][0] = MP_DIGIT(a, 20); - s[6][1] = 0; - s[6][2] = 0; - s[6][3] = MP_DIGIT(a, 21); - s[6][4] = MP_DIGIT(a, 22); - s[6][5] = MP_DIGIT(a, 23); - s[6][6] = 0; - s[6][7] = 0; - s[6][8] = 0; - s[6][9] = 0; - s[6][10] = 0; - s[6][11] = 0; - s[7][0] = MP_DIGIT(a, 23); - for (i = 1; i < 12; i++) { - s[7][i] = MP_DIGIT(a, i+11); - } - s[8][0] = 0; - s[8][1] = MP_DIGIT(a, 20); - s[8][2] = MP_DIGIT(a, 21); - s[8][3] = MP_DIGIT(a, 22); - s[8][4] = MP_DIGIT(a, 23); - s[8][5] = 0; - s[8][6] = 0; - s[8][7] = 0; - s[8][8] = 0; - s[8][9] = 0; - s[8][10] = 0; - s[8][11] = 0; - s[9][0] = 0; - s[9][1] = 0; - s[9][2] = 0; - s[9][3] = MP_DIGIT(a, 23); - s[9][4] = MP_DIGIT(a, 23); - s[9][5] = 0; - s[9][6] = 0; - s[9][7] = 0; - s[9][8] = 0; - s[9][9] = 0; - s[9][10] = 0; - s[9][11] = 0; - - MP_CHECKOK(mp_add(&m[0], &m[1], r)); - MP_CHECKOK(mp_add(r, &m[1], r)); - MP_CHECKOK(mp_add(r, &m[2], r)); - MP_CHECKOK(mp_add(r, &m[3], r)); - MP_CHECKOK(mp_add(r, &m[4], r)); - MP_CHECKOK(mp_add(r, &m[5], r)); - MP_CHECKOK(mp_add(r, &m[6], r)); - MP_CHECKOK(mp_sub(r, &m[7], r)); - MP_CHECKOK(mp_sub(r, &m[8], r)); - MP_CHECKOK(mp_submod(r, &m[9], &meth->irr, r)); - s_mp_clamp(r); - } -#else - /* for polynomials larger than twice the field size or polynomials - * not using all words, use regular reduction */ - if ((a_bits > 768) || (a_bits <= 736)) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { - for (i = 0; i < 6; i++) { - s[0][i] = MP_DIGIT(a, i); - } - s[1][0] = 0; - s[1][1] = 0; - s[1][2] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32); - s[1][3] = MP_DIGIT(a, 11) >> 32; - s[1][4] = 0; - s[1][5] = 0; - for (i = 0; i < 6; i++) { - s[2][i] = MP_DIGIT(a, i+6); - } - s[3][0] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32); - s[3][1] = (MP_DIGIT(a, 11) >> 32) | (MP_DIGIT(a, 6) << 32); - for (i = 2; i < 6; i++) { - s[3][i] = (MP_DIGIT(a, i+4) >> 32) | (MP_DIGIT(a, i+5) << 32); - } - s[4][0] = (MP_DIGIT(a, 11) >> 32) << 32; - s[4][1] = MP_DIGIT(a, 10) << 32; - for (i = 2; i < 6; i++) { - s[4][i] = MP_DIGIT(a, i+4); - } - s[5][0] = 0; - s[5][1] = 0; - s[5][2] = MP_DIGIT(a, 10); - s[5][3] = MP_DIGIT(a, 11); - s[5][4] = 0; - s[5][5] = 0; - s[6][0] = (MP_DIGIT(a, 10) << 32) >> 32; - s[6][1] = (MP_DIGIT(a, 10) >> 32) << 32; - s[6][2] = MP_DIGIT(a, 11); - s[6][3] = 0; - s[6][4] = 0; - s[6][5] = 0; - s[7][0] = (MP_DIGIT(a, 11) >> 32) | (MP_DIGIT(a, 6) << 32); - for (i = 1; i < 6; i++) { - s[7][i] = (MP_DIGIT(a, i+5) >> 32) | (MP_DIGIT(a, i+6) << 32); - } - s[8][0] = MP_DIGIT(a, 10) << 32; - s[8][1] = (MP_DIGIT(a, 10) >> 32) | (MP_DIGIT(a, 11) << 32); - s[8][2] = MP_DIGIT(a, 11) >> 32; - s[8][3] = 0; - s[8][4] = 0; - s[8][5] = 0; - s[9][0] = 0; - s[9][1] = (MP_DIGIT(a, 11) >> 32) << 32; - s[9][2] = MP_DIGIT(a, 11) >> 32; - s[9][3] = 0; - s[9][4] = 0; - s[9][5] = 0; - - MP_CHECKOK(mp_add(&m[0], &m[1], r)); - MP_CHECKOK(mp_add(r, &m[1], r)); - MP_CHECKOK(mp_add(r, &m[2], r)); - MP_CHECKOK(mp_add(r, &m[3], r)); - MP_CHECKOK(mp_add(r, &m[4], r)); - MP_CHECKOK(mp_add(r, &m[5], r)); - MP_CHECKOK(mp_add(r, &m[6], r)); - MP_CHECKOK(mp_sub(r, &m[7], r)); - MP_CHECKOK(mp_sub(r, &m[8], r)); - MP_CHECKOK(mp_submod(r, &m[9], &meth->irr, r)); - s_mp_clamp(r); - } -#endif - - CLEANUP: - return res; -} - -/* Compute the square of polynomial a, reduce modulo p384. Store the - * result in r. r could be a. Uses optimized modular reduction for p384. - */ -mp_err -ec_GFp_nistp384_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_sqr(a, r)); - MP_CHECKOK(ec_GFp_nistp384_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p384. - * Store the result in r. r could be a or b; a could be b. Uses - * optimized modular reduction for p384. */ -mp_err -ec_GFp_nistp384_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(ec_GFp_nistp384_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Wire in fast field arithmetic and precomputation of base point for - * named curves. */ -mp_err -ec_group_set_gfp384(ECGroup *group, ECCurveName name) -{ - if (name == ECCurve_NIST_P384) { - group->meth->field_mod = &ec_GFp_nistp384_mod; - group->meth->field_mul = &ec_GFp_nistp384_mul; - group->meth->field_sqr = &ec_GFp_nistp384_sqr; - } - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_521.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_521.c deleted file mode 100644 index 11172dda7a9c6..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_521.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila - * - *********************************************************************** */ - -#include "ecp.h" -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#ifndef _KERNEL -#include -#endif - -#define ECP521_DIGITS ECL_CURVE_DIGITS(521) - -/* Fast modular reduction for p521 = 2^521 - 1. a can be r. Uses - * algorithm 2.31 from Hankerson, Menezes, Vanstone. Guide to - * Elliptic Curve Cryptography. */ -mp_err -ec_GFp_nistp521_mod(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - int a_bits = mpl_significant_bits(a); - unsigned int i; - - /* m1, m2 are statically-allocated mp_int of exactly the size we need */ - mp_int m1; - - mp_digit s1[ECP521_DIGITS] = { 0 }; - - MP_SIGN(&m1) = MP_ZPOS; - MP_ALLOC(&m1) = ECP521_DIGITS; - MP_USED(&m1) = ECP521_DIGITS; - MP_DIGITS(&m1) = s1; - - if (a_bits < 521) { - if (a==r) return MP_OKAY; - return mp_copy(a, r); - } - /* for polynomials larger than twice the field size or polynomials - * not using all words, use regular reduction */ - if (a_bits > (521*2)) { - MP_CHECKOK(mp_mod(a, &meth->irr, r)); - } else { -#define FIRST_DIGIT (ECP521_DIGITS-1) - for (i = FIRST_DIGIT; i < MP_USED(a)-1; i++) { - s1[i-FIRST_DIGIT] = (MP_DIGIT(a, i) >> 9) - | (MP_DIGIT(a, 1+i) << (MP_DIGIT_BIT-9)); - } - s1[i-FIRST_DIGIT] = MP_DIGIT(a, i) >> 9; - - if ( a != r ) { - MP_CHECKOK(s_mp_pad(r,ECP521_DIGITS)); - for (i = 0; i < ECP521_DIGITS; i++) { - MP_DIGIT(r,i) = MP_DIGIT(a, i); - } - } - MP_USED(r) = ECP521_DIGITS; - MP_DIGIT(r,FIRST_DIGIT) &= 0x1FF; - - MP_CHECKOK(s_mp_add(r, &m1)); - if (MP_DIGIT(r, FIRST_DIGIT) & 0x200) { - MP_CHECKOK(s_mp_add_d(r,1)); - MP_DIGIT(r,FIRST_DIGIT) &= 0x1FF; - } - s_mp_clamp(r); - } - - CLEANUP: - return res; -} - -/* Compute the square of polynomial a, reduce modulo p521. Store the - * result in r. r could be a. Uses optimized modular reduction for p521. - */ -mp_err -ec_GFp_nistp521_sqr(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_sqr(a, r)); - MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p521. - * Store the result in r. r could be a or b; a could be b. Uses - * optimized modular reduction for p521. */ -mp_err -ec_GFp_nistp521_mul(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth)); - CLEANUP: - return res; -} - -/* Divides two field elements. If a is NULL, then returns the inverse of - * b. */ -mp_err -ec_GFp_nistp521_div(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - mp_int t; - - /* If a is NULL, then return the inverse of b, otherwise return a/b. */ - if (a == NULL) { - return mp_invmod(b, &meth->irr, r); - } else { - /* MPI doesn't support divmod, so we implement it using invmod and - * mulmod. */ - MP_CHECKOK(mp_init(&t, FLAG(b))); - MP_CHECKOK(mp_invmod(b, &meth->irr, &t)); - MP_CHECKOK(mp_mul(a, &t, r)); - MP_CHECKOK(ec_GFp_nistp521_mod(r, r, meth)); - CLEANUP: - mp_clear(&t); - return res; - } -} - -/* Wire in fast field arithmetic and precomputation of base point for - * named curves. */ -mp_err -ec_group_set_gfp521(ECGroup *group, ECCurveName name) -{ - if (name == ECCurve_NIST_P521) { - group->meth->field_mod = &ec_GFp_nistp521_mod; - group->meth->field_mul = &ec_GFp_nistp521_mul; - group->meth->field_sqr = &ec_GFp_nistp521_sqr; - group->meth->field_div = &ec_GFp_nistp521_div; - } - return MP_OKAY; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_aff.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_aff.c deleted file mode 100644 index c9d9232717191..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_aff.c +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * Bodo Moeller , - * Nils Larsch , and - * Lenka Fibikova , the OpenSSL Project - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "ecp.h" -#include "mplogic.h" -#ifndef _KERNEL -#include -#endif - -/* Checks if point P(px, py) is at infinity. Uses affine coordinates. */ -mp_err -ec_GFp_pt_is_inf_aff(const mp_int *px, const mp_int *py) -{ - - if ((mp_cmp_z(px) == 0) && (mp_cmp_z(py) == 0)) { - return MP_YES; - } else { - return MP_NO; - } - -} - -/* Sets P(px, py) to be the point at infinity. Uses affine coordinates. */ -mp_err -ec_GFp_pt_set_inf_aff(mp_int *px, mp_int *py) -{ - mp_zero(px); - mp_zero(py); - return MP_OKAY; -} - -/* Computes R = P + Q based on IEEE P1363 A.10.1. Elliptic curve points P, - * Q, and R can all be identical. Uses affine coordinates. Assumes input - * is already field-encoded using field_enc, and returns output that is - * still field-encoded. */ -mp_err -ec_GFp_pt_add_aff(const mp_int *px, const mp_int *py, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int lambda, temp, tempx, tempy; - - MP_DIGITS(&lambda) = 0; - MP_DIGITS(&temp) = 0; - MP_DIGITS(&tempx) = 0; - MP_DIGITS(&tempy) = 0; - MP_CHECKOK(mp_init(&lambda, FLAG(px))); - MP_CHECKOK(mp_init(&temp, FLAG(px))); - MP_CHECKOK(mp_init(&tempx, FLAG(px))); - MP_CHECKOK(mp_init(&tempy, FLAG(px))); - /* if P = inf, then R = Q */ - if (ec_GFp_pt_is_inf_aff(px, py) == 0) { - MP_CHECKOK(mp_copy(qx, rx)); - MP_CHECKOK(mp_copy(qy, ry)); - res = MP_OKAY; - goto CLEANUP; - } - /* if Q = inf, then R = P */ - if (ec_GFp_pt_is_inf_aff(qx, qy) == 0) { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - res = MP_OKAY; - goto CLEANUP; - } - /* if px != qx, then lambda = (py-qy) / (px-qx) */ - if (mp_cmp(px, qx) != 0) { - MP_CHECKOK(group->meth->field_sub(py, qy, &tempy, group->meth)); - MP_CHECKOK(group->meth->field_sub(px, qx, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_div(&tempy, &tempx, &lambda, group->meth)); - } else { - /* if py != qy or qy = 0, then R = inf */ - if (((mp_cmp(py, qy) != 0)) || (mp_cmp_z(qy) == 0)) { - mp_zero(rx); - mp_zero(ry); - res = MP_OKAY; - goto CLEANUP; - } - /* lambda = (3qx^2+a) / (2qy) */ - MP_CHECKOK(group->meth->field_sqr(qx, &tempx, group->meth)); - MP_CHECKOK(mp_set_int(&temp, 3)); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(&temp, &temp, group->meth)); - } - MP_CHECKOK(group->meth-> - field_mul(&tempx, &temp, &tempx, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&tempx, &group->curvea, &tempx, group->meth)); - MP_CHECKOK(mp_set_int(&temp, 2)); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(&temp, &temp, group->meth)); - } - MP_CHECKOK(group->meth->field_mul(qy, &temp, &tempy, group->meth)); - MP_CHECKOK(group->meth-> - field_div(&tempx, &tempy, &lambda, group->meth)); - } - /* rx = lambda^2 - px - qx */ - MP_CHECKOK(group->meth->field_sqr(&lambda, &tempx, group->meth)); - MP_CHECKOK(group->meth->field_sub(&tempx, px, &tempx, group->meth)); - MP_CHECKOK(group->meth->field_sub(&tempx, qx, &tempx, group->meth)); - /* ry = (x1-x2) * lambda - y1 */ - MP_CHECKOK(group->meth->field_sub(qx, &tempx, &tempy, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(&tempy, &lambda, &tempy, group->meth)); - MP_CHECKOK(group->meth->field_sub(&tempy, qy, &tempy, group->meth)); - MP_CHECKOK(mp_copy(&tempx, rx)); - MP_CHECKOK(mp_copy(&tempy, ry)); - - CLEANUP: - mp_clear(&lambda); - mp_clear(&temp); - mp_clear(&tempx); - mp_clear(&tempy); - return res; -} - -/* Computes R = P - Q. Elliptic curve points P, Q, and R can all be - * identical. Uses affine coordinates. Assumes input is already - * field-encoded using field_enc, and returns output that is still - * field-encoded. */ -mp_err -ec_GFp_pt_sub_aff(const mp_int *px, const mp_int *py, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, - const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int nqy; - - MP_DIGITS(&nqy) = 0; - MP_CHECKOK(mp_init(&nqy, FLAG(px))); - /* nqy = -qy */ - MP_CHECKOK(group->meth->field_neg(qy, &nqy, group->meth)); - res = group->point_add(px, py, qx, &nqy, rx, ry, group); - CLEANUP: - mp_clear(&nqy); - return res; -} - -/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses - * affine coordinates. Assumes input is already field-encoded using - * field_enc, and returns output that is still field-encoded. */ -mp_err -ec_GFp_pt_dbl_aff(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, const ECGroup *group) -{ - return ec_GFp_pt_add_aff(px, py, px, py, rx, ry, group); -} - -/* by default, this routine is unused and thus doesn't need to be compiled */ -#ifdef ECL_ENABLE_GFP_PT_MUL_AFF -/* Computes R = nP based on IEEE P1363 A.10.3. Elliptic curve points P and - * R can be identical. Uses affine coordinates. Assumes input is already - * field-encoded using field_enc, and returns output that is still - * field-encoded. */ -mp_err -ec_GFp_pt_mul_aff(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int k, k3, qx, qy, sx, sy; - int b1, b3, i, l; - - MP_DIGITS(&k) = 0; - MP_DIGITS(&k3) = 0; - MP_DIGITS(&qx) = 0; - MP_DIGITS(&qy) = 0; - MP_DIGITS(&sx) = 0; - MP_DIGITS(&sy) = 0; - MP_CHECKOK(mp_init(&k)); - MP_CHECKOK(mp_init(&k3)); - MP_CHECKOK(mp_init(&qx)); - MP_CHECKOK(mp_init(&qy)); - MP_CHECKOK(mp_init(&sx)); - MP_CHECKOK(mp_init(&sy)); - - /* if n = 0 then r = inf */ - if (mp_cmp_z(n) == 0) { - mp_zero(rx); - mp_zero(ry); - res = MP_OKAY; - goto CLEANUP; - } - /* Q = P, k = n */ - MP_CHECKOK(mp_copy(px, &qx)); - MP_CHECKOK(mp_copy(py, &qy)); - MP_CHECKOK(mp_copy(n, &k)); - /* if n < 0 then Q = -Q, k = -k */ - if (mp_cmp_z(n) < 0) { - MP_CHECKOK(group->meth->field_neg(&qy, &qy, group->meth)); - MP_CHECKOK(mp_neg(&k, &k)); - } -#ifdef ECL_DEBUG /* basic double and add method */ - l = mpl_significant_bits(&k) - 1; - MP_CHECKOK(mp_copy(&qx, &sx)); - MP_CHECKOK(mp_copy(&qy, &sy)); - for (i = l - 1; i >= 0; i--) { - /* S = 2S */ - MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group)); - /* if k_i = 1, then S = S + Q */ - if (mpl_get_bit(&k, i) != 0) { - MP_CHECKOK(group-> - point_add(&sx, &sy, &qx, &qy, &sx, &sy, group)); - } - } -#else /* double and add/subtract method from - * standard */ - /* k3 = 3 * k */ - MP_CHECKOK(mp_set_int(&k3, 3)); - MP_CHECKOK(mp_mul(&k, &k3, &k3)); - /* S = Q */ - MP_CHECKOK(mp_copy(&qx, &sx)); - MP_CHECKOK(mp_copy(&qy, &sy)); - /* l = index of high order bit in binary representation of 3*k */ - l = mpl_significant_bits(&k3) - 1; - /* for i = l-1 downto 1 */ - for (i = l - 1; i >= 1; i--) { - /* S = 2S */ - MP_CHECKOK(group->point_dbl(&sx, &sy, &sx, &sy, group)); - b3 = MP_GET_BIT(&k3, i); - b1 = MP_GET_BIT(&k, i); - /* if k3_i = 1 and k_i = 0, then S = S + Q */ - if ((b3 == 1) && (b1 == 0)) { - MP_CHECKOK(group-> - point_add(&sx, &sy, &qx, &qy, &sx, &sy, group)); - /* if k3_i = 0 and k_i = 1, then S = S - Q */ - } else if ((b3 == 0) && (b1 == 1)) { - MP_CHECKOK(group-> - point_sub(&sx, &sy, &qx, &qy, &sx, &sy, group)); - } - } -#endif - /* output S */ - MP_CHECKOK(mp_copy(&sx, rx)); - MP_CHECKOK(mp_copy(&sy, ry)); - - CLEANUP: - mp_clear(&k); - mp_clear(&k3); - mp_clear(&qx); - mp_clear(&qy); - mp_clear(&sx); - mp_clear(&sy); - return res; -} -#endif - -/* Validates a point on a GFp curve. */ -mp_err -ec_GFp_validate_point(const mp_int *px, const mp_int *py, const ECGroup *group) -{ - mp_err res = MP_NO; - mp_int accl, accr, tmp, pxt, pyt; - - MP_DIGITS(&accl) = 0; - MP_DIGITS(&accr) = 0; - MP_DIGITS(&tmp) = 0; - MP_DIGITS(&pxt) = 0; - MP_DIGITS(&pyt) = 0; - MP_CHECKOK(mp_init(&accl, FLAG(px))); - MP_CHECKOK(mp_init(&accr, FLAG(px))); - MP_CHECKOK(mp_init(&tmp, FLAG(px))); - MP_CHECKOK(mp_init(&pxt, FLAG(px))); - MP_CHECKOK(mp_init(&pyt, FLAG(px))); - - /* 1: Verify that publicValue is not the point at infinity */ - if (ec_GFp_pt_is_inf_aff(px, py) == MP_YES) { - res = MP_NO; - goto CLEANUP; - } - /* 2: Verify that the coordinates of publicValue are elements - * of the field. - */ - if ((MP_SIGN(px) == MP_NEG) || (mp_cmp(px, &group->meth->irr) >= 0) || - (MP_SIGN(py) == MP_NEG) || (mp_cmp(py, &group->meth->irr) >= 0)) { - res = MP_NO; - goto CLEANUP; - } - /* 3: Verify that publicValue is on the curve. */ - if (group->meth->field_enc) { - group->meth->field_enc(px, &pxt, group->meth); - group->meth->field_enc(py, &pyt, group->meth); - } else { - mp_copy(px, &pxt); - mp_copy(py, &pyt); - } - /* left-hand side: y^2 */ - MP_CHECKOK( group->meth->field_sqr(&pyt, &accl, group->meth) ); - /* right-hand side: x^3 + a*x + b */ - MP_CHECKOK( group->meth->field_sqr(&pxt, &tmp, group->meth) ); - MP_CHECKOK( group->meth->field_mul(&pxt, &tmp, &accr, group->meth) ); - MP_CHECKOK( group->meth->field_mul(&group->curvea, &pxt, &tmp, group->meth) ); - MP_CHECKOK( group->meth->field_add(&tmp, &accr, &accr, group->meth) ); - MP_CHECKOK( group->meth->field_add(&accr, &group->curveb, &accr, group->meth) ); - /* check LHS - RHS == 0 */ - MP_CHECKOK( group->meth->field_sub(&accl, &accr, &accr, group->meth) ); - if (mp_cmp_z(&accr) != 0) { - res = MP_NO; - goto CLEANUP; - } - /* 4: Verify that the order of the curve times the publicValue - * is the point at infinity. - */ - /* timing mitigation is not supported */ - MP_CHECKOK( ECPoint_mul(group, &group->order, px, py, &pxt, &pyt, /*timing*/ 0) ); - if (ec_GFp_pt_is_inf_aff(&pxt, &pyt) != MP_YES) { - res = MP_NO; - goto CLEANUP; - } - - res = MP_YES; - -CLEANUP: - mp_clear(&accl); - mp_clear(&accr); - mp_clear(&tmp); - mp_clear(&pxt); - mp_clear(&pyt); - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c deleted file mode 100644 index 9e1bdf20f67db..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c +++ /dev/null @@ -1,564 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang-Shantz , - * Stephen Fung , and - * Douglas Stebila , Sun Microsystems Laboratories. - * Bodo Moeller , - * Nils Larsch , and - * Lenka Fibikova , the OpenSSL Project - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "ecp.h" -#include "mplogic.h" -#ifndef _KERNEL -#include -#endif -#ifdef ECL_DEBUG -#include -#endif - -/* Converts a point P(px, py) from affine coordinates to Jacobian - * projective coordinates R(rx, ry, rz). Assumes input is already - * field-encoded using field_enc, and returns output that is still - * field-encoded. */ -mp_err -ec_GFp_pt_aff2jac(const mp_int *px, const mp_int *py, mp_int *rx, - mp_int *ry, mp_int *rz, const ECGroup *group) -{ - mp_err res = MP_OKAY; - - if (ec_GFp_pt_is_inf_aff(px, py) == MP_YES) { - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz)); - } else { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - MP_CHECKOK(mp_set_int(rz, 1)); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth->field_enc(rz, rz, group->meth)); - } - } - CLEANUP: - return res; -} - -/* Converts a point P(px, py, pz) from Jacobian projective coordinates to - * affine coordinates R(rx, ry). P and R can share x and y coordinates. - * Assumes input is already field-encoded using field_enc, and returns - * output that is still field-encoded. */ -mp_err -ec_GFp_pt_jac2aff(const mp_int *px, const mp_int *py, const mp_int *pz, - mp_int *rx, mp_int *ry, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int z1, z2, z3; - - MP_DIGITS(&z1) = 0; - MP_DIGITS(&z2) = 0; - MP_DIGITS(&z3) = 0; - MP_CHECKOK(mp_init(&z1, FLAG(px))); - MP_CHECKOK(mp_init(&z2, FLAG(px))); - MP_CHECKOK(mp_init(&z3, FLAG(px))); - - /* if point at infinity, then set point at infinity and exit */ - if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) { - MP_CHECKOK(ec_GFp_pt_set_inf_aff(rx, ry)); - goto CLEANUP; - } - - /* transform (px, py, pz) into (px / pz^2, py / pz^3) */ - if (mp_cmp_d(pz, 1) == 0) { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - } else { - MP_CHECKOK(group->meth->field_div(NULL, pz, &z1, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&z1, &z2, group->meth)); - MP_CHECKOK(group->meth->field_mul(&z1, &z2, &z3, group->meth)); - MP_CHECKOK(group->meth->field_mul(px, &z2, rx, group->meth)); - MP_CHECKOK(group->meth->field_mul(py, &z3, ry, group->meth)); - } - - CLEANUP: - mp_clear(&z1); - mp_clear(&z2); - mp_clear(&z3); - return res; -} - -/* Checks if point P(px, py, pz) is at infinity. Uses Jacobian - * coordinates. */ -mp_err -ec_GFp_pt_is_inf_jac(const mp_int *px, const mp_int *py, const mp_int *pz) -{ - return mp_cmp_z(pz); -} - -/* Sets P(px, py, pz) to be the point at infinity. Uses Jacobian - * coordinates. */ -mp_err -ec_GFp_pt_set_inf_jac(mp_int *px, mp_int *py, mp_int *pz) -{ - mp_zero(pz); - return MP_OKAY; -} - -/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is - * (qx, qy, 1). Elliptic curve points P, Q, and R can all be identical. - * Uses mixed Jacobian-affine coordinates. Assumes input is already - * field-encoded using field_enc, and returns output that is still - * field-encoded. Uses equation (2) from Brown, Hankerson, Lopez, and - * Menezes. Software Implementation of the NIST Elliptic Curves Over Prime - * Fields. */ -mp_err -ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, const mp_int *pz, - const mp_int *qx, const mp_int *qy, mp_int *rx, - mp_int *ry, mp_int *rz, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int A, B, C, D, C2, C3; - - MP_DIGITS(&A) = 0; - MP_DIGITS(&B) = 0; - MP_DIGITS(&C) = 0; - MP_DIGITS(&D) = 0; - MP_DIGITS(&C2) = 0; - MP_DIGITS(&C3) = 0; - MP_CHECKOK(mp_init(&A, FLAG(px))); - MP_CHECKOK(mp_init(&B, FLAG(px))); - MP_CHECKOK(mp_init(&C, FLAG(px))); - MP_CHECKOK(mp_init(&D, FLAG(px))); - MP_CHECKOK(mp_init(&C2, FLAG(px))); - MP_CHECKOK(mp_init(&C3, FLAG(px))); - - /* If either P or Q is the point at infinity, then return the other - * point */ - if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) { - MP_CHECKOK(ec_GFp_pt_aff2jac(qx, qy, rx, ry, rz, group)); - goto CLEANUP; - } - if (ec_GFp_pt_is_inf_aff(qx, qy) == MP_YES) { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - MP_CHECKOK(mp_copy(pz, rz)); - goto CLEANUP; - } - - /* A = qx * pz^2, B = qy * pz^3 */ - MP_CHECKOK(group->meth->field_sqr(pz, &A, group->meth)); - MP_CHECKOK(group->meth->field_mul(&A, pz, &B, group->meth)); - MP_CHECKOK(group->meth->field_mul(&A, qx, &A, group->meth)); - MP_CHECKOK(group->meth->field_mul(&B, qy, &B, group->meth)); - - /* - * Additional checks for point equality and point at infinity - */ - if (mp_cmp(px, &A) == 0 && mp_cmp(py, &B) == 0) { - /* POINT_DOUBLE(P) */ - MP_CHECKOK(ec_GFp_pt_dbl_jac(px, py, pz, rx, ry, rz, group)); - goto CLEANUP; - } - - /* C = A - px, D = B - py */ - MP_CHECKOK(group->meth->field_sub(&A, px, &C, group->meth)); - MP_CHECKOK(group->meth->field_sub(&B, py, &D, group->meth)); - - /* C2 = C^2, C3 = C^3 */ - MP_CHECKOK(group->meth->field_sqr(&C, &C2, group->meth)); - MP_CHECKOK(group->meth->field_mul(&C, &C2, &C3, group->meth)); - - /* rz = pz * C */ - MP_CHECKOK(group->meth->field_mul(pz, &C, rz, group->meth)); - - /* C = px * C^2 */ - MP_CHECKOK(group->meth->field_mul(px, &C2, &C, group->meth)); - /* A = D^2 */ - MP_CHECKOK(group->meth->field_sqr(&D, &A, group->meth)); - - /* rx = D^2 - (C^3 + 2 * (px * C^2)) */ - MP_CHECKOK(group->meth->field_add(&C, &C, rx, group->meth)); - MP_CHECKOK(group->meth->field_add(&C3, rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_sub(&A, rx, rx, group->meth)); - - /* C3 = py * C^3 */ - MP_CHECKOK(group->meth->field_mul(py, &C3, &C3, group->meth)); - - /* ry = D * (px * C^2 - rx) - py * C^3 */ - MP_CHECKOK(group->meth->field_sub(&C, rx, ry, group->meth)); - MP_CHECKOK(group->meth->field_mul(&D, ry, ry, group->meth)); - MP_CHECKOK(group->meth->field_sub(ry, &C3, ry, group->meth)); - - CLEANUP: - mp_clear(&A); - mp_clear(&B); - mp_clear(&C); - mp_clear(&D); - mp_clear(&C2); - mp_clear(&C3); - return res; -} - -/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses - * Jacobian coordinates. - * - * Assumes input is already field-encoded using field_enc, and returns - * output that is still field-encoded. - * - * This routine implements Point Doubling in the Jacobian Projective - * space as described in the paper "Efficient elliptic curve exponentiation - * using mixed coordinates", by H. Cohen, A Miyaji, T. Ono. - */ -mp_err -ec_GFp_pt_dbl_jac(const mp_int *px, const mp_int *py, const mp_int *pz, - mp_int *rx, mp_int *ry, mp_int *rz, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int t0, t1, M, S; - - MP_DIGITS(&t0) = 0; - MP_DIGITS(&t1) = 0; - MP_DIGITS(&M) = 0; - MP_DIGITS(&S) = 0; - MP_CHECKOK(mp_init(&t0, FLAG(px))); - MP_CHECKOK(mp_init(&t1, FLAG(px))); - MP_CHECKOK(mp_init(&M, FLAG(px))); - MP_CHECKOK(mp_init(&S, FLAG(px))); - - if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) { - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz)); - goto CLEANUP; - } - - if (mp_cmp_d(pz, 1) == 0) { - /* M = 3 * px^2 + a */ - MP_CHECKOK(group->meth->field_sqr(px, &t0, group->meth)); - MP_CHECKOK(group->meth->field_add(&t0, &t0, &M, group->meth)); - MP_CHECKOK(group->meth->field_add(&t0, &M, &t0, group->meth)); - MP_CHECKOK(group->meth-> - field_add(&t0, &group->curvea, &M, group->meth)); - } else if (mp_cmp_int(&group->curvea, -3, FLAG(px)) == 0) { - /* M = 3 * (px + pz^2) * (px - pz^2) */ - MP_CHECKOK(group->meth->field_sqr(pz, &M, group->meth)); - MP_CHECKOK(group->meth->field_add(px, &M, &t0, group->meth)); - MP_CHECKOK(group->meth->field_sub(px, &M, &t1, group->meth)); - MP_CHECKOK(group->meth->field_mul(&t0, &t1, &M, group->meth)); - MP_CHECKOK(group->meth->field_add(&M, &M, &t0, group->meth)); - MP_CHECKOK(group->meth->field_add(&t0, &M, &M, group->meth)); - } else { - /* M = 3 * (px^2) + a * (pz^4) */ - MP_CHECKOK(group->meth->field_sqr(px, &t0, group->meth)); - MP_CHECKOK(group->meth->field_add(&t0, &t0, &M, group->meth)); - MP_CHECKOK(group->meth->field_add(&t0, &M, &t0, group->meth)); - MP_CHECKOK(group->meth->field_sqr(pz, &M, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&M, &M, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(&M, &group->curvea, &M, group->meth)); - MP_CHECKOK(group->meth->field_add(&M, &t0, &M, group->meth)); - } - - /* rz = 2 * py * pz */ - /* t0 = 4 * py^2 */ - if (mp_cmp_d(pz, 1) == 0) { - MP_CHECKOK(group->meth->field_add(py, py, rz, group->meth)); - MP_CHECKOK(group->meth->field_sqr(rz, &t0, group->meth)); - } else { - MP_CHECKOK(group->meth->field_add(py, py, &t0, group->meth)); - MP_CHECKOK(group->meth->field_mul(&t0, pz, rz, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&t0, &t0, group->meth)); - } - - /* S = 4 * px * py^2 = px * (2 * py)^2 */ - MP_CHECKOK(group->meth->field_mul(px, &t0, &S, group->meth)); - - /* rx = M^2 - 2 * S */ - MP_CHECKOK(group->meth->field_add(&S, &S, &t1, group->meth)); - MP_CHECKOK(group->meth->field_sqr(&M, rx, group->meth)); - MP_CHECKOK(group->meth->field_sub(rx, &t1, rx, group->meth)); - - /* ry = M * (S - rx) - 8 * py^4 */ - MP_CHECKOK(group->meth->field_sqr(&t0, &t1, group->meth)); - if (mp_isodd(&t1)) { - MP_CHECKOK(mp_add(&t1, &group->meth->irr, &t1)); - } - MP_CHECKOK(mp_div_2(&t1, &t1)); - MP_CHECKOK(group->meth->field_sub(&S, rx, &S, group->meth)); - MP_CHECKOK(group->meth->field_mul(&M, &S, &M, group->meth)); - MP_CHECKOK(group->meth->field_sub(&M, &t1, ry, group->meth)); - - CLEANUP: - mp_clear(&t0); - mp_clear(&t1); - mp_clear(&M); - mp_clear(&S); - return res; -} - -/* by default, this routine is unused and thus doesn't need to be compiled */ -#ifdef ECL_ENABLE_GFP_PT_MUL_JAC -/* Computes R = nP where R is (rx, ry) and P is (px, py). The parameters - * a, b and p are the elliptic curve coefficients and the prime that - * determines the field GFp. Elliptic curve points P and R can be - * identical. Uses mixed Jacobian-affine coordinates. Assumes input is - * already field-encoded using field_enc, and returns output that is still - * field-encoded. Uses 4-bit window method. */ -mp_err -ec_GFp_pt_mul_jac(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int precomp[16][2], rz; - int i, ni, d; - - MP_DIGITS(&rz) = 0; - for (i = 0; i < 16; i++) { - MP_DIGITS(&precomp[i][0]) = 0; - MP_DIGITS(&precomp[i][1]) = 0; - } - - ARGCHK(group != NULL, MP_BADARG); - ARGCHK((n != NULL) && (px != NULL) && (py != NULL), MP_BADARG); - - /* initialize precomputation table */ - for (i = 0; i < 16; i++) { - MP_CHECKOK(mp_init(&precomp[i][0])); - MP_CHECKOK(mp_init(&precomp[i][1])); - } - - /* fill precomputation table */ - mp_zero(&precomp[0][0]); - mp_zero(&precomp[0][1]); - MP_CHECKOK(mp_copy(px, &precomp[1][0])); - MP_CHECKOK(mp_copy(py, &precomp[1][1])); - for (i = 2; i < 16; i++) { - MP_CHECKOK(group-> - point_add(&precomp[1][0], &precomp[1][1], - &precomp[i - 1][0], &precomp[i - 1][1], - &precomp[i][0], &precomp[i][1], group)); - } - - d = (mpl_significant_bits(n) + 3) / 4; - - /* R = inf */ - MP_CHECKOK(mp_init(&rz)); - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz)); - - for (i = d - 1; i >= 0; i--) { - /* compute window ni */ - ni = MP_GET_BIT(n, 4 * i + 3); - ni <<= 1; - ni |= MP_GET_BIT(n, 4 * i + 2); - ni <<= 1; - ni |= MP_GET_BIT(n, 4 * i + 1); - ni <<= 1; - ni |= MP_GET_BIT(n, 4 * i); - /* R = 2^4 * R */ - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - /* R = R + (ni * P) */ - MP_CHECKOK(ec_GFp_pt_add_jac_aff - (rx, ry, &rz, &precomp[ni][0], &precomp[ni][1], rx, ry, - &rz, group)); - } - - /* convert result S to affine coordinates */ - MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group)); - - CLEANUP: - mp_clear(&rz); - for (i = 0; i < 16; i++) { - mp_clear(&precomp[i][0]); - mp_clear(&precomp[i][1]); - } - return res; -} -#endif - -/* Elliptic curve scalar-point multiplication. Computes R(x, y) = k1 * G + - * k2 * P(x, y), where G is the generator (base point) of the group of - * points on the elliptic curve. Allows k1 = NULL or { k2, P } = NULL. - * Uses mixed Jacobian-affine coordinates. Input and output values are - * assumed to be NOT field-encoded. Uses algorithm 15 (simultaneous - * multiple point multiplication) from Brown, Hankerson, Lopez, Menezes. - * Software Implementation of the NIST Elliptic Curves over Prime Fields. */ -mp_err -ec_GFp_pts_mul_jac(const mp_int *k1, const mp_int *k2, const mp_int *px, - const mp_int *py, mp_int *rx, mp_int *ry, - const ECGroup *group, int timing) -{ - mp_err res = MP_OKAY; - mp_int precomp[4][4][2]; - mp_int rz; - const mp_int *a, *b; - int i, j; - int ai, bi, d; - - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - MP_DIGITS(&precomp[i][j][0]) = 0; - MP_DIGITS(&precomp[i][j][1]) = 0; - } - } - MP_DIGITS(&rz) = 0; - - ARGCHK(group != NULL, MP_BADARG); - ARGCHK(!((k1 == NULL) - && ((k2 == NULL) || (px == NULL) - || (py == NULL))), MP_BADARG); - - /* if some arguments are not defined used ECPoint_mul */ - if (k1 == NULL) { - return ECPoint_mul(group, k2, px, py, rx, ry, timing); - } else if ((k2 == NULL) || (px == NULL) || (py == NULL)) { - return ECPoint_mul(group, k1, NULL, NULL, rx, ry, timing); - } - - /* initialize precomputation table */ - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - MP_CHECKOK(mp_init(&precomp[i][j][0], FLAG(k1))); - MP_CHECKOK(mp_init(&precomp[i][j][1], FLAG(k1))); - } - } - - /* fill precomputation table */ - /* assign {k1, k2} = {a, b} such that len(a) >= len(b) */ - if (mpl_significant_bits(k1) < mpl_significant_bits(k2)) { - a = k2; - b = k1; - if (group->meth->field_enc) { - MP_CHECKOK(group->meth-> - field_enc(px, &precomp[1][0][0], group->meth)); - MP_CHECKOK(group->meth-> - field_enc(py, &precomp[1][0][1], group->meth)); - } else { - MP_CHECKOK(mp_copy(px, &precomp[1][0][0])); - MP_CHECKOK(mp_copy(py, &precomp[1][0][1])); - } - MP_CHECKOK(mp_copy(&group->genx, &precomp[0][1][0])); - MP_CHECKOK(mp_copy(&group->geny, &precomp[0][1][1])); - } else { - a = k1; - b = k2; - MP_CHECKOK(mp_copy(&group->genx, &precomp[1][0][0])); - MP_CHECKOK(mp_copy(&group->geny, &precomp[1][0][1])); - if (group->meth->field_enc) { - MP_CHECKOK(group->meth-> - field_enc(px, &precomp[0][1][0], group->meth)); - MP_CHECKOK(group->meth-> - field_enc(py, &precomp[0][1][1], group->meth)); - } else { - MP_CHECKOK(mp_copy(px, &precomp[0][1][0])); - MP_CHECKOK(mp_copy(py, &precomp[0][1][1])); - } - } - /* precompute [*][0][*] */ - mp_zero(&precomp[0][0][0]); - mp_zero(&precomp[0][0][1]); - MP_CHECKOK(group-> - point_dbl(&precomp[1][0][0], &precomp[1][0][1], - &precomp[2][0][0], &precomp[2][0][1], group)); - MP_CHECKOK(group-> - point_add(&precomp[1][0][0], &precomp[1][0][1], - &precomp[2][0][0], &precomp[2][0][1], - &precomp[3][0][0], &precomp[3][0][1], group)); - /* precompute [*][1][*] */ - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][1][0], &precomp[0][1][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][1][0], &precomp[i][1][1], group)); - } - /* precompute [*][2][*] */ - MP_CHECKOK(group-> - point_dbl(&precomp[0][1][0], &precomp[0][1][1], - &precomp[0][2][0], &precomp[0][2][1], group)); - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][2][0], &precomp[0][2][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][2][0], &precomp[i][2][1], group)); - } - /* precompute [*][3][*] */ - MP_CHECKOK(group-> - point_add(&precomp[0][1][0], &precomp[0][1][1], - &precomp[0][2][0], &precomp[0][2][1], - &precomp[0][3][0], &precomp[0][3][1], group)); - for (i = 1; i < 4; i++) { - MP_CHECKOK(group-> - point_add(&precomp[0][3][0], &precomp[0][3][1], - &precomp[i][0][0], &precomp[i][0][1], - &precomp[i][3][0], &precomp[i][3][1], group)); - } - - d = (mpl_significant_bits(a) + 1) / 2; - - /* R = inf */ - MP_CHECKOK(mp_init(&rz, FLAG(k1))); - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz)); - - for (i = d - 1; i >= 0; i--) { - ai = MP_GET_BIT(a, 2 * i + 1); - ai <<= 1; - ai |= MP_GET_BIT(a, 2 * i); - bi = MP_GET_BIT(b, 2 * i + 1); - bi <<= 1; - bi |= MP_GET_BIT(b, 2 * i); - /* R = 2^2 * R */ - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - MP_CHECKOK(ec_GFp_pt_dbl_jac(rx, ry, &rz, rx, ry, &rz, group)); - /* R = R + (ai * A + bi * B) */ - MP_CHECKOK(ec_GFp_pt_add_jac_aff - (rx, ry, &rz, &precomp[ai][bi][0], &precomp[ai][bi][1], - rx, ry, &rz, group)); - } - - MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group)); - - if (group->meth->field_dec) { - MP_CHECKOK(group->meth->field_dec(rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_dec(ry, ry, group->meth)); - } - - CLEANUP: - mp_clear(&rz); - for (i = 0; i < 4; i++) { - for (j = 0; j < 4; j++) { - mp_clear(&precomp[i][j][0]); - mp_clear(&precomp[i][j][1]); - } - } - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c deleted file mode 100644 index c5cdef9bf4ada..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library for prime field curves. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stephen Fung , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: May 2017 - *********************************************************************** */ - -#include "ecp.h" -#include "ecl-priv.h" -#include "mplogic.h" -#ifndef _KERNEL -#include -#endif - -#define MAX_SCRATCH 6 - -/* Computes R = 2P. Elliptic curve points P and R can be identical. Uses - * Modified Jacobian coordinates. - * - * Assumes input is already field-encoded using field_enc, and returns - * output that is still field-encoded. - * - */ -mp_err -ec_GFp_pt_dbl_jm(const mp_int *px, const mp_int *py, const mp_int *pz, - const mp_int *paz4, mp_int *rx, mp_int *ry, mp_int *rz, - mp_int *raz4, mp_int scratch[], const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int *t0, *t1, *M, *S; - - t0 = &scratch[0]; - t1 = &scratch[1]; - M = &scratch[2]; - S = &scratch[3]; - -#if MAX_SCRATCH < 4 -#error "Scratch array defined too small " -#endif - - /* Check for point at infinity */ - if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) { - /* Set r = pt at infinity by setting rz = 0 */ - - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, rz)); - goto CLEANUP; - } - - /* M = 3 (px^2) + a*(pz^4) */ - MP_CHECKOK(group->meth->field_sqr(px, t0, group->meth)); - MP_CHECKOK(group->meth->field_add(t0, t0, M, group->meth)); - MP_CHECKOK(group->meth->field_add(t0, M, t0, group->meth)); - MP_CHECKOK(group->meth->field_add(t0, paz4, M, group->meth)); - - /* rz = 2 * py * pz */ - MP_CHECKOK(group->meth->field_mul(py, pz, S, group->meth)); - MP_CHECKOK(group->meth->field_add(S, S, rz, group->meth)); - - /* t0 = 2y^2 , t1 = 8y^4 */ - MP_CHECKOK(group->meth->field_sqr(py, t0, group->meth)); - MP_CHECKOK(group->meth->field_add(t0, t0, t0, group->meth)); - MP_CHECKOK(group->meth->field_sqr(t0, t1, group->meth)); - MP_CHECKOK(group->meth->field_add(t1, t1, t1, group->meth)); - - /* S = 4 * px * py^2 = 2 * px * t0 */ - MP_CHECKOK(group->meth->field_mul(px, t0, S, group->meth)); - MP_CHECKOK(group->meth->field_add(S, S, S, group->meth)); - - - /* rx = M^2 - 2S */ - MP_CHECKOK(group->meth->field_sqr(M, rx, group->meth)); - MP_CHECKOK(group->meth->field_sub(rx, S, rx, group->meth)); - MP_CHECKOK(group->meth->field_sub(rx, S, rx, group->meth)); - - /* ry = M * (S - rx) - t1 */ - MP_CHECKOK(group->meth->field_sub(S, rx, S, group->meth)); - MP_CHECKOK(group->meth->field_mul(S, M, ry, group->meth)); - MP_CHECKOK(group->meth->field_sub(ry, t1, ry, group->meth)); - - /* ra*z^4 = 2*t1*(apz4) */ - MP_CHECKOK(group->meth->field_mul(paz4, t1, raz4, group->meth)); - MP_CHECKOK(group->meth->field_add(raz4, raz4, raz4, group->meth)); - - - CLEANUP: - return res; -} - -/* Computes R = P + Q where R is (rx, ry, rz), P is (px, py, pz) and Q is - * (qx, qy, 1). Elliptic curve points P, Q, and R can all be identical. - * Uses mixed Modified_Jacobian-affine coordinates. Assumes input is - * already field-encoded using field_enc, and returns output that is still - * field-encoded. */ -mp_err -ec_GFp_pt_add_jm_aff(const mp_int *px, const mp_int *py, const mp_int *pz, - const mp_int *paz4, const mp_int *qx, - const mp_int *qy, mp_int *rx, mp_int *ry, mp_int *rz, - mp_int *raz4, mp_int scratch[], const ECGroup *group) -{ - mp_err res = MP_OKAY; - mp_int *A, *B, *C, *D, *C2, *C3; - - A = &scratch[0]; - B = &scratch[1]; - C = &scratch[2]; - D = &scratch[3]; - C2 = &scratch[4]; - C3 = &scratch[5]; - -#if MAX_SCRATCH < 6 -#error "Scratch array defined too small " -#endif - - /* If either P or Q is the point at infinity, then return the other - * point */ - if (ec_GFp_pt_is_inf_jac(px, py, pz) == MP_YES) { - MP_CHECKOK(ec_GFp_pt_aff2jac(qx, qy, rx, ry, rz, group)); - MP_CHECKOK(group->meth->field_sqr(rz, raz4, group->meth)); - MP_CHECKOK(group->meth->field_sqr(raz4, raz4, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(raz4, &group->curvea, raz4, group->meth)); - goto CLEANUP; - } - if (ec_GFp_pt_is_inf_aff(qx, qy) == MP_YES) { - MP_CHECKOK(mp_copy(px, rx)); - MP_CHECKOK(mp_copy(py, ry)); - MP_CHECKOK(mp_copy(pz, rz)); - MP_CHECKOK(mp_copy(paz4, raz4)); - goto CLEANUP; - } - - /* A = qx * pz^2, B = qy * pz^3 */ - MP_CHECKOK(group->meth->field_sqr(pz, A, group->meth)); - MP_CHECKOK(group->meth->field_mul(A, pz, B, group->meth)); - MP_CHECKOK(group->meth->field_mul(A, qx, A, group->meth)); - MP_CHECKOK(group->meth->field_mul(B, qy, B, group->meth)); - - /* - * Additional checks for point equality and point at infinity - */ - if (mp_cmp(px, A) == 0 && mp_cmp(py, B) == 0) { - /* POINT_DOUBLE(P) */ - MP_CHECKOK(ec_GFp_pt_dbl_jm(px, py, pz, paz4, rx, ry, rz, raz4, - scratch, group)); - goto CLEANUP; - } - - /* C = A - px, D = B - py */ - MP_CHECKOK(group->meth->field_sub(A, px, C, group->meth)); - MP_CHECKOK(group->meth->field_sub(B, py, D, group->meth)); - - /* C2 = C^2, C3 = C^3 */ - MP_CHECKOK(group->meth->field_sqr(C, C2, group->meth)); - MP_CHECKOK(group->meth->field_mul(C, C2, C3, group->meth)); - - /* rz = pz * C */ - MP_CHECKOK(group->meth->field_mul(pz, C, rz, group->meth)); - - /* C = px * C^2 */ - MP_CHECKOK(group->meth->field_mul(px, C2, C, group->meth)); - /* A = D^2 */ - MP_CHECKOK(group->meth->field_sqr(D, A, group->meth)); - - /* rx = D^2 - (C^3 + 2 * (px * C^2)) */ - MP_CHECKOK(group->meth->field_add(C, C, rx, group->meth)); - MP_CHECKOK(group->meth->field_add(C3, rx, rx, group->meth)); - MP_CHECKOK(group->meth->field_sub(A, rx, rx, group->meth)); - - /* C3 = py * C^3 */ - MP_CHECKOK(group->meth->field_mul(py, C3, C3, group->meth)); - - /* ry = D * (px * C^2 - rx) - py * C^3 */ - MP_CHECKOK(group->meth->field_sub(C, rx, ry, group->meth)); - MP_CHECKOK(group->meth->field_mul(D, ry, ry, group->meth)); - MP_CHECKOK(group->meth->field_sub(ry, C3, ry, group->meth)); - - /* raz4 = a * rz^4 */ - MP_CHECKOK(group->meth->field_sqr(rz, raz4, group->meth)); - MP_CHECKOK(group->meth->field_sqr(raz4, raz4, group->meth)); - MP_CHECKOK(group->meth-> - field_mul(raz4, &group->curvea, raz4, group->meth)); -CLEANUP: - return res; -} - -/* Computes R = nP where R is (rx, ry) and P is the base point. Elliptic - * curve points P and R can be identical. Uses mixed Modified-Jacobian - * co-ordinates for doubling and Chudnovsky Jacobian coordinates for - * additions. Assumes input is already field-encoded using field_enc, and - * returns output that is still field-encoded. Uses 5-bit window NAF - * method (algorithm 11) for scalar-point multiplication from Brown, - * Hankerson, Lopez, Menezes. Software Implementation of the NIST Elliptic - * Curves Over Prime Fields. */ -mp_err -ec_GFp_pt_mul_jm_wNAF(const mp_int *n, const mp_int *px, const mp_int *py, - mp_int *rx, mp_int *ry, const ECGroup *group, - int timing) -{ - mp_err res = MP_OKAY; - mp_int precomp[16][2], rz, tpx, tpy, tpz; - mp_int raz4, tpaz4; - mp_int scratch[MAX_SCRATCH]; - signed char *naf = NULL; - int i, orderBitSize; - int numDoubles, numAdds, extraDoubles, extraAdds; - - MP_DIGITS(&rz) = 0; - MP_DIGITS(&raz4) = 0; - MP_DIGITS(&tpx) = 0; - MP_DIGITS(&tpy) = 0; - MP_DIGITS(&tpz) = 0; - MP_DIGITS(&tpaz4) = 0; - for (i = 0; i < 16; i++) { - MP_DIGITS(&precomp[i][0]) = 0; - MP_DIGITS(&precomp[i][1]) = 0; - } - for (i = 0; i < MAX_SCRATCH; i++) { - MP_DIGITS(&scratch[i]) = 0; - } - - ARGCHK(group != NULL, MP_BADARG); - ARGCHK((n != NULL) && (px != NULL) && (py != NULL), MP_BADARG); - - /* initialize precomputation table */ - MP_CHECKOK(mp_init(&tpx, FLAG(n))); - MP_CHECKOK(mp_init(&tpy, FLAG(n))); - MP_CHECKOK(mp_init(&tpz, FLAG(n))); - MP_CHECKOK(mp_init(&tpaz4, FLAG(n))); - MP_CHECKOK(mp_init(&rz, FLAG(n))); - MP_CHECKOK(mp_init(&raz4, FLAG(n))); - - for (i = 0; i < 16; i++) { - MP_CHECKOK(mp_init(&precomp[i][0], FLAG(n))); - MP_CHECKOK(mp_init(&precomp[i][1], FLAG(n))); - } - for (i = 0; i < MAX_SCRATCH; i++) { - MP_CHECKOK(mp_init(&scratch[i], FLAG(n))); - } - - /* Set out[8] = P */ - MP_CHECKOK(mp_copy(px, &precomp[8][0])); - MP_CHECKOK(mp_copy(py, &precomp[8][1])); - - /* Set (tpx, tpy) = 2P */ - MP_CHECKOK(group-> - point_dbl(&precomp[8][0], &precomp[8][1], &tpx, &tpy, - group)); - - /* Set 3P, 5P, ..., 15P */ - for (i = 8; i < 15; i++) { - MP_CHECKOK(group-> - point_add(&precomp[i][0], &precomp[i][1], &tpx, &tpy, - &precomp[i + 1][0], &precomp[i + 1][1], - group)); - } - - /* Set -15P, -13P, ..., -P */ - for (i = 0; i < 8; i++) { - MP_CHECKOK(mp_copy(&precomp[15 - i][0], &precomp[i][0])); - MP_CHECKOK(group->meth-> - field_neg(&precomp[15 - i][1], &precomp[i][1], - group->meth)); - } - - /* R = inf */ - MP_CHECKOK(ec_GFp_pt_set_inf_jac(rx, ry, &rz)); - - orderBitSize = mpl_significant_bits(&group->order); - - /* Allocate memory for NAF */ -#ifdef _KERNEL - naf = (signed char *) kmem_alloc((orderBitSize + 1), FLAG(n)); -#else - naf = (signed char *) malloc(sizeof(signed char) * (orderBitSize + 1)); - if (naf == NULL) { - res = MP_MEM; - goto CLEANUP; - } -#endif - - /* Compute 5NAF */ - ec_compute_wNAF(naf, orderBitSize, n, 5); - - numAdds = 0; - numDoubles = orderBitSize; - /* wNAF method */ - for (i = orderBitSize; i >= 0; i--) { - - if (ec_GFp_pt_is_inf_jac(rx, ry, &rz) == MP_YES) { - numDoubles--; - } - - /* R = 2R */ - ec_GFp_pt_dbl_jm(rx, ry, &rz, &raz4, rx, ry, &rz, - &raz4, scratch, group); - - if (naf[i] != 0) { - ec_GFp_pt_add_jm_aff(rx, ry, &rz, &raz4, - &precomp[(naf[i] + 15) / 2][0], - &precomp[(naf[i] + 15) / 2][1], rx, ry, - &rz, &raz4, scratch, group); - numAdds++; - } - } - - /* extra operations to make timing less dependent on secrets */ - if (timing) { - /* low-order bit of timing argument contains no entropy */ - timing >>= 1; - - MP_CHECKOK(ec_GFp_pt_set_inf_jac(&tpx, &tpy, &tpz)); - mp_zero(&tpaz4); - - /* Set the temp value to a non-infinite point */ - ec_GFp_pt_add_jm_aff(&tpx, &tpy, &tpz, &tpaz4, - &precomp[8][0], - &precomp[8][1], &tpx, &tpy, - &tpz, &tpaz4, scratch, group); - - /* two bits of extra adds */ - extraAdds = timing & 0x3; - timing >>= 2; - /* Window size is 5, so the maximum number of additions is ceil(orderBitSize/5) */ - /* This is the same as (orderBitSize + 4) / 5 */ - for(i = numAdds; i <= (orderBitSize + 4) / 5 + extraAdds; i++) { - ec_GFp_pt_add_jm_aff(&tpx, &tpy, &tpz, &tpaz4, - &precomp[9 + (i % 3)][0], - &precomp[9 + (i % 3)][1], &tpx, &tpy, - &tpz, &tpaz4, scratch, group); - } - - /* two bits of extra doubles */ - extraDoubles = timing & 0x3; - timing >>= 2; - for(i = numDoubles; i <= orderBitSize + extraDoubles; i++) { - ec_GFp_pt_dbl_jm(&tpx, &tpy, &tpz, &tpaz4, &tpx, &tpy, &tpz, - &tpaz4, scratch, group); - } - - } - - /* convert result S to affine coordinates */ - MP_CHECKOK(ec_GFp_pt_jac2aff(rx, ry, &rz, rx, ry, group)); - - CLEANUP: - for (i = 0; i < MAX_SCRATCH; i++) { - mp_clear(&scratch[i]); - } - for (i = 0; i < 16; i++) { - mp_clear(&precomp[i][0]); - mp_clear(&precomp[i][1]); - } - mp_clear(&tpx); - mp_clear(&tpy); - mp_clear(&tpz); - mp_clear(&tpaz4); - mp_clear(&rz); - mp_clear(&raz4); -#ifdef _KERNEL - kmem_free(naf, (orderBitSize + 1)); -#else - free(naf); -#endif - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_mont.c b/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_mont.c deleted file mode 100644 index 6b5d6a62deff2..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_mont.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the elliptic curve math library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Douglas Stebila , Sun Microsystems Laboratories - * - *********************************************************************** */ - -/* Uses Montgomery reduction for field arithmetic. See mpi/mpmontg.c for - * code implementation. */ - -#include "mpi.h" -#include "mplogic.h" -#include "mpi-priv.h" -#include "ecl-priv.h" -#include "ecp.h" -#ifndef _KERNEL -#include -#include -#endif - -/* Construct a generic GFMethod for arithmetic over prime fields with - * irreducible irr. */ -GFMethod * -GFMethod_consGFp_mont(const mp_int *irr) -{ - mp_err res = MP_OKAY; - int i; - GFMethod *meth = NULL; - mp_mont_modulus *mmm; - - meth = GFMethod_consGFp(irr); - if (meth == NULL) - return NULL; - -#ifdef _KERNEL - mmm = (mp_mont_modulus *) kmem_alloc(sizeof(mp_mont_modulus), - FLAG(irr)); -#else - mmm = (mp_mont_modulus *) malloc(sizeof(mp_mont_modulus)); -#endif - if (mmm == NULL) { - res = MP_MEM; - goto CLEANUP; - } - - meth->field_mul = &ec_GFp_mul_mont; - meth->field_sqr = &ec_GFp_sqr_mont; - meth->field_div = &ec_GFp_div_mont; - meth->field_enc = &ec_GFp_enc_mont; - meth->field_dec = &ec_GFp_dec_mont; - meth->extra1 = mmm; - meth->extra2 = NULL; - meth->extra_free = &ec_GFp_extra_free_mont; - - mmm->N = meth->irr; - i = mpl_significant_bits(&meth->irr); - i += MP_DIGIT_BIT - 1; - mmm->b = i - i % MP_DIGIT_BIT; - mmm->n0prime = 0 - s_mp_invmod_radix(MP_DIGIT(&meth->irr, 0)); - - CLEANUP: - if (res != MP_OKAY) { - GFMethod_free(meth); - return NULL; - } - return meth; -} - -/* Wrapper functions for generic prime field arithmetic. */ - -/* Field multiplication using Montgomery reduction. */ -mp_err -ec_GFp_mul_mont(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - -#ifdef MP_MONT_USE_MP_MUL - /* if MP_MONT_USE_MP_MUL is defined, then the function s_mp_mul_mont - * is not implemented and we have to use mp_mul and s_mp_redc directly - */ - MP_CHECKOK(mp_mul(a, b, r)); - MP_CHECKOK(s_mp_redc(r, (mp_mont_modulus *) meth->extra1)); -#else - mp_int s; - - MP_DIGITS(&s) = 0; - /* s_mp_mul_mont doesn't allow source and destination to be the same */ - if ((a == r) || (b == r)) { - MP_CHECKOK(mp_init(&s, FLAG(a))); - MP_CHECKOK(s_mp_mul_mont - (a, b, &s, (mp_mont_modulus *) meth->extra1)); - MP_CHECKOK(mp_copy(&s, r)); - mp_clear(&s); - } else { - return s_mp_mul_mont(a, b, r, (mp_mont_modulus *) meth->extra1); - } -#endif - CLEANUP: - return res; -} - -/* Field squaring using Montgomery reduction. */ -mp_err -ec_GFp_sqr_mont(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - return ec_GFp_mul_mont(a, a, r, meth); -} - -/* Field division using Montgomery reduction. */ -mp_err -ec_GFp_div_mont(const mp_int *a, const mp_int *b, mp_int *r, - const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - /* if A=aZ represents a encoded in montgomery coordinates with Z and # - * and \ respectively represent multiplication and division in - * montgomery coordinates, then A\B = (a/b)Z = (A/B)Z and Binv = - * (1/b)Z = (1/B)(Z^2) where B # Binv = Z */ - MP_CHECKOK(ec_GFp_div(a, b, r, meth)); - MP_CHECKOK(ec_GFp_enc_mont(r, r, meth)); - if (a == NULL) { - MP_CHECKOK(ec_GFp_enc_mont(r, r, meth)); - } - CLEANUP: - return res; -} - -/* Encode a field element in Montgomery form. See s_mp_to_mont in - * mpi/mpmontg.c */ -mp_err -ec_GFp_enc_mont(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_mont_modulus *mmm; - mp_err res = MP_OKAY; - - mmm = (mp_mont_modulus *) meth->extra1; - MP_CHECKOK(mpl_lsh(a, r, mmm->b)); - MP_CHECKOK(mp_mod(r, &mmm->N, r)); - CLEANUP: - return res; -} - -/* Decode a field element from Montgomery form. */ -mp_err -ec_GFp_dec_mont(const mp_int *a, mp_int *r, const GFMethod *meth) -{ - mp_err res = MP_OKAY; - - if (a != r) { - MP_CHECKOK(mp_copy(a, r)); - } - MP_CHECKOK(s_mp_redc(r, (mp_mont_modulus *) meth->extra1)); - CLEANUP: - return res; -} - -/* Free the memory allocated to the extra fields of Montgomery GFMethod - * object. */ -void -ec_GFp_extra_free_mont(GFMethod *meth) -{ - if (meth->extra1 != NULL) { -#ifdef _KERNEL - kmem_free(meth->extra1, sizeof(mp_mont_modulus)); -#else - free(meth->extra1); -#endif - meth->extra1 = NULL; - } -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/logtab.h b/src/jdk.crypto.ec/share/native/libsunec/impl/logtab.h deleted file mode 100644 index 9f709ccb7e211..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/logtab.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1994-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#ifndef _LOGTAB_H -#define _LOGTAB_H - -const float s_logv_2[] = { - 0.000000000f, 0.000000000f, 1.000000000f, 0.630929754f, /* 0 1 2 3 */ - 0.500000000f, 0.430676558f, 0.386852807f, 0.356207187f, /* 4 5 6 7 */ - 0.333333333f, 0.315464877f, 0.301029996f, 0.289064826f, /* 8 9 10 11 */ - 0.278942946f, 0.270238154f, 0.262649535f, 0.255958025f, /* 12 13 14 15 */ - 0.250000000f, 0.244650542f, 0.239812467f, 0.235408913f, /* 16 17 18 19 */ - 0.231378213f, 0.227670249f, 0.224243824f, 0.221064729f, /* 20 21 22 23 */ - 0.218104292f, 0.215338279f, 0.212746054f, 0.210309918f, /* 24 25 26 27 */ - 0.208014598f, 0.205846832f, 0.203795047f, 0.201849087f, /* 28 29 30 31 */ - 0.200000000f, 0.198239863f, 0.196561632f, 0.194959022f, /* 32 33 34 35 */ - 0.193426404f, 0.191958720f, 0.190551412f, 0.189200360f, /* 36 37 38 39 */ - 0.187901825f, 0.186652411f, 0.185449023f, 0.184288833f, /* 40 41 42 43 */ - 0.183169251f, 0.182087900f, 0.181042597f, 0.180031327f, /* 44 45 46 47 */ - 0.179052232f, 0.178103594f, 0.177183820f, 0.176291434f, /* 48 49 50 51 */ - 0.175425064f, 0.174583430f, 0.173765343f, 0.172969690f, /* 52 53 54 55 */ - 0.172195434f, 0.171441601f, 0.170707280f, 0.169991616f, /* 56 57 58 59 */ - 0.169293808f, 0.168613099f, 0.167948779f, 0.167300179f, /* 60 61 62 63 */ - 0.166666667f -}; - -#endif /* _LOGTAB_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m-priv.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m-priv.h deleted file mode 100644 index caa56e45f9a43..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m-priv.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang Shantz and - * Douglas Stebila of Sun Laboratories. - * - *********************************************************************** */ - -#ifndef _MP_GF2M_PRIV_H_ -#define _MP_GF2M_PRIV_H_ - -#include "mpi-priv.h" - -extern const mp_digit mp_gf2m_sqr_tb[16]; - -#if defined(MP_USE_UINT_DIGIT) -#define MP_DIGIT_BITS 32 -#else -#define MP_DIGIT_BITS 64 -#endif - -/* Platform-specific macros for fast binary polynomial squaring. */ -#if MP_DIGIT_BITS == 32 -#define gf2m_SQR1(w) \ - mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 16 | \ - mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] -#define gf2m_SQR0(w) \ - mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ - mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] -#else -#define gf2m_SQR1(w) \ - mp_gf2m_sqr_tb[(w) >> 60 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 56 & 0xF] << 48 | \ - mp_gf2m_sqr_tb[(w) >> 52 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 48 & 0xF] << 32 | \ - mp_gf2m_sqr_tb[(w) >> 44 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 40 & 0xF] << 16 | \ - mp_gf2m_sqr_tb[(w) >> 36 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) >> 32 & 0xF] -#define gf2m_SQR0(w) \ - mp_gf2m_sqr_tb[(w) >> 28 & 0xF] << 56 | mp_gf2m_sqr_tb[(w) >> 24 & 0xF] << 48 | \ - mp_gf2m_sqr_tb[(w) >> 20 & 0xF] << 40 | mp_gf2m_sqr_tb[(w) >> 16 & 0xF] << 32 | \ - mp_gf2m_sqr_tb[(w) >> 12 & 0xF] << 24 | mp_gf2m_sqr_tb[(w) >> 8 & 0xF] << 16 | \ - mp_gf2m_sqr_tb[(w) >> 4 & 0xF] << 8 | mp_gf2m_sqr_tb[(w) & 0xF] -#endif - -/* Multiply two binary polynomials mp_digits a, b. - * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1. - * Output in two mp_digits rh, rl. - */ -void s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b); - -/* Compute xor-multiply of two binary polynomials (a1, a0) x (b1, b0) - * result is a binary polynomial in 4 mp_digits r[4]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1, - const mp_digit b0); - -/* Compute xor-multiply of two binary polynomials (a2, a1, a0) x (b2, b1, b0) - * result is a binary polynomial in 6 mp_digits r[6]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0, - const mp_digit b2, const mp_digit b1, const mp_digit b0); - -/* Compute xor-multiply of two binary polynomials (a3, a2, a1, a0) x (b3, b2, b1, b0) - * result is a binary polynomial in 8 mp_digits r[8]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1, - const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1, - const mp_digit b0); - -#endif /* _MP_GF2M_PRIV_H_ */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.c b/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.c deleted file mode 100644 index 31911c04d9c5c..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.c +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang Shantz and - * Douglas Stebila of Sun Laboratories. - * - *********************************************************************** */ - -#include "mp_gf2m.h" -#include "mp_gf2m-priv.h" -#include "mplogic.h" -#include "mpi-priv.h" - -const mp_digit mp_gf2m_sqr_tb[16] = -{ - 0, 1, 4, 5, 16, 17, 20, 21, - 64, 65, 68, 69, 80, 81, 84, 85 -}; - -/* Multiply two binary polynomials mp_digits a, b. - * Result is a polynomial with degree < 2 * MP_DIGIT_BITS - 1. - * Output in two mp_digits rh, rl. - */ -#if MP_DIGIT_BITS == 32 -void -s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b) -{ - register mp_digit h, l, s; - mp_digit tab[8], top2b = a >> 30; - register mp_digit a1, a2, a4; - - a1 = a & (0x3FFFFFFF); a2 = a1 << 1; a4 = a2 << 1; - - tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2; - tab[4] = a4; tab[5] = a1^a4; tab[6] = a2^a4; tab[7] = a1^a2^a4; - - s = tab[b & 0x7]; l = s; - s = tab[b >> 3 & 0x7]; l ^= s << 3; h = s >> 29; - s = tab[b >> 6 & 0x7]; l ^= s << 6; h ^= s >> 26; - s = tab[b >> 9 & 0x7]; l ^= s << 9; h ^= s >> 23; - s = tab[b >> 12 & 0x7]; l ^= s << 12; h ^= s >> 20; - s = tab[b >> 15 & 0x7]; l ^= s << 15; h ^= s >> 17; - s = tab[b >> 18 & 0x7]; l ^= s << 18; h ^= s >> 14; - s = tab[b >> 21 & 0x7]; l ^= s << 21; h ^= s >> 11; - s = tab[b >> 24 & 0x7]; l ^= s << 24; h ^= s >> 8; - s = tab[b >> 27 & 0x7]; l ^= s << 27; h ^= s >> 5; - s = tab[b >> 30 ]; l ^= s << 30; h ^= s >> 2; - - /* compensate for the top two bits of a */ - - if (top2b & 01) { l ^= b << 30; h ^= b >> 2; } - if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } - - *rh = h; *rl = l; -} -#else -void -s_bmul_1x1(mp_digit *rh, mp_digit *rl, const mp_digit a, const mp_digit b) -{ - register mp_digit h, l, s; - mp_digit tab[16], top3b = a >> 61; - register mp_digit a1, a2, a4, a8; - - a1 = a & (0x1FFFFFFFFFFFFFFFULL); a2 = a1 << 1; - a4 = a2 << 1; a8 = a4 << 1; - tab[ 0] = 0; tab[ 1] = a1; tab[ 2] = a2; tab[ 3] = a1^a2; - tab[ 4] = a4; tab[ 5] = a1^a4; tab[ 6] = a2^a4; tab[ 7] = a1^a2^a4; - tab[ 8] = a8; tab[ 9] = a1^a8; tab[10] = a2^a8; tab[11] = a1^a2^a8; - tab[12] = a4^a8; tab[13] = a1^a4^a8; tab[14] = a2^a4^a8; tab[15] = a1^a2^a4^a8; - - s = tab[b & 0xF]; l = s; - s = tab[b >> 4 & 0xF]; l ^= s << 4; h = s >> 60; - s = tab[b >> 8 & 0xF]; l ^= s << 8; h ^= s >> 56; - s = tab[b >> 12 & 0xF]; l ^= s << 12; h ^= s >> 52; - s = tab[b >> 16 & 0xF]; l ^= s << 16; h ^= s >> 48; - s = tab[b >> 20 & 0xF]; l ^= s << 20; h ^= s >> 44; - s = tab[b >> 24 & 0xF]; l ^= s << 24; h ^= s >> 40; - s = tab[b >> 28 & 0xF]; l ^= s << 28; h ^= s >> 36; - s = tab[b >> 32 & 0xF]; l ^= s << 32; h ^= s >> 32; - s = tab[b >> 36 & 0xF]; l ^= s << 36; h ^= s >> 28; - s = tab[b >> 40 & 0xF]; l ^= s << 40; h ^= s >> 24; - s = tab[b >> 44 & 0xF]; l ^= s << 44; h ^= s >> 20; - s = tab[b >> 48 & 0xF]; l ^= s << 48; h ^= s >> 16; - s = tab[b >> 52 & 0xF]; l ^= s << 52; h ^= s >> 12; - s = tab[b >> 56 & 0xF]; l ^= s << 56; h ^= s >> 8; - s = tab[b >> 60 ]; l ^= s << 60; h ^= s >> 4; - - /* compensate for the top three bits of a */ - - if (top3b & 01) { l ^= b << 61; h ^= b >> 3; } - if (top3b & 02) { l ^= b << 62; h ^= b >> 2; } - if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } - - *rh = h; *rl = l; -} -#endif - -/* Compute xor-multiply of two binary polynomials (a1, a0) x (b1, b0) - * result is a binary polynomial in 4 mp_digits r[4]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void -s_bmul_2x2(mp_digit *r, const mp_digit a1, const mp_digit a0, const mp_digit b1, - const mp_digit b0) -{ - mp_digit m1, m0; - /* r[3] = h1, r[2] = h0; r[1] = l1; r[0] = l0 */ - s_bmul_1x1(r+3, r+2, a1, b1); - s_bmul_1x1(r+1, r, a0, b0); - s_bmul_1x1(&m1, &m0, a0 ^ a1, b0 ^ b1); - /* Correction on m1 ^= l1 ^ h1; m0 ^= l0 ^ h0; */ - r[2] ^= m1 ^ r[1] ^ r[3]; /* h0 ^= m1 ^ l1 ^ h1; */ - r[1] = r[3] ^ r[2] ^ r[0] ^ m1 ^ m0; /* l1 ^= l0 ^ h0 ^ m0; */ -} - -/* Compute xor-multiply of two binary polynomials (a2, a1, a0) x (b2, b1, b0) - * result is a binary polynomial in 6 mp_digits r[6]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void -s_bmul_3x3(mp_digit *r, const mp_digit a2, const mp_digit a1, const mp_digit a0, - const mp_digit b2, const mp_digit b1, const mp_digit b0) -{ - mp_digit zm[4]; - - s_bmul_1x1(r+5, r+4, a2, b2); /* fill top 2 words */ - s_bmul_2x2(zm, a1, a2^a0, b1, b2^b0); /* fill middle 4 words */ - s_bmul_2x2(r, a1, a0, b1, b0); /* fill bottom 4 words */ - - zm[3] ^= r[3]; - zm[2] ^= r[2]; - zm[1] ^= r[1] ^ r[5]; - zm[0] ^= r[0] ^ r[4]; - - r[5] ^= zm[3]; - r[4] ^= zm[2]; - r[3] ^= zm[1]; - r[2] ^= zm[0]; -} - -/* Compute xor-multiply of two binary polynomials (a3, a2, a1, a0) x (b3, b2, b1, b0) - * result is a binary polynomial in 8 mp_digits r[8]. - * The caller MUST ensure that r has the right amount of space allocated. - */ -void s_bmul_4x4(mp_digit *r, const mp_digit a3, const mp_digit a2, const mp_digit a1, - const mp_digit a0, const mp_digit b3, const mp_digit b2, const mp_digit b1, - const mp_digit b0) -{ - mp_digit zm[4]; - - s_bmul_2x2(r+4, a3, a2, b3, b2); /* fill top 4 words */ - s_bmul_2x2(zm, a3^a1, a2^a0, b3^b1, b2^b0); /* fill middle 4 words */ - s_bmul_2x2(r, a1, a0, b1, b0); /* fill bottom 4 words */ - - zm[3] ^= r[3] ^ r[7]; - zm[2] ^= r[2] ^ r[6]; - zm[1] ^= r[1] ^ r[5]; - zm[0] ^= r[0] ^ r[4]; - - r[5] ^= zm[3]; - r[4] ^= zm[2]; - r[3] ^= zm[1]; - r[2] ^= zm[0]; -} - -/* Compute addition of two binary polynomials a and b, - * store result in c; c could be a or b, a and b could be equal; - * c is the bitwise XOR of a and b. - */ -mp_err -mp_badd(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_digit *pa, *pb, *pc; - mp_size ix; - mp_size used_pa, used_pb; - mp_err res = MP_OKAY; - - /* Add all digits up to the precision of b. If b had more - * precision than a initially, swap a, b first - */ - if (MP_USED(a) >= MP_USED(b)) { - pa = MP_DIGITS(a); - pb = MP_DIGITS(b); - used_pa = MP_USED(a); - used_pb = MP_USED(b); - } else { - pa = MP_DIGITS(b); - pb = MP_DIGITS(a); - used_pa = MP_USED(b); - used_pb = MP_USED(a); - } - - /* Make sure c has enough precision for the output value */ - MP_CHECKOK( s_mp_pad(c, used_pa) ); - - /* Do word-by-word xor */ - pc = MP_DIGITS(c); - for (ix = 0; ix < used_pb; ix++) { - (*pc++) = (*pa++) ^ (*pb++); - } - - /* Finish the rest of digits until we're actually done */ - for (; ix < used_pa; ++ix) { - *pc++ = *pa++; - } - - MP_USED(c) = used_pa; - MP_SIGN(c) = ZPOS; - s_mp_clamp(c); - -CLEANUP: - return res; -} - -#define s_mp_div2(a) MP_CHECKOK( mpl_rsh((a), (a), 1) ); - -/* Compute binary polynomial multiply d = a * b */ -static void -s_bmul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *d) -{ - mp_digit a_i, a0b0, a1b1, carry = 0; - while (a_len--) { - a_i = *a++; - s_bmul_1x1(&a1b1, &a0b0, a_i, b); - *d++ = a0b0 ^ carry; - carry = a1b1; - } - *d = carry; -} - -/* Compute binary polynomial xor multiply accumulate d ^= a * b */ -static void -s_bmul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *d) -{ - mp_digit a_i, a0b0, a1b1, carry = 0; - while (a_len--) { - a_i = *a++; - s_bmul_1x1(&a1b1, &a0b0, a_i, b); - *d++ ^= a0b0 ^ carry; - carry = a1b1; - } - *d ^= carry; -} - -/* Compute binary polynomial xor multiply c = a * b. - * All parameters may be identical. - */ -mp_err -mp_bmul(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_digit *pb, b_i; - mp_int tmp; - mp_size ib, a_used, b_used; - mp_err res = MP_OKAY; - - MP_DIGITS(&tmp) = 0; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if (a == c) { - MP_CHECKOK( mp_init_copy(&tmp, a) ); - if (a == b) - b = &tmp; - a = &tmp; - } else if (b == c) { - MP_CHECKOK( mp_init_copy(&tmp, b) ); - b = &tmp; - } - - if (MP_USED(a) < MP_USED(b)) { - const mp_int *xch = b; /* switch a and b if b longer */ - b = a; - a = xch; - } - - MP_USED(c) = 1; MP_DIGIT(c, 0) = 0; - MP_CHECKOK( s_mp_pad(c, USED(a) + USED(b)) ); - - pb = MP_DIGITS(b); - s_bmul_d(MP_DIGITS(a), MP_USED(a), *pb++, MP_DIGITS(c)); - - /* Outer loop: Digits of b */ - a_used = MP_USED(a); - b_used = MP_USED(b); - MP_USED(c) = a_used + b_used; - for (ib = 1; ib < b_used; ib++) { - b_i = *pb++; - - /* Inner product: Digits of a */ - if (b_i) - s_bmul_d_add(MP_DIGITS(a), a_used, b_i, MP_DIGITS(c) + ib); - else - MP_DIGIT(c, ib + a_used) = b_i; - } - - s_mp_clamp(c); - - SIGN(c) = ZPOS; - -CLEANUP: - mp_clear(&tmp); - return res; -} - - -/* Compute modular reduction of a and store result in r. - * r could be a. - * For modular arithmetic, the irreducible polynomial f(t) is represented - * as an array of int[], where f(t) is of the form: - * f(t) = t^p[0] + t^p[1] + ... + t^p[k] - * where m = p[0] > p[1] > ... > p[k] = 0. - */ -mp_err -mp_bmod(const mp_int *a, const unsigned int p[], mp_int *r) -{ - int j, k; - int n, dN, d0, d1; - mp_digit zz, *z, tmp; - mp_size used; - mp_err res = MP_OKAY; - - /* The algorithm does the reduction in place in r, - * if a != r, copy a into r first so reduction can be done in r - */ - if (a != r) { - MP_CHECKOK( mp_copy(a, r) ); - } - z = MP_DIGITS(r); - - /* start reduction */ - dN = p[0] / MP_DIGIT_BITS; - used = MP_USED(r); - - for (j = used - 1; j > dN;) { - - zz = z[j]; - if (zz == 0) { - j--; continue; - } - z[j] = 0; - - for (k = 1; p[k] > 0; k++) { - /* reducing component t^p[k] */ - n = p[0] - p[k]; - d0 = n % MP_DIGIT_BITS; - d1 = MP_DIGIT_BITS - d0; - n /= MP_DIGIT_BITS; - z[j-n] ^= (zz>>d0); - if (d0) - z[j-n-1] ^= (zz<> d0); - if (d0) - z[j-n-1] ^= (zz << d1); - - } - - /* final round of reduction */ - while (j == dN) { - - d0 = p[0] % MP_DIGIT_BITS; - zz = z[dN] >> d0; - if (zz == 0) break; - d1 = MP_DIGIT_BITS - d0; - - /* clear up the top d1 bits */ - if (d0) z[dN] = (z[dN] << d1) >> d1; - *z ^= zz; /* reduction t^0 component */ - - for (k = 1; p[k] > 0; k++) { - /* reducing component t^p[k]*/ - n = p[k] / MP_DIGIT_BITS; - d0 = p[k] % MP_DIGIT_BITS; - d1 = MP_DIGIT_BITS - d0; - z[n] ^= (zz << d0); - tmp = zz >> d1; - if (d0 && tmp) - z[n+1] ^= tmp; - } - } - - s_mp_clamp(r); -CLEANUP: - return res; -} - -/* Compute the product of two polynomials a and b, reduce modulo p, - * Store the result in r. r could be a or b; a could be b. - */ -mp_err -mp_bmulmod(const mp_int *a, const mp_int *b, const unsigned int p[], mp_int *r) -{ - mp_err res; - - if (a == b) return mp_bsqrmod(a, p, r); - if ((res = mp_bmul(a, b, r) ) != MP_OKAY) - return res; - return mp_bmod(r, p, r); -} - -/* Compute binary polynomial squaring c = a*a mod p . - * Parameter r and a can be identical. - */ - -mp_err -mp_bsqrmod(const mp_int *a, const unsigned int p[], mp_int *r) -{ - mp_digit *pa, *pr, a_i; - mp_int tmp; - mp_size ia, a_used; - mp_err res; - - ARGCHK(a != NULL && r != NULL, MP_BADARG); - MP_DIGITS(&tmp) = 0; - - if (a == r) { - MP_CHECKOK( mp_init_copy(&tmp, a) ); - a = &tmp; - } - - MP_USED(r) = 1; MP_DIGIT(r, 0) = 0; - MP_CHECKOK( s_mp_pad(r, 2*USED(a)) ); - - pa = MP_DIGITS(a); - pr = MP_DIGITS(r); - a_used = MP_USED(a); - MP_USED(r) = 2 * a_used; - - for (ia = 0; ia < a_used; ia++) { - a_i = *pa++; - *pr++ = gf2m_SQR0(a_i); - *pr++ = gf2m_SQR1(a_i); - } - - MP_CHECKOK( mp_bmod(r, p, r) ); - s_mp_clamp(r); - SIGN(r) = ZPOS; - -CLEANUP: - mp_clear(&tmp); - return res; -} - -/* Compute binary polynomial y/x mod p, y divided by x, reduce modulo p. - * Store the result in r. r could be x or y, and x could equal y. - * Uses algorithm Modular_Division_GF(2^m) from - * Chang-Shantz, S. "From Euclid's GCD to Montgomery Multiplication to - * the Great Divide". - */ -int -mp_bdivmod(const mp_int *y, const mp_int *x, const mp_int *pp, - const unsigned int p[], mp_int *r) -{ - mp_int aa, bb, uu; - mp_int *a, *b, *u, *v; - mp_err res = MP_OKAY; - - MP_DIGITS(&aa) = 0; - MP_DIGITS(&bb) = 0; - MP_DIGITS(&uu) = 0; - - MP_CHECKOK( mp_init_copy(&aa, x) ); - MP_CHECKOK( mp_init_copy(&uu, y) ); - MP_CHECKOK( mp_init_copy(&bb, pp) ); - MP_CHECKOK( s_mp_pad(r, USED(pp)) ); - MP_USED(r) = 1; MP_DIGIT(r, 0) = 0; - - a = &aa; b= &bb; u=&uu; v=r; - /* reduce x and y mod p */ - MP_CHECKOK( mp_bmod(a, p, a) ); - MP_CHECKOK( mp_bmod(u, p, u) ); - - while (!mp_isodd(a)) { - s_mp_div2(a); - if (mp_isodd(u)) { - MP_CHECKOK( mp_badd(u, pp, u) ); - } - s_mp_div2(u); - } - - do { - if (mp_cmp_mag(b, a) > 0) { - MP_CHECKOK( mp_badd(b, a, b) ); - MP_CHECKOK( mp_badd(v, u, v) ); - do { - s_mp_div2(b); - if (mp_isodd(v)) { - MP_CHECKOK( mp_badd(v, pp, v) ); - } - s_mp_div2(v); - } while (!mp_isodd(b)); - } - else if ((MP_DIGIT(a,0) == 1) && (MP_USED(a) == 1)) - break; - else { - MP_CHECKOK( mp_badd(a, b, a) ); - MP_CHECKOK( mp_badd(u, v, u) ); - do { - s_mp_div2(a); - if (mp_isodd(u)) { - MP_CHECKOK( mp_badd(u, pp, u) ); - } - s_mp_div2(u); - } while (!mp_isodd(a)); - } - } while (1); - - MP_CHECKOK( mp_copy(u, r) ); - -CLEANUP: - /* XXX this appears to be a memory leak in the NSS code */ - mp_clear(&aa); - mp_clear(&bb); - mp_clear(&uu); - return res; - -} - -/* Convert the bit-string representation of a polynomial a into an array - * of integers corresponding to the bits with non-zero coefficient. - * Up to max elements of the array will be filled. Return value is total - * number of coefficients that would be extracted if array was large enough. - */ -int -mp_bpoly2arr(const mp_int *a, unsigned int p[], int max) -{ - int i, j, k; - mp_digit top_bit, mask; - - top_bit = 1; - top_bit <<= MP_DIGIT_BIT - 1; - - for (k = 0; k < max; k++) p[k] = 0; - k = 0; - - for (i = MP_USED(a) - 1; i >= 0; i--) { - mask = top_bit; - for (j = MP_DIGIT_BIT - 1; j >= 0; j--) { - if (MP_DIGITS(a)[i] & mask) { - if (k < max) p[k] = MP_DIGIT_BIT * i + j; - k++; - } - mask >>= 1; - } - } - - return k; -} - -/* Convert the coefficient array representation of a polynomial to a - * bit-string. The array must be terminated by 0. - */ -mp_err -mp_barr2poly(const unsigned int p[], mp_int *a) -{ - - mp_err res = MP_OKAY; - int i; - - mp_zero(a); - for (i = 0; p[i] > 0; i++) { - MP_CHECKOK( mpl_set_bit(a, p[i], 1) ); - } - MP_CHECKOK( mpl_set_bit(a, 0, 1) ); - -CLEANUP: - return res; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.h deleted file mode 100644 index c95d30ffc7446..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mp_gf2m.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Multi-precision Binary Polynomial Arithmetic Library. - * - * The Initial Developer of the Original Code is - * Sun Microsystems, Inc. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang Shantz and - * Douglas Stebila of Sun Laboratories. - * - *********************************************************************** */ - -#ifndef _MP_GF2M_H_ -#define _MP_GF2M_H_ - -#include "mpi.h" - -mp_err mp_badd(const mp_int *a, const mp_int *b, mp_int *c); -mp_err mp_bmul(const mp_int *a, const mp_int *b, mp_int *c); - -/* For modular arithmetic, the irreducible polynomial f(t) is represented - * as an array of int[], where f(t) is of the form: - * f(t) = t^p[0] + t^p[1] + ... + t^p[k] - * where m = p[0] > p[1] > ... > p[k] = 0. - */ -mp_err mp_bmod(const mp_int *a, const unsigned int p[], mp_int *r); -mp_err mp_bmulmod(const mp_int *a, const mp_int *b, const unsigned int p[], - mp_int *r); -mp_err mp_bsqrmod(const mp_int *a, const unsigned int p[], mp_int *r); -mp_err mp_bdivmod(const mp_int *y, const mp_int *x, const mp_int *pp, - const unsigned int p[], mp_int *r); - -int mp_bpoly2arr(const mp_int *a, unsigned int p[], int max); -mp_err mp_barr2poly(const unsigned int p[], mp_int *a); - -#endif /* _MP_GF2M_H_ */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-config.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-config.h deleted file mode 100644 index a349f96ad8854..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-config.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1997 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Netscape Communications Corporation - * - *********************************************************************** */ - -#ifndef _MPI_CONFIG_H -#define _MPI_CONFIG_H - -/* $Id: mpi-config.h,v 1.5 2004/04/25 15:03:10 gerv%gerv.net Exp $ */ - -/* - For boolean options, - 0 = no - 1 = yes - - Other options are documented individually. - - */ - -#ifndef MP_IOFUNC -#define MP_IOFUNC 0 /* include mp_print() ? */ -#endif - -#ifndef MP_MODARITH -#define MP_MODARITH 1 /* include modular arithmetic ? */ -#endif - -#ifndef MP_NUMTH -#define MP_NUMTH 1 /* include number theoretic functions? */ -#endif - -#ifndef MP_LOGTAB -#define MP_LOGTAB 1 /* use table of logs instead of log()? */ -#endif - -#ifndef MP_MEMSET -#define MP_MEMSET 1 /* use memset() to zero buffers? */ -#endif - -#ifndef MP_MEMCPY -#define MP_MEMCPY 1 /* use memcpy() to copy buffers? */ -#endif - -#ifndef MP_CRYPTO -#define MP_CRYPTO 1 /* erase memory on free? */ -#endif - -#ifndef MP_ARGCHK -/* - 0 = no parameter checks - 1 = runtime checks, continue execution and return an error to caller - 2 = assertions; dump core on parameter errors - */ -#ifdef DEBUG -#define MP_ARGCHK 2 /* how to check input arguments */ -#else -#define MP_ARGCHK 1 /* how to check input arguments */ -#endif -#endif - -#ifndef MP_DEBUG -#define MP_DEBUG 0 /* print diagnostic output? */ -#endif - -#ifndef MP_DEFPREC -#define MP_DEFPREC 64 /* default precision, in digits */ -#endif - -#ifndef MP_MACRO -#define MP_MACRO 0 /* use macros for frequent calls? */ -#endif - -#ifndef MP_SQUARE -#define MP_SQUARE 1 /* use separate squaring code? */ -#endif - -#endif /* _MPI_CONFIG_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-priv.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-priv.h deleted file mode 100644 index 76bac90693d5f..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi-priv.h +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Netscape Communications Corporation - * - *********************************************************************** */ - -/* Arbitrary precision integer arithmetic library - * - * NOTE WELL: the content of this header file is NOT part of the "public" - * API for the MPI library, and may change at any time. - * Application programs that use libmpi should NOT include this header file. - */ - -#ifndef _MPI_PRIV_H -#define _MPI_PRIV_H - -/* $Id: mpi-priv.h,v 1.20 2005/11/22 07:16:43 relyea%netscape.com Exp $ */ - -#include "mpi.h" -#ifndef _KERNEL -#include -#include -#include -#endif /* _KERNEL */ - -#if MP_DEBUG -#include - -#define DIAG(T,V) {fprintf(stderr,T);mp_print(V,stderr);fputc('\n',stderr);} -#else -#define DIAG(T,V) -#endif - -/* If we aren't using a wired-in logarithm table, we need to include - the math library to get the log() function - */ - -/* {{{ s_logv_2[] - log table for 2 in various bases */ - -#if MP_LOGTAB -/* - A table of the logs of 2 for various bases (the 0 and 1 entries of - this table are meaningless and should not be referenced). - - This table is used to compute output lengths for the mp_toradix() - function. Since a number n in radix r takes up about log_r(n) - digits, we estimate the output size by taking the least integer - greater than log_r(n), where: - - log_r(n) = log_2(n) * log_r(2) - - This table, therefore, is a table of log_r(2) for 2 <= r <= 36, - which are the output bases supported. - */ - -extern const float s_logv_2[]; -#define LOG_V_2(R) s_logv_2[(R)] - -#else - -/* - If MP_LOGTAB is not defined, use the math library to compute the - logarithms on the fly. Otherwise, use the table. - Pick which works best for your system. - */ - -#include -#define LOG_V_2(R) (log(2.0)/log(R)) - -#endif /* if MP_LOGTAB */ - -/* }}} */ - -/* {{{ Digit arithmetic macros */ - -/* - When adding and multiplying digits, the results can be larger than - can be contained in an mp_digit. Thus, an mp_word is used. These - macros mask off the upper and lower digits of the mp_word (the - mp_word may be more than 2 mp_digits wide, but we only concern - ourselves with the low-order 2 mp_digits) - */ - -#define CARRYOUT(W) (mp_digit)((W)>>DIGIT_BIT) -#define ACCUM(W) (mp_digit)(W) - -#define MP_MIN(a,b) (((a) < (b)) ? (a) : (b)) -#define MP_MAX(a,b) (((a) > (b)) ? (a) : (b)) -#define MP_HOWMANY(a,b) (((a) + (b) - 1)/(b)) -#define MP_ROUNDUP(a,b) (MP_HOWMANY(a,b) * (b)) - -/* }}} */ - -/* {{{ Comparison constants */ - -#define MP_LT -1 -#define MP_EQ 0 -#define MP_GT 1 - -/* }}} */ - -/* {{{ private function declarations */ - -/* - If MP_MACRO is false, these will be defined as actual functions; - otherwise, suitable macro definitions will be used. This works - around the fact that ANSI C89 doesn't support an 'inline' keyword - (although I hear C9x will ... about bloody time). At present, the - macro definitions are identical to the function bodies, but they'll - expand in place, instead of generating a function call. - - I chose these particular functions to be made into macros because - some profiling showed they are called a lot on a typical workload, - and yet they are primarily housekeeping. - */ -#if MP_MACRO == 0 - void s_mp_setz(mp_digit *dp, mp_size count); /* zero digits */ - void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count); /* copy */ - void *s_mp_alloc(size_t nb, size_t ni, int flag); /* general allocator */ - void s_mp_free(void *ptr, mp_size); /* general free function */ -extern unsigned long mp_allocs; -extern unsigned long mp_frees; -extern unsigned long mp_copies; -#else - - /* Even if these are defined as macros, we need to respect the settings - of the MP_MEMSET and MP_MEMCPY configuration options... - */ - #if MP_MEMSET == 0 - #define s_mp_setz(dp, count) \ - {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=0;} - #else - #define s_mp_setz(dp, count) memset(dp, 0, (count) * sizeof(mp_digit)) - #endif /* MP_MEMSET */ - - #if MP_MEMCPY == 0 - #define s_mp_copy(sp, dp, count) \ - {int ix;for(ix=0;ix<(count);ix++)(dp)[ix]=(sp)[ix];} - #else - #define s_mp_copy(sp, dp, count) memcpy(dp, sp, (count) * sizeof(mp_digit)) - #endif /* MP_MEMCPY */ - - #define s_mp_alloc(nb, ni) calloc(nb, ni) - #define s_mp_free(ptr) {if(ptr) free(ptr);} -#endif /* MP_MACRO */ - -mp_err s_mp_grow(mp_int *mp, mp_size min); /* increase allocated size */ -mp_err s_mp_pad(mp_int *mp, mp_size min); /* left pad with zeroes */ - -#if MP_MACRO == 0 - void s_mp_clamp(mp_int *mp); /* clip leading zeroes */ -#else - #define s_mp_clamp(mp)\ - { mp_size used = MP_USED(mp); \ - while (used > 1 && DIGIT(mp, used - 1) == 0) --used; \ - MP_USED(mp) = used; \ - } -#endif /* MP_MACRO */ - -void s_mp_exch(mp_int *a, mp_int *b); /* swap a and b in place */ - -mp_err s_mp_lshd(mp_int *mp, mp_size p); /* left-shift by p digits */ -void s_mp_rshd(mp_int *mp, mp_size p); /* right-shift by p digits */ -mp_err s_mp_mul_2d(mp_int *mp, mp_digit d); /* multiply by 2^d in place */ -void s_mp_div_2d(mp_int *mp, mp_digit d); /* divide by 2^d in place */ -void s_mp_mod_2d(mp_int *mp, mp_digit d); /* modulo 2^d in place */ -void s_mp_div_2(mp_int *mp); /* divide by 2 in place */ -mp_err s_mp_mul_2(mp_int *mp); /* multiply by 2 in place */ -mp_err s_mp_norm(mp_int *a, mp_int *b, mp_digit *pd); - /* normalize for division */ -mp_err s_mp_add_d(mp_int *mp, mp_digit d); /* unsigned digit addition */ -mp_err s_mp_sub_d(mp_int *mp, mp_digit d); /* unsigned digit subtract */ -mp_err s_mp_mul_d(mp_int *mp, mp_digit d); /* unsigned digit multiply */ -mp_err s_mp_div_d(mp_int *mp, mp_digit d, mp_digit *r); - /* unsigned digit divide */ -mp_err s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu); - /* Barrett reduction */ -mp_err s_mp_add(mp_int *a, const mp_int *b); /* magnitude addition */ -mp_err s_mp_add_3arg(const mp_int *a, const mp_int *b, mp_int *c); -mp_err s_mp_sub(mp_int *a, const mp_int *b); /* magnitude subtract */ -mp_err s_mp_sub_3arg(const mp_int *a, const mp_int *b, mp_int *c); -mp_err s_mp_add_offset(mp_int *a, mp_int *b, mp_size offset); - /* a += b * RADIX^offset */ -mp_err s_mp_mul(mp_int *a, const mp_int *b); /* magnitude multiply */ -#if MP_SQUARE -mp_err s_mp_sqr(mp_int *a); /* magnitude square */ -#else -#define s_mp_sqr(a) s_mp_mul(a, a) -#endif -mp_err s_mp_div(mp_int *rem, mp_int *div, mp_int *quot); /* magnitude div */ -mp_err s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c); -mp_err s_mp_2expt(mp_int *a, mp_digit k); /* a = 2^k */ -int s_mp_cmp(const mp_int *a, const mp_int *b); /* magnitude comparison */ -int s_mp_cmp_d(const mp_int *a, mp_digit d); /* magnitude digit compare */ -int s_mp_ispow2(const mp_int *v); /* is v a power of 2? */ -int s_mp_ispow2d(mp_digit d); /* is d a power of 2? */ - -int s_mp_tovalue(char ch, int r); /* convert ch to value */ -char s_mp_todigit(mp_digit val, int r, int low); /* convert val to digit */ -int s_mp_outlen(int bits, int r); /* output length in bytes */ -mp_digit s_mp_invmod_radix(mp_digit P); /* returns (P ** -1) mod RADIX */ -mp_err s_mp_invmod_odd_m( const mp_int *a, const mp_int *m, mp_int *c); -mp_err s_mp_invmod_2d( const mp_int *a, mp_size k, mp_int *c); -mp_err s_mp_invmod_even_m(const mp_int *a, const mp_int *m, mp_int *c); - -#ifdef NSS_USE_COMBA - -#define IS_POWER_OF_2(a) ((a) && !((a) & ((a)-1))) - -void s_mp_mul_comba_4(const mp_int *A, const mp_int *B, mp_int *C); -void s_mp_mul_comba_8(const mp_int *A, const mp_int *B, mp_int *C); -void s_mp_mul_comba_16(const mp_int *A, const mp_int *B, mp_int *C); -void s_mp_mul_comba_32(const mp_int *A, const mp_int *B, mp_int *C); - -void s_mp_sqr_comba_4(const mp_int *A, mp_int *B); -void s_mp_sqr_comba_8(const mp_int *A, mp_int *B); -void s_mp_sqr_comba_16(const mp_int *A, mp_int *B); -void s_mp_sqr_comba_32(const mp_int *A, mp_int *B); - -#endif /* end NSS_USE_COMBA */ - -/* ------ mpv functions, operate on arrays of digits, not on mp_int's ------ */ -#if defined (__OS2__) && defined (__IBMC__) -#define MPI_ASM_DECL __cdecl -#else -#define MPI_ASM_DECL -#endif - -#ifdef MPI_AMD64 - -mp_digit MPI_ASM_DECL s_mpv_mul_set_vec64(mp_digit*, mp_digit *, mp_size, mp_digit); -mp_digit MPI_ASM_DECL s_mpv_mul_add_vec64(mp_digit*, const mp_digit*, mp_size, mp_digit); - -/* c = a * b */ -#define s_mpv_mul_d(a, a_len, b, c) \ - ((unsigned long*)c)[a_len] = s_mpv_mul_set_vec64(c, a, a_len, b) - -/* c += a * b */ -#define s_mpv_mul_d_add(a, a_len, b, c) \ - ((unsigned long*)c)[a_len] = s_mpv_mul_add_vec64(c, a, a_len, b) - -#else - -void MPI_ASM_DECL s_mpv_mul_d(const mp_digit *a, mp_size a_len, - mp_digit b, mp_digit *c); -void MPI_ASM_DECL s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, - mp_digit b, mp_digit *c); - -#endif - -void MPI_ASM_DECL s_mpv_mul_d_add_prop(const mp_digit *a, - mp_size a_len, mp_digit b, - mp_digit *c); -void MPI_ASM_DECL s_mpv_sqr_add_prop(const mp_digit *a, - mp_size a_len, - mp_digit *sqrs); - -mp_err MPI_ASM_DECL s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo, - mp_digit divisor, mp_digit *quot, mp_digit *rem); - -/* c += a * b * (MP_RADIX ** offset); */ -#define s_mp_mul_d_add_offset(a, b, c, off) \ -(s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off), MP_OKAY) - -typedef struct { - mp_int N; /* modulus N */ - mp_digit n0prime; /* n0' = - (n0 ** -1) mod MP_RADIX */ - mp_size b; /* R == 2 ** b, also b = # significant bits in N */ -} mp_mont_modulus; - -mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c, - mp_mont_modulus *mmm); -mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm); - -/* - * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line - * if a cache exists, or zero if there is no cache. If more than one - * cache line exists, it should return the smallest line size (which is - * usually the L1 cache). - * - * mp_modexp uses this information to make sure that private key information - * isn't being leaked through the cache. - * - * see mpcpucache.c for the implementation. - */ -unsigned long s_mpi_getProcessorLineSize(); - -/* }}} */ -#endif /* _MPI_PRIV_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c b/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c deleted file mode 100644 index e085c0ce78fa1..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.c +++ /dev/null @@ -1,4871 +0,0 @@ -/* - * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Netscape Communications Corporation - * Douglas Stebila of Sun Laboratories. - * - * Last Modified Date from the Original Code: Nov 2019 - *********************************************************************** */ - -/* Arbitrary precision integer arithmetic library */ - -#include "mpi-priv.h" -#if defined(OSF1) -#include -#endif - -#if MP_LOGTAB -/* - A table of the logs of 2 for various bases (the 0 and 1 entries of - this table are meaningless and should not be referenced). - - This table is used to compute output lengths for the mp_toradix() - function. Since a number n in radix r takes up about log_r(n) - digits, we estimate the output size by taking the least integer - greater than log_r(n), where: - - log_r(n) = log_2(n) * log_r(2) - - This table, therefore, is a table of log_r(2) for 2 <= r <= 36, - which are the output bases supported. - */ -#include "logtab.h" -#endif - -/* {{{ Constant strings */ - -/* Constant strings returned by mp_strerror() */ -static const char *mp_err_string[] = { - "unknown result code", /* say what? */ - "boolean true", /* MP_OKAY, MP_YES */ - "boolean false", /* MP_NO */ - "out of memory", /* MP_MEM */ - "argument out of range", /* MP_RANGE */ - "invalid input parameter", /* MP_BADARG */ - "result is undefined" /* MP_UNDEF */ -}; - -/* Value to digit maps for radix conversion */ - -/* s_dmap_1 - standard digits and letters */ -static const char *s_dmap_1 = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; - -/* }}} */ - -unsigned long mp_allocs; -unsigned long mp_frees; -unsigned long mp_copies; - -/* {{{ Default precision manipulation */ - -/* Default precision for newly created mp_int's */ -static mp_size s_mp_defprec = MP_DEFPREC; - -mp_size mp_get_prec(void) -{ - return s_mp_defprec; - -} /* end mp_get_prec() */ - -void mp_set_prec(mp_size prec) -{ - if(prec == 0) - s_mp_defprec = MP_DEFPREC; - else - s_mp_defprec = prec; - -} /* end mp_set_prec() */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ mp_init(mp, kmflag) */ - -/* - mp_init(mp, kmflag) - - Initialize a new zero-valued mp_int. Returns MP_OKAY if successful, - MP_MEM if memory could not be allocated for the structure. - */ - -mp_err mp_init(mp_int *mp, int kmflag) -{ - return mp_init_size(mp, s_mp_defprec, kmflag); - -} /* end mp_init() */ - -/* }}} */ - -/* {{{ mp_init_size(mp, prec, kmflag) */ - -/* - mp_init_size(mp, prec, kmflag) - - Initialize a new zero-valued mp_int with at least the given - precision; returns MP_OKAY if successful, or MP_MEM if memory could - not be allocated for the structure. - */ - -mp_err mp_init_size(mp_int *mp, mp_size prec, int kmflag) -{ - ARGCHK(mp != NULL && prec > 0, MP_BADARG); - - prec = MP_ROUNDUP(prec, s_mp_defprec); - if((DIGITS(mp) = s_mp_alloc(prec, sizeof(mp_digit), kmflag)) == NULL) - return MP_MEM; - - SIGN(mp) = ZPOS; - USED(mp) = 1; - ALLOC(mp) = prec; - - return MP_OKAY; - -} /* end mp_init_size() */ - -/* }}} */ - -/* {{{ mp_init_copy(mp, from) */ - -/* - mp_init_copy(mp, from) - - Initialize mp as an exact copy of from. Returns MP_OKAY if - successful, MP_MEM if memory could not be allocated for the new - structure. - */ - -mp_err mp_init_copy(mp_int *mp, const mp_int *from) -{ - ARGCHK(mp != NULL && from != NULL, MP_BADARG); - - if(mp == from) - return MP_OKAY; - - if((DIGITS(mp) = s_mp_alloc(ALLOC(from), sizeof(mp_digit), FLAG(from))) == NULL) - return MP_MEM; - - s_mp_copy(DIGITS(from), DIGITS(mp), USED(from)); - USED(mp) = USED(from); - ALLOC(mp) = ALLOC(from); - SIGN(mp) = SIGN(from); - -#ifndef _WIN32 - FLAG(mp) = FLAG(from); -#endif /* _WIN32 */ - - return MP_OKAY; - -} /* end mp_init_copy() */ - -/* }}} */ - -/* {{{ mp_copy(from, to) */ - -/* - mp_copy(from, to) - - Copies the mp_int 'from' to the mp_int 'to'. It is presumed that - 'to' has already been initialized (if not, use mp_init_copy() - instead). If 'from' and 'to' are identical, nothing happens. - */ - -mp_err mp_copy(const mp_int *from, mp_int *to) -{ - ARGCHK(from != NULL && to != NULL, MP_BADARG); - - if(from == to) - return MP_OKAY; - - ++mp_copies; - { /* copy */ - mp_digit *tmp; - - /* - If the allocated buffer in 'to' already has enough space to hold - all the used digits of 'from', we'll re-use it to avoid hitting - the memory allocater more than necessary; otherwise, we'd have - to grow anyway, so we just allocate a hunk and make the copy as - usual - */ - if(ALLOC(to) >= USED(from)) { - s_mp_setz(DIGITS(to) + USED(from), ALLOC(to) - USED(from)); - s_mp_copy(DIGITS(from), DIGITS(to), USED(from)); - - } else { - if((tmp = s_mp_alloc(ALLOC(from), sizeof(mp_digit), FLAG(from))) == NULL) - return MP_MEM; - - s_mp_copy(DIGITS(from), tmp, USED(from)); - - if(DIGITS(to) != NULL) { -#if MP_CRYPTO - s_mp_setz(DIGITS(to), ALLOC(to)); -#endif - s_mp_free(DIGITS(to), ALLOC(to)); - } - - DIGITS(to) = tmp; - ALLOC(to) = ALLOC(from); - } - - /* Copy the precision and sign from the original */ - USED(to) = USED(from); - SIGN(to) = SIGN(from); - } /* end copy */ - - return MP_OKAY; - -} /* end mp_copy() */ - -/* }}} */ - -/* {{{ mp_exch(mp1, mp2) */ - -/* - mp_exch(mp1, mp2) - - Exchange mp1 and mp2 without allocating any intermediate memory - (well, unless you count the stack space needed for this call and the - locals it creates...). This cannot fail. - */ - -void mp_exch(mp_int *mp1, mp_int *mp2) -{ -#if MP_ARGCHK == 2 - assert(mp1 != NULL && mp2 != NULL); -#else - if(mp1 == NULL || mp2 == NULL) - return; -#endif - - s_mp_exch(mp1, mp2); - -} /* end mp_exch() */ - -/* }}} */ - -/* {{{ mp_clear(mp) */ - -/* - mp_clear(mp) - - Release the storage used by an mp_int, and void its fields so that - if someone calls mp_clear() again for the same int later, we won't - get tollchocked. - */ - -void mp_clear(mp_int *mp) -{ - if(mp == NULL) - return; - - if(DIGITS(mp) != NULL) { -#if MP_CRYPTO - s_mp_setz(DIGITS(mp), ALLOC(mp)); -#endif - s_mp_free(DIGITS(mp), ALLOC(mp)); - DIGITS(mp) = NULL; - } - - USED(mp) = 0; - ALLOC(mp) = 0; - -} /* end mp_clear() */ - -/* }}} */ - -/* {{{ mp_zero(mp) */ - -/* - mp_zero(mp) - - Set mp to zero. Does not change the allocated size of the structure, - and therefore cannot fail (except on a bad argument, which we ignore) - */ -void mp_zero(mp_int *mp) -{ - if(mp == NULL) - return; - - s_mp_setz(DIGITS(mp), ALLOC(mp)); - USED(mp) = 1; - SIGN(mp) = ZPOS; - -} /* end mp_zero() */ - -/* }}} */ - -/* {{{ mp_set(mp, d) */ - -void mp_set(mp_int *mp, mp_digit d) -{ - if(mp == NULL) - return; - - mp_zero(mp); - DIGIT(mp, 0) = d; - -} /* end mp_set() */ - -/* }}} */ - -/* {{{ mp_set_int(mp, z) */ - -mp_err mp_set_int(mp_int *mp, long z) -{ - int ix; - unsigned long v = labs(z); - mp_err res; - - ARGCHK(mp != NULL, MP_BADARG); - - mp_zero(mp); - if(z == 0) - return MP_OKAY; /* shortcut for zero */ - - if (sizeof v <= sizeof(mp_digit)) { - DIGIT(mp,0) = v; - } else { - for (ix = sizeof(long) - 1; ix >= 0; ix--) { - if ((res = s_mp_mul_d(mp, (UCHAR_MAX + 1))) != MP_OKAY) - return res; - - res = s_mp_add_d(mp, (mp_digit)((v >> (ix * CHAR_BIT)) & UCHAR_MAX)); - if (res != MP_OKAY) - return res; - } - } - if(z < 0) - SIGN(mp) = NEG; - - return MP_OKAY; - -} /* end mp_set_int() */ - -/* }}} */ - -/* {{{ mp_set_ulong(mp, z) */ - -mp_err mp_set_ulong(mp_int *mp, unsigned long z) -{ - int ix; - mp_err res; - - ARGCHK(mp != NULL, MP_BADARG); - - mp_zero(mp); - if(z == 0) - return MP_OKAY; /* shortcut for zero */ - - if (sizeof z <= sizeof(mp_digit)) { - DIGIT(mp,0) = z; - } else { - for (ix = sizeof(long) - 1; ix >= 0; ix--) { - if ((res = s_mp_mul_d(mp, (UCHAR_MAX + 1))) != MP_OKAY) - return res; - - res = s_mp_add_d(mp, (mp_digit)((z >> (ix * CHAR_BIT)) & UCHAR_MAX)); - if (res != MP_OKAY) - return res; - } - } - return MP_OKAY; -} /* end mp_set_ulong() */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ Digit arithmetic */ - -/* {{{ mp_add_d(a, d, b) */ - -/* - mp_add_d(a, d, b) - - Compute the sum b = a + d, for a single digit d. Respects the sign of - its primary addend (single digits are unsigned anyway). - */ - -mp_err mp_add_d(const mp_int *a, mp_digit d, mp_int *b) -{ - mp_int tmp; - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_init_copy(&tmp, a)) != MP_OKAY) - return res; - - if(SIGN(&tmp) == ZPOS) { - if((res = s_mp_add_d(&tmp, d)) != MP_OKAY) - goto CLEANUP; - } else if(s_mp_cmp_d(&tmp, d) >= 0) { - if((res = s_mp_sub_d(&tmp, d)) != MP_OKAY) - goto CLEANUP; - } else { - mp_neg(&tmp, &tmp); - - DIGIT(&tmp, 0) = d - DIGIT(&tmp, 0); - } - - if(s_mp_cmp_d(&tmp, 0) == 0) - SIGN(&tmp) = ZPOS; - - s_mp_exch(&tmp, b); - -CLEANUP: - mp_clear(&tmp); - return res; - -} /* end mp_add_d() */ - -/* }}} */ - -/* {{{ mp_sub_d(a, d, b) */ - -/* - mp_sub_d(a, d, b) - - Compute the difference b = a - d, for a single digit d. Respects the - sign of its subtrahend (single digits are unsigned anyway). - */ - -mp_err mp_sub_d(const mp_int *a, mp_digit d, mp_int *b) -{ - mp_int tmp; - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_init_copy(&tmp, a)) != MP_OKAY) - return res; - - if(SIGN(&tmp) == NEG) { - if((res = s_mp_add_d(&tmp, d)) != MP_OKAY) - goto CLEANUP; - } else if(s_mp_cmp_d(&tmp, d) >= 0) { - if((res = s_mp_sub_d(&tmp, d)) != MP_OKAY) - goto CLEANUP; - } else { - mp_neg(&tmp, &tmp); - - DIGIT(&tmp, 0) = d - DIGIT(&tmp, 0); - SIGN(&tmp) = NEG; - } - - if(s_mp_cmp_d(&tmp, 0) == 0) - SIGN(&tmp) = ZPOS; - - s_mp_exch(&tmp, b); - -CLEANUP: - mp_clear(&tmp); - return res; - -} /* end mp_sub_d() */ - -/* }}} */ - -/* {{{ mp_mul_d(a, d, b) */ - -/* - mp_mul_d(a, d, b) - - Compute the product b = a * d, for a single digit d. Respects the sign - of its multiplicand (single digits are unsigned anyway) - */ - -mp_err mp_mul_d(const mp_int *a, mp_digit d, mp_int *b) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if(d == 0) { - mp_zero(b); - return MP_OKAY; - } - - if((res = mp_copy(a, b)) != MP_OKAY) - return res; - - res = s_mp_mul_d(b, d); - - return res; - -} /* end mp_mul_d() */ - -/* }}} */ - -/* {{{ mp_mul_2(a, c) */ - -mp_err mp_mul_2(const mp_int *a, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && c != NULL, MP_BADARG); - - if((res = mp_copy(a, c)) != MP_OKAY) - return res; - - return s_mp_mul_2(c); - -} /* end mp_mul_2() */ - -/* }}} */ - -/* {{{ mp_div_d(a, d, q, r) */ - -/* - mp_div_d(a, d, q, r) - - Compute the quotient q = a / d and remainder r = a mod d, for a - single digit d. Respects the sign of its divisor (single digits are - unsigned anyway). - */ - -mp_err mp_div_d(const mp_int *a, mp_digit d, mp_int *q, mp_digit *r) -{ - mp_err res; - mp_int qp; - mp_digit rem; - int pow; - - ARGCHK(a != NULL, MP_BADARG); - - if(d == 0) - return MP_RANGE; - - /* Shortcut for powers of two ... */ - if((pow = s_mp_ispow2d(d)) >= 0) { - mp_digit mask; - - mask = ((mp_digit)1 << pow) - 1; - rem = DIGIT(a, 0) & mask; - - if(q) { - mp_copy(a, q); - s_mp_div_2d(q, pow); - } - - if(r) - *r = rem; - - return MP_OKAY; - } - - if((res = mp_init_copy(&qp, a)) != MP_OKAY) - return res; - - res = s_mp_div_d(&qp, d, &rem); - - if(s_mp_cmp_d(&qp, 0) == 0) - SIGN(q) = ZPOS; - - if(r) - *r = rem; - - if(q) - s_mp_exch(&qp, q); - - mp_clear(&qp); - return res; - -} /* end mp_div_d() */ - -/* }}} */ - -/* {{{ mp_div_2(a, c) */ - -/* - mp_div_2(a, c) - - Compute c = a / 2, disregarding the remainder. - */ - -mp_err mp_div_2(const mp_int *a, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && c != NULL, MP_BADARG); - - if((res = mp_copy(a, c)) != MP_OKAY) - return res; - - s_mp_div_2(c); - - return MP_OKAY; - -} /* end mp_div_2() */ - -/* }}} */ - -/* {{{ mp_expt_d(a, d, b) */ - -mp_err mp_expt_d(const mp_int *a, mp_digit d, mp_int *c) -{ - mp_int s, x; - mp_err res; - - ARGCHK(a != NULL && c != NULL, MP_BADARG); - - if((res = mp_init(&s, FLAG(a))) != MP_OKAY) - return res; - if((res = mp_init_copy(&x, a)) != MP_OKAY) - goto X; - - DIGIT(&s, 0) = 1; - - while(d != 0) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY) - goto CLEANUP; - } - - d /= 2; - - if((res = s_mp_sqr(&x)) != MP_OKAY) - goto CLEANUP; - } - - s.flag = (mp_sign)0; - s_mp_exch(&s, c); - -CLEANUP: - mp_clear(&x); -X: - mp_clear(&s); - - return res; - -} /* end mp_expt_d() */ - -/* }}} */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ Full arithmetic */ - -/* {{{ mp_abs(a, b) */ - -/* - mp_abs(a, b) - - Compute b = |a|. 'a' and 'b' may be identical. - */ - -mp_err mp_abs(const mp_int *a, mp_int *b) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_copy(a, b)) != MP_OKAY) - return res; - - SIGN(b) = ZPOS; - - return MP_OKAY; - -} /* end mp_abs() */ - -/* }}} */ - -/* {{{ mp_neg(a, b) */ - -/* - mp_neg(a, b) - - Compute b = -a. 'a' and 'b' may be identical. - */ - -mp_err mp_neg(const mp_int *a, mp_int *b) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_copy(a, b)) != MP_OKAY) - return res; - - if(s_mp_cmp_d(b, 0) == MP_EQ) - SIGN(b) = ZPOS; - else - SIGN(b) = (SIGN(b) == NEG) ? ZPOS : NEG; - - return MP_OKAY; - -} /* end mp_neg() */ - -/* }}} */ - -/* {{{ mp_add(a, b, c) */ - -/* - mp_add(a, b, c) - - Compute c = a + b. All parameters may be identical. - */ - -mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if(SIGN(a) == SIGN(b)) { /* same sign: add values, keep sign */ - MP_CHECKOK( s_mp_add_3arg(a, b, c) ); - } else if(s_mp_cmp(a, b) >= 0) { /* different sign: |a| >= |b| */ - MP_CHECKOK( s_mp_sub_3arg(a, b, c) ); - } else { /* different sign: |a| < |b| */ - MP_CHECKOK( s_mp_sub_3arg(b, a, c) ); - } - - if (s_mp_cmp_d(c, 0) == MP_EQ) - SIGN(c) = ZPOS; - -CLEANUP: - return res; - -} /* end mp_add() */ - -/* }}} */ - -/* {{{ mp_sub(a, b, c) */ - -/* - mp_sub(a, b, c) - - Compute c = a - b. All parameters may be identical. - */ - -mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_err res; - int magDiff; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if (a == b) { - mp_zero(c); - return MP_OKAY; - } - - if (MP_SIGN(a) != MP_SIGN(b)) { - MP_CHECKOK( s_mp_add_3arg(a, b, c) ); - } else if (!(magDiff = s_mp_cmp(a, b))) { - mp_zero(c); - res = MP_OKAY; - } else if (magDiff > 0) { - MP_CHECKOK( s_mp_sub_3arg(a, b, c) ); - } else { - MP_CHECKOK( s_mp_sub_3arg(b, a, c) ); - MP_SIGN(c) = !MP_SIGN(a); - } - - if (s_mp_cmp_d(c, 0) == MP_EQ) - MP_SIGN(c) = MP_ZPOS; - -CLEANUP: - return res; - -} /* end mp_sub() */ - -/* }}} */ - -/* {{{ mp_mul(a, b, c) */ - -/* - mp_mul(a, b, c) - - Compute c = a * b. All parameters may be identical. - */ -mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int * c) -{ - mp_digit *pb; - mp_int tmp; - mp_err res; - mp_size ib; - mp_size useda, usedb; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if (a == c) { - if ((res = mp_init_copy(&tmp, a)) != MP_OKAY) - return res; - if (a == b) - b = &tmp; - a = &tmp; - } else if (b == c) { - if ((res = mp_init_copy(&tmp, b)) != MP_OKAY) - return res; - b = &tmp; - } else { - MP_DIGITS(&tmp) = 0; - } - - if (MP_USED(a) < MP_USED(b)) { - const mp_int *xch = b; /* switch a and b, to do fewer outer loops */ - b = a; - a = xch; - } - - MP_USED(c) = 1; MP_DIGIT(c, 0) = 0; - if((res = s_mp_pad(c, USED(a) + USED(b))) != MP_OKAY) - goto CLEANUP; - -#ifdef NSS_USE_COMBA - if ((MP_USED(a) == MP_USED(b)) && IS_POWER_OF_2(MP_USED(b))) { - if (MP_USED(a) == 4) { - s_mp_mul_comba_4(a, b, c); - goto CLEANUP; - } - if (MP_USED(a) == 8) { - s_mp_mul_comba_8(a, b, c); - goto CLEANUP; - } - if (MP_USED(a) == 16) { - s_mp_mul_comba_16(a, b, c); - goto CLEANUP; - } - if (MP_USED(a) == 32) { - s_mp_mul_comba_32(a, b, c); - goto CLEANUP; - } - } -#endif - - pb = MP_DIGITS(b); - s_mpv_mul_d(MP_DIGITS(a), MP_USED(a), *pb++, MP_DIGITS(c)); - - /* Outer loop: Digits of b */ - useda = MP_USED(a); - usedb = MP_USED(b); - for (ib = 1; ib < usedb; ib++) { - mp_digit b_i = *pb++; - - /* Inner product: Digits of a */ - if (b_i) - s_mpv_mul_d_add(MP_DIGITS(a), useda, b_i, MP_DIGITS(c) + ib); - else - MP_DIGIT(c, ib + useda) = b_i; - } - - s_mp_clamp(c); - - if(SIGN(a) == SIGN(b) || s_mp_cmp_d(c, 0) == MP_EQ) - SIGN(c) = ZPOS; - else - SIGN(c) = NEG; - -CLEANUP: - mp_clear(&tmp); - return res; -} /* end mp_mul() */ - -/* }}} */ - -/* {{{ mp_sqr(a, sqr) */ - -#if MP_SQUARE -/* - Computes the square of a. This can be done more - efficiently than a general multiplication, because many of the - computation steps are redundant when squaring. The inner product - step is a bit more complicated, but we save a fair number of - iterations of the multiplication loop. - */ - -/* sqr = a^2; Caller provides both a and tmp; */ -mp_err mp_sqr(const mp_int *a, mp_int *sqr) -{ - mp_digit *pa; - mp_digit d; - mp_err res; - mp_size ix; - mp_int tmp; - int count; - - ARGCHK(a != NULL && sqr != NULL, MP_BADARG); - - if (a == sqr) { - if((res = mp_init_copy(&tmp, a)) != MP_OKAY) - return res; - a = &tmp; - } else { - DIGITS(&tmp) = 0; - res = MP_OKAY; - } - - ix = 2 * MP_USED(a); - if (ix > MP_ALLOC(sqr)) { - MP_USED(sqr) = 1; - MP_CHECKOK( s_mp_grow(sqr, ix) ); - } - MP_USED(sqr) = ix; - MP_DIGIT(sqr, 0) = 0; - -#ifdef NSS_USE_COMBA - if (IS_POWER_OF_2(MP_USED(a))) { - if (MP_USED(a) == 4) { - s_mp_sqr_comba_4(a, sqr); - goto CLEANUP; - } - if (MP_USED(a) == 8) { - s_mp_sqr_comba_8(a, sqr); - goto CLEANUP; - } - if (MP_USED(a) == 16) { - s_mp_sqr_comba_16(a, sqr); - goto CLEANUP; - } - if (MP_USED(a) == 32) { - s_mp_sqr_comba_32(a, sqr); - goto CLEANUP; - } - } -#endif - - pa = MP_DIGITS(a); - count = MP_USED(a) - 1; - if (count > 0) { - d = *pa++; - s_mpv_mul_d(pa, count, d, MP_DIGITS(sqr) + 1); - for (ix = 3; --count > 0; ix += 2) { - d = *pa++; - s_mpv_mul_d_add(pa, count, d, MP_DIGITS(sqr) + ix); - } /* for(ix ...) */ - MP_DIGIT(sqr, MP_USED(sqr)-1) = 0; /* above loop stopped short of this. */ - - /* now sqr *= 2 */ - s_mp_mul_2(sqr); - } else { - MP_DIGIT(sqr, 1) = 0; - } - - /* now add the squares of the digits of a to sqr. */ - s_mpv_sqr_add_prop(MP_DIGITS(a), MP_USED(a), MP_DIGITS(sqr)); - - SIGN(sqr) = ZPOS; - s_mp_clamp(sqr); - -CLEANUP: - mp_clear(&tmp); - return res; - -} /* end mp_sqr() */ -#endif - -/* }}} */ - -/* {{{ mp_div(a, b, q, r) */ - -/* - mp_div(a, b, q, r) - - Compute q = a / b and r = a mod b. Input parameters may be re-used - as output parameters. If q or r is NULL, that portion of the - computation will be discarded (although it will still be computed) - */ -mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r) -{ - mp_err res; - mp_int *pQ, *pR; - mp_int qtmp, rtmp, btmp; - int cmp; - mp_sign signA; - mp_sign signB; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - signA = MP_SIGN(a); - signB = MP_SIGN(b); - - if(mp_cmp_z(b) == MP_EQ) - return MP_RANGE; - - DIGITS(&qtmp) = 0; - DIGITS(&rtmp) = 0; - DIGITS(&btmp) = 0; - - /* Set up some temporaries... */ - if (!r || r == a || r == b) { - MP_CHECKOK( mp_init_copy(&rtmp, a) ); - pR = &rtmp; - } else { - MP_CHECKOK( mp_copy(a, r) ); - pR = r; - } - - if (!q || q == a || q == b) { - MP_CHECKOK( mp_init_size(&qtmp, MP_USED(a), FLAG(a)) ); - pQ = &qtmp; - } else { - MP_CHECKOK( s_mp_pad(q, MP_USED(a)) ); - pQ = q; - mp_zero(pQ); - } - - /* - If |a| <= |b|, we can compute the solution without division; - otherwise, we actually do the work required. - */ - if ((cmp = s_mp_cmp(a, b)) <= 0) { - if (cmp) { - /* r was set to a above. */ - mp_zero(pQ); - } else { - mp_set(pQ, 1); - mp_zero(pR); - } - } else { - MP_CHECKOK( mp_init_copy(&btmp, b) ); - MP_CHECKOK( s_mp_div(pR, &btmp, pQ) ); - } - - /* Compute the signs for the output */ - MP_SIGN(pR) = signA; /* Sr = Sa */ - /* Sq = ZPOS if Sa == Sb */ /* Sq = NEG if Sa != Sb */ - MP_SIGN(pQ) = (signA == signB) ? ZPOS : NEG; - - if(s_mp_cmp_d(pQ, 0) == MP_EQ) - SIGN(pQ) = ZPOS; - if(s_mp_cmp_d(pR, 0) == MP_EQ) - SIGN(pR) = ZPOS; - - /* Copy output, if it is needed */ - if(q && q != pQ) - s_mp_exch(pQ, q); - - if(r && r != pR) - s_mp_exch(pR, r); - -CLEANUP: - mp_clear(&btmp); - mp_clear(&rtmp); - mp_clear(&qtmp); - - return res; - -} /* end mp_div() */ - -/* }}} */ - -/* {{{ mp_div_2d(a, d, q, r) */ - -mp_err mp_div_2d(const mp_int *a, mp_digit d, mp_int *q, mp_int *r) -{ - mp_err res; - - ARGCHK(a != NULL, MP_BADARG); - - if(q) { - if((res = mp_copy(a, q)) != MP_OKAY) - return res; - } - if(r) { - if((res = mp_copy(a, r)) != MP_OKAY) - return res; - } - if(q) { - s_mp_div_2d(q, d); - } - if(r) { - s_mp_mod_2d(r, d); - } - - return MP_OKAY; - -} /* end mp_div_2d() */ - -/* }}} */ - -/* {{{ mp_expt(a, b, c) */ - -/* - mp_expt(a, b, c) - - Compute c = a ** b, that is, raise a to the b power. Uses a - standard iterative square-and-multiply technique. - */ - -mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c) -{ - mp_int s, x; - mp_err res; - mp_digit d; - unsigned int dig, bit; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if(mp_cmp_z(b) < 0) - return MP_RANGE; - - if((res = mp_init(&s, FLAG(a))) != MP_OKAY) - return res; - - mp_set(&s, 1); - - if((res = mp_init_copy(&x, a)) != MP_OKAY) - goto X; - - /* Loop over low-order digits in ascending order */ - for(dig = 0; dig < (USED(b) - 1); dig++) { - d = DIGIT(b, dig); - - /* Loop over bits of each non-maximal digit */ - for(bit = 0; bit < DIGIT_BIT; bit++) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY) - goto CLEANUP; - } - - d >>= 1; - - if((res = s_mp_sqr(&x)) != MP_OKAY) - goto CLEANUP; - } - } - - /* Consider now the last digit... */ - d = DIGIT(b, dig); - - while(d) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY) - goto CLEANUP; - } - - d >>= 1; - - if((res = s_mp_sqr(&x)) != MP_OKAY) - goto CLEANUP; - } - - if(mp_iseven(b)) - SIGN(&s) = SIGN(a); - - res = mp_copy(&s, c); - -CLEANUP: - mp_clear(&x); -X: - mp_clear(&s); - - return res; - -} /* end mp_expt() */ - -/* }}} */ - -/* {{{ mp_2expt(a, k) */ - -/* Compute a = 2^k */ - -mp_err mp_2expt(mp_int *a, mp_digit k) -{ - ARGCHK(a != NULL, MP_BADARG); - - return s_mp_2expt(a, k); - -} /* end mp_2expt() */ - -/* }}} */ - -/* {{{ mp_mod(a, m, c) */ - -/* - mp_mod(a, m, c) - - Compute c = a (mod m). Result will always be 0 <= c < m. - */ - -mp_err mp_mod(const mp_int *a, const mp_int *m, mp_int *c) -{ - mp_err res; - int mag; - - ARGCHK(a != NULL && m != NULL && c != NULL, MP_BADARG); - - if(SIGN(m) == NEG) - return MP_RANGE; - - /* - If |a| > m, we need to divide to get the remainder and take the - absolute value. - - If |a| < m, we don't need to do any division, just copy and adjust - the sign (if a is negative). - - If |a| == m, we can simply set the result to zero. - - This order is intended to minimize the average path length of the - comparison chain on common workloads -- the most frequent cases are - that |a| != m, so we do those first. - */ - if((mag = s_mp_cmp(a, m)) > 0) { - if((res = mp_div(a, m, NULL, c)) != MP_OKAY) - return res; - - if(SIGN(c) == NEG) { - if((res = mp_add(c, m, c)) != MP_OKAY) - return res; - } - - } else if(mag < 0) { - if((res = mp_copy(a, c)) != MP_OKAY) - return res; - - if(mp_cmp_z(a) < 0) { - if((res = mp_add(c, m, c)) != MP_OKAY) - return res; - - } - - } else { - mp_zero(c); - - } - - return MP_OKAY; - -} /* end mp_mod() */ - -/* }}} */ - -/* {{{ mp_mod_d(a, d, c) */ - -/* - mp_mod_d(a, d, c) - - Compute c = a (mod d). Result will always be 0 <= c < d - */ -mp_err mp_mod_d(const mp_int *a, mp_digit d, mp_digit *c) -{ - mp_err res; - mp_digit rem; - - ARGCHK(a != NULL && c != NULL, MP_BADARG); - - if(s_mp_cmp_d(a, d) > 0) { - if((res = mp_div_d(a, d, NULL, &rem)) != MP_OKAY) - return res; - - } else { - if(SIGN(a) == NEG) - rem = d - DIGIT(a, 0); - else - rem = DIGIT(a, 0); - } - - if(c) - *c = rem; - - return MP_OKAY; - -} /* end mp_mod_d() */ - -/* }}} */ - -/* {{{ mp_sqrt(a, b) */ - -/* - mp_sqrt(a, b) - - Compute the integer square root of a, and store the result in b. - Uses an integer-arithmetic version of Newton's iterative linear - approximation technique to determine this value; the result has the - following two properties: - - b^2 <= a - (b+1)^2 >= a - - It is a range error to pass a negative value. - */ -mp_err mp_sqrt(const mp_int *a, mp_int *b) -{ - mp_int x, t; - mp_err res; - mp_size used; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - /* Cannot take square root of a negative value */ - if(SIGN(a) == NEG) - return MP_RANGE; - - /* Special cases for zero and one, trivial */ - if(mp_cmp_d(a, 1) <= 0) - return mp_copy(a, b); - - /* Initialize the temporaries we'll use below */ - if((res = mp_init_size(&t, USED(a), FLAG(a))) != MP_OKAY) - return res; - - /* Compute an initial guess for the iteration as a itself */ - if((res = mp_init_copy(&x, a)) != MP_OKAY) - goto X; - - used = MP_USED(&x); - if (used > 1) { - s_mp_rshd(&x, used / 2); - } - - for(;;) { - /* t = (x * x) - a */ - mp_copy(&x, &t); /* can't fail, t is big enough for original x */ - if((res = mp_sqr(&t, &t)) != MP_OKAY || - (res = mp_sub(&t, a, &t)) != MP_OKAY) - goto CLEANUP; - - /* t = t / 2x */ - s_mp_mul_2(&x); - if((res = mp_div(&t, &x, &t, NULL)) != MP_OKAY) - goto CLEANUP; - s_mp_div_2(&x); - - /* Terminate the loop, if the quotient is zero */ - if(mp_cmp_z(&t) == MP_EQ) - break; - - /* x = x - t */ - if((res = mp_sub(&x, &t, &x)) != MP_OKAY) - goto CLEANUP; - - } - - /* Copy result to output parameter */ - mp_sub_d(&x, 1, &x); - s_mp_exch(&x, b); - - CLEANUP: - mp_clear(&x); - X: - mp_clear(&t); - - return res; - -} /* end mp_sqrt() */ - -/* }}} */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ Modular arithmetic */ - -#if MP_MODARITH -/* {{{ mp_addmod(a, b, m, c) */ - -/* - mp_addmod(a, b, m, c) - - Compute c = (a + b) mod m - */ - -mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG); - - if((res = mp_add(a, b, c)) != MP_OKAY) - return res; - if((res = mp_mod(c, m, c)) != MP_OKAY) - return res; - - return MP_OKAY; - -} - -/* }}} */ - -/* {{{ mp_submod(a, b, m, c) */ - -/* - mp_submod(a, b, m, c) - - Compute c = (a - b) mod m - */ - -mp_err mp_submod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG); - - if((res = mp_sub(a, b, c)) != MP_OKAY) - return res; - if((res = mp_mod(c, m, c)) != MP_OKAY) - return res; - - return MP_OKAY; - -} - -/* }}} */ - -/* {{{ mp_mulmod(a, b, m, c) */ - -/* - mp_mulmod(a, b, m, c) - - Compute c = (a * b) mod m - */ - -mp_err mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL && m != NULL && c != NULL, MP_BADARG); - - if((res = mp_mul(a, b, c)) != MP_OKAY) - return res; - if((res = mp_mod(c, m, c)) != MP_OKAY) - return res; - - return MP_OKAY; - -} - -/* }}} */ - -/* {{{ mp_sqrmod(a, m, c) */ - -#if MP_SQUARE -mp_err mp_sqrmod(const mp_int *a, const mp_int *m, mp_int *c) -{ - mp_err res; - - ARGCHK(a != NULL && m != NULL && c != NULL, MP_BADARG); - - if((res = mp_sqr(a, c)) != MP_OKAY) - return res; - if((res = mp_mod(c, m, c)) != MP_OKAY) - return res; - - return MP_OKAY; - -} /* end mp_sqrmod() */ -#endif - -/* }}} */ - -/* {{{ s_mp_exptmod(a, b, m, c) */ - -/* - s_mp_exptmod(a, b, m, c) - - Compute c = (a ** b) mod m. Uses a standard square-and-multiply - method with modular reductions at each step. (This is basically the - same code as mp_expt(), except for the addition of the reductions) - - The modular reductions are done using Barrett's algorithm (see - s_mp_reduce() below for details) - */ - -mp_err s_mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c) -{ - mp_int s, x, mu; - mp_err res; - mp_digit d; - unsigned int dig, bit; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if(mp_cmp_z(b) < 0 || mp_cmp_z(m) <= 0) - return MP_RANGE; - - if((res = mp_init(&s, FLAG(a))) != MP_OKAY) - return res; - if((res = mp_init_copy(&x, a)) != MP_OKAY || - (res = mp_mod(&x, m, &x)) != MP_OKAY) - goto X; - if((res = mp_init(&mu, FLAG(a))) != MP_OKAY) - goto MU; - - mp_set(&s, 1); - - /* mu = b^2k / m */ - s_mp_add_d(&mu, 1); - s_mp_lshd(&mu, 2 * USED(m)); - if((res = mp_div(&mu, m, &mu, NULL)) != MP_OKAY) - goto CLEANUP; - - /* Loop over digits of b in ascending order, except highest order */ - for(dig = 0; dig < (USED(b) - 1); dig++) { - d = DIGIT(b, dig); - - /* Loop over the bits of the lower-order digits */ - for(bit = 0; bit < DIGIT_BIT; bit++) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY) - goto CLEANUP; - if((res = s_mp_reduce(&s, m, &mu)) != MP_OKAY) - goto CLEANUP; - } - - d >>= 1; - - if((res = s_mp_sqr(&x)) != MP_OKAY) - goto CLEANUP; - if((res = s_mp_reduce(&x, m, &mu)) != MP_OKAY) - goto CLEANUP; - } - } - - /* Now do the last digit... */ - d = DIGIT(b, dig); - - while(d) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY) - goto CLEANUP; - if((res = s_mp_reduce(&s, m, &mu)) != MP_OKAY) - goto CLEANUP; - } - - d >>= 1; - - if((res = s_mp_sqr(&x)) != MP_OKAY) - goto CLEANUP; - if((res = s_mp_reduce(&x, m, &mu)) != MP_OKAY) - goto CLEANUP; - } - - s_mp_exch(&s, c); - - CLEANUP: - mp_clear(&mu); - MU: - mp_clear(&x); - X: - mp_clear(&s); - - return res; - -} /* end s_mp_exptmod() */ - -/* }}} */ - -/* {{{ mp_exptmod_d(a, d, m, c) */ - -mp_err mp_exptmod_d(const mp_int *a, mp_digit d, const mp_int *m, mp_int *c) -{ - mp_int s, x; - mp_err res; - - ARGCHK(a != NULL && c != NULL, MP_BADARG); - - if((res = mp_init(&s, FLAG(a))) != MP_OKAY) - return res; - if((res = mp_init_copy(&x, a)) != MP_OKAY) - goto X; - - mp_set(&s, 1); - - while(d != 0) { - if(d & 1) { - if((res = s_mp_mul(&s, &x)) != MP_OKAY || - (res = mp_mod(&s, m, &s)) != MP_OKAY) - goto CLEANUP; - } - - d /= 2; - - if((res = s_mp_sqr(&x)) != MP_OKAY || - (res = mp_mod(&x, m, &x)) != MP_OKAY) - goto CLEANUP; - } - - s.flag = (mp_sign)0; - s_mp_exch(&s, c); - -CLEANUP: - mp_clear(&x); -X: - mp_clear(&s); - - return res; - -} /* end mp_exptmod_d() */ - -/* }}} */ -#endif /* if MP_MODARITH */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ Comparison functions */ - -/* {{{ mp_cmp_z(a) */ - -/* - mp_cmp_z(a) - - Compare a <=> 0. Returns <0 if a<0, 0 if a=0, >0 if a>0. - */ - -int mp_cmp_z(const mp_int *a) -{ - if(SIGN(a) == NEG) - return MP_LT; - else if(USED(a) == 1 && DIGIT(a, 0) == 0) - return MP_EQ; - else - return MP_GT; - -} /* end mp_cmp_z() */ - -/* }}} */ - -/* {{{ mp_cmp_d(a, d) */ - -/* - mp_cmp_d(a, d) - - Compare a <=> d. Returns <0 if a0 if a>d - */ - -int mp_cmp_d(const mp_int *a, mp_digit d) -{ - ARGCHK(a != NULL, MP_EQ); - - if(SIGN(a) == NEG) - return MP_LT; - - return s_mp_cmp_d(a, d); - -} /* end mp_cmp_d() */ - -/* }}} */ - -/* {{{ mp_cmp(a, b) */ - -int mp_cmp(const mp_int *a, const mp_int *b) -{ - ARGCHK(a != NULL && b != NULL, MP_EQ); - - if(SIGN(a) == SIGN(b)) { - int mag; - - if((mag = s_mp_cmp(a, b)) == MP_EQ) - return MP_EQ; - - if(SIGN(a) == ZPOS) - return mag; - else - return -mag; - - } else if(SIGN(a) == ZPOS) { - return MP_GT; - } else { - return MP_LT; - } - -} /* end mp_cmp() */ - -/* }}} */ - -/* {{{ mp_cmp_mag(a, b) */ - -/* - mp_cmp_mag(a, b) - - Compares |a| <=> |b|, and returns an appropriate comparison result - */ - -int mp_cmp_mag(mp_int *a, mp_int *b) -{ - ARGCHK(a != NULL && b != NULL, MP_EQ); - - return s_mp_cmp(a, b); - -} /* end mp_cmp_mag() */ - -/* }}} */ - -/* {{{ mp_cmp_int(a, z, kmflag) */ - -/* - This just converts z to an mp_int, and uses the existing comparison - routines. This is sort of inefficient, but it's not clear to me how - frequently this wil get used anyway. For small positive constants, - you can always use mp_cmp_d(), and for zero, there is mp_cmp_z(). - */ -int mp_cmp_int(const mp_int *a, long z, int kmflag) -{ - mp_int tmp; - int out; - - ARGCHK(a != NULL, MP_EQ); - - mp_init(&tmp, kmflag); mp_set_int(&tmp, z); - out = mp_cmp(a, &tmp); - mp_clear(&tmp); - - return out; - -} /* end mp_cmp_int() */ - -/* }}} */ - -/* {{{ mp_isodd(a) */ - -/* - mp_isodd(a) - - Returns a true (non-zero) value if a is odd, false (zero) otherwise. - */ -int mp_isodd(const mp_int *a) -{ - ARGCHK(a != NULL, 0); - - return (int)(DIGIT(a, 0) & 1); - -} /* end mp_isodd() */ - -/* }}} */ - -/* {{{ mp_iseven(a) */ - -int mp_iseven(const mp_int *a) -{ - return !mp_isodd(a); - -} /* end mp_iseven() */ - -/* }}} */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ Number theoretic functions */ - -#if MP_NUMTH -/* {{{ mp_gcd(a, b, c) */ - -/* - Like the old mp_gcd() function, except computes the GCD using the - binary algorithm due to Josef Stein in 1961 (via Knuth). - */ -mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c) -{ - mp_err res; - mp_int u, v, t; - mp_size k = 0; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if(mp_cmp_z(a) == MP_EQ && mp_cmp_z(b) == MP_EQ) - return MP_RANGE; - if(mp_cmp_z(a) == MP_EQ) { - return mp_copy(b, c); - } else if(mp_cmp_z(b) == MP_EQ) { - return mp_copy(a, c); - } - - if((res = mp_init(&t, FLAG(a))) != MP_OKAY) - return res; - if((res = mp_init_copy(&u, a)) != MP_OKAY) - goto U; - if((res = mp_init_copy(&v, b)) != MP_OKAY) - goto V; - - SIGN(&u) = ZPOS; - SIGN(&v) = ZPOS; - - /* Divide out common factors of 2 until at least 1 of a, b is even */ - while(mp_iseven(&u) && mp_iseven(&v)) { - s_mp_div_2(&u); - s_mp_div_2(&v); - ++k; - } - - /* Initialize t */ - if(mp_isodd(&u)) { - if((res = mp_copy(&v, &t)) != MP_OKAY) - goto CLEANUP; - - /* t = -v */ - if(SIGN(&v) == ZPOS) - SIGN(&t) = NEG; - else - SIGN(&t) = ZPOS; - - } else { - if((res = mp_copy(&u, &t)) != MP_OKAY) - goto CLEANUP; - - } - - for(;;) { - while(mp_iseven(&t)) { - s_mp_div_2(&t); - } - - if(mp_cmp_z(&t) == MP_GT) { - if((res = mp_copy(&t, &u)) != MP_OKAY) - goto CLEANUP; - - } else { - if((res = mp_copy(&t, &v)) != MP_OKAY) - goto CLEANUP; - - /* v = -t */ - if(SIGN(&t) == ZPOS) - SIGN(&v) = NEG; - else - SIGN(&v) = ZPOS; - } - - if((res = mp_sub(&u, &v, &t)) != MP_OKAY) - goto CLEANUP; - - if(s_mp_cmp_d(&t, 0) == MP_EQ) - break; - } - - s_mp_2expt(&v, k); /* v = 2^k */ - res = mp_mul(&u, &v, c); /* c = u * v */ - - CLEANUP: - mp_clear(&v); - V: - mp_clear(&u); - U: - mp_clear(&t); - - return res; - -} /* end mp_gcd() */ - -/* }}} */ - -/* {{{ mp_lcm(a, b, c) */ - -/* We compute the least common multiple using the rule: - - ab = [a, b](a, b) - - ... by computing the product, and dividing out the gcd. - */ - -mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c) -{ - mp_int gcd, prod; - mp_err res; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - /* Set up temporaries */ - if((res = mp_init(&gcd, FLAG(a))) != MP_OKAY) - return res; - if((res = mp_init(&prod, FLAG(a))) != MP_OKAY) - goto GCD; - - if((res = mp_mul(a, b, &prod)) != MP_OKAY) - goto CLEANUP; - if((res = mp_gcd(a, b, &gcd)) != MP_OKAY) - goto CLEANUP; - - res = mp_div(&prod, &gcd, c, NULL); - - CLEANUP: - mp_clear(&prod); - GCD: - mp_clear(&gcd); - - return res; - -} /* end mp_lcm() */ - -/* }}} */ - -/* {{{ mp_xgcd(a, b, g, x, y) */ - -/* - mp_xgcd(a, b, g, x, y) - - Compute g = (a, b) and values x and y satisfying Bezout's identity - (that is, ax + by = g). This uses the binary extended GCD algorithm - based on the Stein algorithm used for mp_gcd() - See algorithm 14.61 in Handbook of Applied Cryptogrpahy. - */ - -mp_err mp_xgcd(const mp_int *a, const mp_int *b, mp_int *g, mp_int *x, mp_int *y) -{ - mp_int gx, xc, yc, u, v, A, B, C, D; - mp_int *clean[9]; - mp_err res; - int last = -1; - - if(mp_cmp_z(b) == 0) - return MP_RANGE; - - /* Initialize all these variables we need */ - MP_CHECKOK( mp_init(&u, FLAG(a)) ); - clean[++last] = &u; - MP_CHECKOK( mp_init(&v, FLAG(a)) ); - clean[++last] = &v; - MP_CHECKOK( mp_init(&gx, FLAG(a)) ); - clean[++last] = &gx; - MP_CHECKOK( mp_init(&A, FLAG(a)) ); - clean[++last] = &A; - MP_CHECKOK( mp_init(&B, FLAG(a)) ); - clean[++last] = &B; - MP_CHECKOK( mp_init(&C, FLAG(a)) ); - clean[++last] = &C; - MP_CHECKOK( mp_init(&D, FLAG(a)) ); - clean[++last] = &D; - MP_CHECKOK( mp_init_copy(&xc, a) ); - clean[++last] = &xc; - mp_abs(&xc, &xc); - MP_CHECKOK( mp_init_copy(&yc, b) ); - clean[++last] = &yc; - mp_abs(&yc, &yc); - - mp_set(&gx, 1); - - /* Divide by two until at least one of them is odd */ - while(mp_iseven(&xc) && mp_iseven(&yc)) { - mp_size nx = mp_trailing_zeros(&xc); - mp_size ny = mp_trailing_zeros(&yc); - mp_size n = MP_MIN(nx, ny); - s_mp_div_2d(&xc,n); - s_mp_div_2d(&yc,n); - MP_CHECKOK( s_mp_mul_2d(&gx,n) ); - } - - mp_copy(&xc, &u); - mp_copy(&yc, &v); - mp_set(&A, 1); mp_set(&D, 1); - - /* Loop through binary GCD algorithm */ - do { - while(mp_iseven(&u)) { - s_mp_div_2(&u); - - if(mp_iseven(&A) && mp_iseven(&B)) { - s_mp_div_2(&A); s_mp_div_2(&B); - } else { - MP_CHECKOK( mp_add(&A, &yc, &A) ); - s_mp_div_2(&A); - MP_CHECKOK( mp_sub(&B, &xc, &B) ); - s_mp_div_2(&B); - } - } - - while(mp_iseven(&v)) { - s_mp_div_2(&v); - - if(mp_iseven(&C) && mp_iseven(&D)) { - s_mp_div_2(&C); s_mp_div_2(&D); - } else { - MP_CHECKOK( mp_add(&C, &yc, &C) ); - s_mp_div_2(&C); - MP_CHECKOK( mp_sub(&D, &xc, &D) ); - s_mp_div_2(&D); - } - } - - if(mp_cmp(&u, &v) >= 0) { - MP_CHECKOK( mp_sub(&u, &v, &u) ); - MP_CHECKOK( mp_sub(&A, &C, &A) ); - MP_CHECKOK( mp_sub(&B, &D, &B) ); - } else { - MP_CHECKOK( mp_sub(&v, &u, &v) ); - MP_CHECKOK( mp_sub(&C, &A, &C) ); - MP_CHECKOK( mp_sub(&D, &B, &D) ); - } - } while (mp_cmp_z(&u) != 0); - - /* copy results to output */ - if(x) - MP_CHECKOK( mp_copy(&C, x) ); - - if(y) - MP_CHECKOK( mp_copy(&D, y) ); - - if(g) - MP_CHECKOK( mp_mul(&gx, &v, g) ); - - CLEANUP: - while(last >= 0) - mp_clear(clean[last--]); - - return res; - -} /* end mp_xgcd() */ - -/* }}} */ - -mp_size mp_trailing_zeros(const mp_int *mp) -{ - mp_digit d; - mp_size n = 0; - unsigned int ix; - - if (!mp || !MP_DIGITS(mp) || !mp_cmp_z(mp)) - return n; - - for (ix = 0; !(d = MP_DIGIT(mp,ix)) && (ix < MP_USED(mp)); ++ix) - n += MP_DIGIT_BIT; - if (!d) - return 0; /* shouldn't happen, but ... */ -#if !defined(MP_USE_UINT_DIGIT) - if (!(d & 0xffffffffU)) { - d >>= 32; - n += 32; - } -#endif - if (!(d & 0xffffU)) { - d >>= 16; - n += 16; - } - if (!(d & 0xffU)) { - d >>= 8; - n += 8; - } - if (!(d & 0xfU)) { - d >>= 4; - n += 4; - } - if (!(d & 0x3U)) { - d >>= 2; - n += 2; - } - if (!(d & 0x1U)) { - d >>= 1; - n += 1; - } -#if MP_ARGCHK == 2 - assert(0 != (d & 1)); -#endif - return n; -} - -/* Given a and prime p, computes c and k such that a*c == 2**k (mod p). -** Returns k (positive) or error (negative). -** This technique from the paper "Fast Modular Reciprocals" (unpublished) -** by Richard Schroeppel (a.k.a. Captain Nemo). -*/ -mp_err s_mp_almost_inverse(const mp_int *a, const mp_int *p, mp_int *c) -{ - mp_err res; - mp_err k = 0; - mp_int d, f, g; - - ARGCHK(a && p && c, MP_BADARG); - - MP_DIGITS(&d) = 0; - MP_DIGITS(&f) = 0; - MP_DIGITS(&g) = 0; - MP_CHECKOK( mp_init(&d, FLAG(a)) ); - MP_CHECKOK( mp_init_copy(&f, a) ); /* f = a */ - MP_CHECKOK( mp_init_copy(&g, p) ); /* g = p */ - - mp_set(c, 1); - mp_zero(&d); - - if (mp_cmp_z(&f) == 0) { - res = MP_UNDEF; - } else - for (;;) { - int diff_sign; - while (mp_iseven(&f)) { - mp_size n = mp_trailing_zeros(&f); - if (!n) { - res = MP_UNDEF; - goto CLEANUP; - } - s_mp_div_2d(&f, n); - MP_CHECKOK( s_mp_mul_2d(&d, n) ); - k += n; - } - if (mp_cmp_d(&f, 1) == MP_EQ) { /* f == 1 */ - res = k; - break; - } - diff_sign = mp_cmp(&f, &g); - if (diff_sign < 0) { /* f < g */ - s_mp_exch(&f, &g); - s_mp_exch(c, &d); - } else if (diff_sign == 0) { /* f == g */ - res = MP_UNDEF; /* a and p are not relatively prime */ - break; - } - if ((MP_DIGIT(&f,0) % 4) == (MP_DIGIT(&g,0) % 4)) { - MP_CHECKOK( mp_sub(&f, &g, &f) ); /* f = f - g */ - MP_CHECKOK( mp_sub(c, &d, c) ); /* c = c - d */ - } else { - MP_CHECKOK( mp_add(&f, &g, &f) ); /* f = f + g */ - MP_CHECKOK( mp_add(c, &d, c) ); /* c = c + d */ - } - } - if (res >= 0) { - if (s_mp_cmp(c, p) >= 0) { - MP_CHECKOK( mp_div(c, p, NULL, c)); - } - if (MP_SIGN(c) != MP_ZPOS) { - MP_CHECKOK( mp_add(c, p, c) ); - } - res = k; - } - -CLEANUP: - mp_clear(&d); - mp_clear(&f); - mp_clear(&g); - return res; -} - -/* Compute T = (P ** -1) mod MP_RADIX. Also works for 16-bit mp_digits. -** This technique from the paper "Fast Modular Reciprocals" (unpublished) -** by Richard Schroeppel (a.k.a. Captain Nemo). -*/ -mp_digit s_mp_invmod_radix(mp_digit P) -{ - mp_digit T = P; - T *= 2 - (P * T); - T *= 2 - (P * T); - T *= 2 - (P * T); - T *= 2 - (P * T); -#if !defined(MP_USE_UINT_DIGIT) - T *= 2 - (P * T); - T *= 2 - (P * T); -#endif - return T; -} - -/* Given c, k, and prime p, where a*c == 2**k (mod p), -** Compute x = (a ** -1) mod p. This is similar to Montgomery reduction. -** This technique from the paper "Fast Modular Reciprocals" (unpublished) -** by Richard Schroeppel (a.k.a. Captain Nemo). -*/ -mp_err s_mp_fixup_reciprocal(const mp_int *c, const mp_int *p, int k, mp_int *x) -{ - int k_orig = k; - mp_digit r; - mp_size ix; - mp_err res; - - if (mp_cmp_z(c) < 0) { /* c < 0 */ - MP_CHECKOK( mp_add(c, p, x) ); /* x = c + p */ - } else { - MP_CHECKOK( mp_copy(c, x) ); /* x = c */ - } - - /* make sure x is large enough */ - ix = MP_HOWMANY(k, MP_DIGIT_BIT) + MP_USED(p) + 1; - ix = MP_MAX(ix, MP_USED(x)); - MP_CHECKOK( s_mp_pad(x, ix) ); - - r = 0 - s_mp_invmod_radix(MP_DIGIT(p,0)); - - for (ix = 0; k > 0; ix++) { - int j = MP_MIN(k, MP_DIGIT_BIT); - mp_digit v = r * MP_DIGIT(x, ix); - if (j < MP_DIGIT_BIT) { - v &= ((mp_digit)1 << j) - 1; /* v = v mod (2 ** j) */ - } - s_mp_mul_d_add_offset(p, v, x, ix); /* x += p * v * (RADIX ** ix) */ - k -= j; - } - s_mp_clamp(x); - s_mp_div_2d(x, k_orig); - res = MP_OKAY; - -CLEANUP: - return res; -} - -/* compute mod inverse using Schroeppel's method, only if m is odd */ -mp_err s_mp_invmod_odd_m(const mp_int *a, const mp_int *m, mp_int *c) -{ - int k; - mp_err res; - mp_int x; - - ARGCHK(a && m && c, MP_BADARG); - - if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0) - return MP_RANGE; - if (mp_iseven(m)) - return MP_UNDEF; - - MP_DIGITS(&x) = 0; - - if (a == c) { - if ((res = mp_init_copy(&x, a)) != MP_OKAY) - return res; - if (a == m) - m = &x; - a = &x; - } else if (m == c) { - if ((res = mp_init_copy(&x, m)) != MP_OKAY) - return res; - m = &x; - } else { - MP_DIGITS(&x) = 0; - } - - MP_CHECKOK( s_mp_almost_inverse(a, m, c) ); - k = res; - MP_CHECKOK( s_mp_fixup_reciprocal(c, m, k, c) ); -CLEANUP: - mp_clear(&x); - return res; -} - -/* Known good algorithm for computing modular inverse. But slow. */ -mp_err mp_invmod_xgcd(const mp_int *a, const mp_int *m, mp_int *c) -{ - mp_int g, x; - mp_err res; - - ARGCHK(a && m && c, MP_BADARG); - - if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0) - return MP_RANGE; - - MP_DIGITS(&g) = 0; - MP_DIGITS(&x) = 0; - MP_CHECKOK( mp_init(&x, FLAG(a)) ); - MP_CHECKOK( mp_init(&g, FLAG(a)) ); - - MP_CHECKOK( mp_xgcd(a, m, &g, &x, NULL) ); - - if (mp_cmp_d(&g, 1) != MP_EQ) { - res = MP_UNDEF; - goto CLEANUP; - } - - res = mp_mod(&x, m, c); - SIGN(c) = SIGN(a); - -CLEANUP: - mp_clear(&x); - mp_clear(&g); - - return res; -} - -/* modular inverse where modulus is 2**k. */ -/* c = a**-1 mod 2**k */ -mp_err s_mp_invmod_2d(const mp_int *a, mp_size k, mp_int *c) -{ - mp_err res; - mp_size ix = k + 4; - mp_int t0, t1, val, tmp, two2k; - - static const mp_digit d2 = 2; - static const mp_int two = { 0, MP_ZPOS, 1, 1, (mp_digit *)&d2 }; - - if (mp_iseven(a)) - return MP_UNDEF; - if (k <= MP_DIGIT_BIT) { - mp_digit i = s_mp_invmod_radix(MP_DIGIT(a,0)); - if (k < MP_DIGIT_BIT) - i &= ((mp_digit)1 << k) - (mp_digit)1; - mp_set(c, i); - return MP_OKAY; - } - MP_DIGITS(&t0) = 0; - MP_DIGITS(&t1) = 0; - MP_DIGITS(&val) = 0; - MP_DIGITS(&tmp) = 0; - MP_DIGITS(&two2k) = 0; - MP_CHECKOK( mp_init_copy(&val, a) ); - s_mp_mod_2d(&val, k); - MP_CHECKOK( mp_init_copy(&t0, &val) ); - MP_CHECKOK( mp_init_copy(&t1, &t0) ); - MP_CHECKOK( mp_init(&tmp, FLAG(a)) ); - MP_CHECKOK( mp_init(&two2k, FLAG(a)) ); - MP_CHECKOK( s_mp_2expt(&two2k, k) ); - do { - MP_CHECKOK( mp_mul(&val, &t1, &tmp) ); - MP_CHECKOK( mp_sub(&two, &tmp, &tmp) ); - MP_CHECKOK( mp_mul(&t1, &tmp, &t1) ); - s_mp_mod_2d(&t1, k); - while (MP_SIGN(&t1) != MP_ZPOS) { - MP_CHECKOK( mp_add(&t1, &two2k, &t1) ); - } - if (mp_cmp(&t1, &t0) == MP_EQ) - break; - MP_CHECKOK( mp_copy(&t1, &t0) ); - } while (--ix > 0); - if (!ix) { - res = MP_UNDEF; - } else { - mp_exch(c, &t1); - } - -CLEANUP: - mp_clear(&t0); - mp_clear(&t1); - mp_clear(&val); - mp_clear(&tmp); - mp_clear(&two2k); - return res; -} - -mp_err s_mp_invmod_even_m(const mp_int *a, const mp_int *m, mp_int *c) -{ - mp_err res; - mp_size k; - mp_int oddFactor, evenFactor; /* factors of the modulus */ - mp_int oddPart, evenPart; /* parts to combine via CRT. */ - mp_int C2, tmp1, tmp2; - - /*static const mp_digit d1 = 1; */ - /*static const mp_int one = { MP_ZPOS, 1, 1, (mp_digit *)&d1 }; */ - - if ((res = s_mp_ispow2(m)) >= 0) { - k = res; - return s_mp_invmod_2d(a, k, c); - } - MP_DIGITS(&oddFactor) = 0; - MP_DIGITS(&evenFactor) = 0; - MP_DIGITS(&oddPart) = 0; - MP_DIGITS(&evenPart) = 0; - MP_DIGITS(&C2) = 0; - MP_DIGITS(&tmp1) = 0; - MP_DIGITS(&tmp2) = 0; - - MP_CHECKOK( mp_init_copy(&oddFactor, m) ); /* oddFactor = m */ - MP_CHECKOK( mp_init(&evenFactor, FLAG(m)) ); - MP_CHECKOK( mp_init(&oddPart, FLAG(m)) ); - MP_CHECKOK( mp_init(&evenPart, FLAG(m)) ); - MP_CHECKOK( mp_init(&C2, FLAG(m)) ); - MP_CHECKOK( mp_init(&tmp1, FLAG(m)) ); - MP_CHECKOK( mp_init(&tmp2, FLAG(m)) ); - - k = mp_trailing_zeros(m); - s_mp_div_2d(&oddFactor, k); - MP_CHECKOK( s_mp_2expt(&evenFactor, k) ); - - /* compute a**-1 mod oddFactor. */ - MP_CHECKOK( s_mp_invmod_odd_m(a, &oddFactor, &oddPart) ); - /* compute a**-1 mod evenFactor, where evenFactor == 2**k. */ - MP_CHECKOK( s_mp_invmod_2d( a, k, &evenPart) ); - - /* Use Chinese Remainer theorem to compute a**-1 mod m. */ - /* let m1 = oddFactor, v1 = oddPart, - * let m2 = evenFactor, v2 = evenPart. - */ - - /* Compute C2 = m1**-1 mod m2. */ - MP_CHECKOK( s_mp_invmod_2d(&oddFactor, k, &C2) ); - - /* compute u = (v2 - v1)*C2 mod m2 */ - MP_CHECKOK( mp_sub(&evenPart, &oddPart, &tmp1) ); - MP_CHECKOK( mp_mul(&tmp1, &C2, &tmp2) ); - s_mp_mod_2d(&tmp2, k); - while (MP_SIGN(&tmp2) != MP_ZPOS) { - MP_CHECKOK( mp_add(&tmp2, &evenFactor, &tmp2) ); - } - - /* compute answer = v1 + u*m1 */ - MP_CHECKOK( mp_mul(&tmp2, &oddFactor, c) ); - MP_CHECKOK( mp_add(&oddPart, c, c) ); - /* not sure this is necessary, but it's low cost if not. */ - MP_CHECKOK( mp_mod(c, m, c) ); - -CLEANUP: - mp_clear(&oddFactor); - mp_clear(&evenFactor); - mp_clear(&oddPart); - mp_clear(&evenPart); - mp_clear(&C2); - mp_clear(&tmp1); - mp_clear(&tmp2); - return res; -} - - -/* {{{ mp_invmod(a, m, c) */ - -/* - mp_invmod(a, m, c) - - Compute c = a^-1 (mod m), if there is an inverse for a (mod m). - This is equivalent to the question of whether (a, m) = 1. If not, - MP_UNDEF is returned, and there is no inverse. - */ - -mp_err mp_invmod(const mp_int *a, const mp_int *m, mp_int *c) -{ - - ARGCHK(a && m && c, MP_BADARG); - - if(mp_cmp_z(a) == 0 || mp_cmp_z(m) == 0) - return MP_RANGE; - - if (mp_isodd(m)) { - return s_mp_invmod_odd_m(a, m, c); - } - if (mp_iseven(a)) - return MP_UNDEF; /* not invertable */ - - return s_mp_invmod_even_m(a, m, c); - -} /* end mp_invmod() */ - -/* }}} */ -#endif /* if MP_NUMTH */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ mp_print(mp, ofp) */ - -#if MP_IOFUNC -/* - mp_print(mp, ofp) - - Print a textual representation of the given mp_int on the output - stream 'ofp'. Output is generated using the internal radix. - */ - -void mp_print(mp_int *mp, FILE *ofp) -{ - int ix; - - if(mp == NULL || ofp == NULL) - return; - - fputc((SIGN(mp) == NEG) ? '-' : '+', ofp); - - for(ix = USED(mp) - 1; ix >= 0; ix--) { - fprintf(ofp, DIGIT_FMT, DIGIT(mp, ix)); - } - -} /* end mp_print() */ - -#endif /* if MP_IOFUNC */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* {{{ More I/O Functions */ - -/* {{{ mp_read_raw(mp, str, len) */ - -/* - mp_read_raw(mp, str, len) - - Read in a raw value (base 256) into the given mp_int - */ - -mp_err mp_read_raw(mp_int *mp, char *str, int len) -{ - int ix; - mp_err res; - unsigned char *ustr = (unsigned char *)str; - - ARGCHK(mp != NULL && str != NULL && len > 0, MP_BADARG); - - mp_zero(mp); - - /* Get sign from first byte */ - if(ustr[0]) - SIGN(mp) = NEG; - else - SIGN(mp) = ZPOS; - - /* Read the rest of the digits */ - for(ix = 1; ix < len; ix++) { - if((res = mp_mul_d(mp, 256, mp)) != MP_OKAY) - return res; - if((res = mp_add_d(mp, ustr[ix], mp)) != MP_OKAY) - return res; - } - - return MP_OKAY; - -} /* end mp_read_raw() */ - -/* }}} */ - -/* {{{ mp_raw_size(mp) */ - -int mp_raw_size(mp_int *mp) -{ - ARGCHK(mp != NULL, 0); - - return (USED(mp) * sizeof(mp_digit)) + 1; - -} /* end mp_raw_size() */ - -/* }}} */ - -/* {{{ mp_toraw(mp, str) */ - -mp_err mp_toraw(mp_int *mp, char *str) -{ - int ix, jx, pos = 1; - - ARGCHK(mp != NULL && str != NULL, MP_BADARG); - - str[0] = (char)SIGN(mp); - - /* Iterate over each digit... */ - for(ix = USED(mp) - 1; ix >= 0; ix--) { - mp_digit d = DIGIT(mp, ix); - - /* Unpack digit bytes, high order first */ - for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) { - str[pos++] = (char)(d >> (jx * CHAR_BIT)); - } - } - - return MP_OKAY; - -} /* end mp_toraw() */ - -/* }}} */ - -/* {{{ mp_read_radix(mp, str, radix) */ - -/* - mp_read_radix(mp, str, radix) - - Read an integer from the given string, and set mp to the resulting - value. The input is presumed to be in base 10. Leading non-digit - characters are ignored, and the function reads until a non-digit - character or the end of the string. - */ - -mp_err mp_read_radix(mp_int *mp, const char *str, int radix) -{ - int ix = 0, val = 0; - mp_err res; - mp_sign sig = ZPOS; - - ARGCHK(mp != NULL && str != NULL && radix >= 2 && radix <= MAX_RADIX, - MP_BADARG); - - mp_zero(mp); - - /* Skip leading non-digit characters until a digit or '-' or '+' */ - while(str[ix] && - (s_mp_tovalue(str[ix], radix) < 0) && - str[ix] != '-' && - str[ix] != '+') { - ++ix; - } - - if(str[ix] == '-') { - sig = NEG; - ++ix; - } else if(str[ix] == '+') { - sig = ZPOS; /* this is the default anyway... */ - ++ix; - } - - while((val = s_mp_tovalue(str[ix], radix)) >= 0) { - if((res = s_mp_mul_d(mp, radix)) != MP_OKAY) - return res; - if((res = s_mp_add_d(mp, val)) != MP_OKAY) - return res; - ++ix; - } - - if(s_mp_cmp_d(mp, 0) == MP_EQ) - SIGN(mp) = ZPOS; - else - SIGN(mp) = sig; - - return MP_OKAY; - -} /* end mp_read_radix() */ - -mp_err mp_read_variable_radix(mp_int *a, const char * str, int default_radix) -{ - int radix = default_radix; - int cx; - mp_sign sig = ZPOS; - mp_err res; - - /* Skip leading non-digit characters until a digit or '-' or '+' */ - while ((cx = *str) != 0 && - (s_mp_tovalue(cx, radix) < 0) && - cx != '-' && - cx != '+') { - ++str; - } - - if (cx == '-') { - sig = NEG; - ++str; - } else if (cx == '+') { - sig = ZPOS; /* this is the default anyway... */ - ++str; - } - - if (str[0] == '0') { - if ((str[1] | 0x20) == 'x') { - radix = 16; - str += 2; - } else { - radix = 8; - str++; - } - } - res = mp_read_radix(a, str, radix); - if (res == MP_OKAY) { - MP_SIGN(a) = (s_mp_cmp_d(a, 0) == MP_EQ) ? ZPOS : sig; - } - return res; -} - -/* }}} */ - -/* {{{ mp_radix_size(mp, radix) */ - -int mp_radix_size(mp_int *mp, int radix) -{ - int bits; - - if(!mp || radix < 2 || radix > MAX_RADIX) - return 0; - - bits = USED(mp) * DIGIT_BIT - 1; - - return s_mp_outlen(bits, radix); - -} /* end mp_radix_size() */ - -/* }}} */ - -/* {{{ mp_toradix(mp, str, radix) */ - -mp_err mp_toradix(mp_int *mp, char *str, int radix) -{ - int ix, pos = 0; - - ARGCHK(mp != NULL && str != NULL, MP_BADARG); - ARGCHK(radix > 1 && radix <= MAX_RADIX, MP_RANGE); - - if(mp_cmp_z(mp) == MP_EQ) { - str[0] = '0'; - str[1] = '\0'; - } else { - mp_err res; - mp_int tmp; - mp_sign sgn; - mp_digit rem, rdx = (mp_digit)radix; - char ch; - - if((res = mp_init_copy(&tmp, mp)) != MP_OKAY) - return res; - - /* Save sign for later, and take absolute value */ - sgn = SIGN(&tmp); SIGN(&tmp) = ZPOS; - - /* Generate output digits in reverse order */ - while(mp_cmp_z(&tmp) != 0) { - if((res = mp_div_d(&tmp, rdx, &tmp, &rem)) != MP_OKAY) { - mp_clear(&tmp); - return res; - } - - /* Generate digits, use capital letters */ - ch = s_mp_todigit(rem, radix, 0); - - str[pos++] = ch; - } - - /* Add - sign if original value was negative */ - if(sgn == NEG) - str[pos++] = '-'; - - /* Add trailing NUL to end the string */ - str[pos--] = '\0'; - - /* Reverse the digits and sign indicator */ - ix = 0; - while(ix < pos) { - char tmp = str[ix]; - - str[ix] = str[pos]; - str[pos] = tmp; - ++ix; - --pos; - } - - mp_clear(&tmp); - } - - return MP_OKAY; - -} /* end mp_toradix() */ - -/* }}} */ - -/* {{{ mp_tovalue(ch, r) */ - -int mp_tovalue(char ch, int r) -{ - return s_mp_tovalue(ch, r); - -} /* end mp_tovalue() */ - -/* }}} */ - -/* }}} */ - -/* {{{ mp_strerror(ec) */ - -/* - mp_strerror(ec) - - Return a string describing the meaning of error code 'ec'. The - string returned is allocated in static memory, so the caller should - not attempt to modify or free the memory associated with this - string. - */ -const char *mp_strerror(mp_err ec) -{ - int aec = (ec < 0) ? -ec : ec; - - /* Code values are negative, so the senses of these comparisons - are accurate */ - if(ec < MP_LAST_CODE || ec > MP_OKAY) { - return mp_err_string[0]; /* unknown error code */ - } else { - return mp_err_string[aec + 1]; - } - -} /* end mp_strerror() */ - -/* }}} */ - -/*========================================================================*/ -/*------------------------------------------------------------------------*/ -/* Static function definitions (internal use only) */ - -/* {{{ Memory management */ - -/* {{{ s_mp_grow(mp, min) */ - -/* Make sure there are at least 'min' digits allocated to mp */ -mp_err s_mp_grow(mp_int *mp, mp_size min) -{ - if(min > ALLOC(mp)) { - mp_digit *tmp; - - /* Set min to next nearest default precision block size */ - min = MP_ROUNDUP(min, s_mp_defprec); - - if((tmp = s_mp_alloc(min, sizeof(mp_digit), FLAG(mp))) == NULL) - return MP_MEM; - - s_mp_copy(DIGITS(mp), tmp, USED(mp)); - -#if MP_CRYPTO - s_mp_setz(DIGITS(mp), ALLOC(mp)); -#endif - s_mp_free(DIGITS(mp), ALLOC(mp)); - DIGITS(mp) = tmp; - ALLOC(mp) = min; - } - - return MP_OKAY; - -} /* end s_mp_grow() */ - -/* }}} */ - -/* {{{ s_mp_pad(mp, min) */ - -/* Make sure the used size of mp is at least 'min', growing if needed */ -mp_err s_mp_pad(mp_int *mp, mp_size min) -{ - if(min > USED(mp)) { - mp_err res; - - /* Make sure there is room to increase precision */ - if (min > ALLOC(mp)) { - if ((res = s_mp_grow(mp, min)) != MP_OKAY) - return res; - } else { - s_mp_setz(DIGITS(mp) + USED(mp), min - USED(mp)); - } - - /* Increase precision; should already be 0-filled */ - USED(mp) = min; - } - - return MP_OKAY; - -} /* end s_mp_pad() */ - -/* }}} */ - -/* {{{ s_mp_setz(dp, count) */ - -#if MP_MACRO == 0 -/* Set 'count' digits pointed to by dp to be zeroes */ -void s_mp_setz(mp_digit *dp, mp_size count) -{ -#if MP_MEMSET == 0 - int ix; - - for(ix = 0; ix < count; ix++) - dp[ix] = 0; -#else - memset(dp, 0, count * sizeof(mp_digit)); -#endif - -} /* end s_mp_setz() */ -#endif - -/* }}} */ - -/* {{{ s_mp_copy(sp, dp, count) */ - -#if MP_MACRO == 0 -/* Copy 'count' digits from sp to dp */ -void s_mp_copy(const mp_digit *sp, mp_digit *dp, mp_size count) -{ -#if MP_MEMCPY == 0 - int ix; - - for(ix = 0; ix < count; ix++) - dp[ix] = sp[ix]; -#else - memcpy(dp, sp, count * sizeof(mp_digit)); -#endif - -} /* end s_mp_copy() */ -#endif - -/* }}} */ - -/* {{{ s_mp_alloc(nb, ni, kmflag) */ - -#if MP_MACRO == 0 -/* Allocate ni records of nb bytes each, and return a pointer to that */ -void *s_mp_alloc(size_t nb, size_t ni, int kmflag) -{ - ++mp_allocs; -#ifdef _KERNEL - mp_int *mp; - mp = kmem_zalloc(nb * ni, kmflag); - if (mp != NULL) - FLAG(mp) = kmflag; - return (mp); -#else - return calloc(nb, ni); -#endif - -} /* end s_mp_alloc() */ -#endif - -/* }}} */ - -/* {{{ s_mp_free(ptr) */ - -#if MP_MACRO == 0 -/* Free the memory pointed to by ptr */ -void s_mp_free(void *ptr, mp_size alloc) -{ - if(ptr) { - ++mp_frees; -#ifdef _KERNEL - kmem_free(ptr, alloc * sizeof (mp_digit)); -#else - free(ptr); -#endif - } -} /* end s_mp_free() */ -#endif - -/* }}} */ - -/* {{{ s_mp_clamp(mp) */ - -#if MP_MACRO == 0 -/* Remove leading zeroes from the given value */ -void s_mp_clamp(mp_int *mp) -{ - mp_size used = MP_USED(mp); - while (used > 1 && DIGIT(mp, used - 1) == 0) - --used; - MP_USED(mp) = used; -} /* end s_mp_clamp() */ -#endif - -/* }}} */ - -/* {{{ s_mp_exch(a, b) */ - -/* Exchange the data for a and b; (b, a) = (a, b) */ -void s_mp_exch(mp_int *a, mp_int *b) -{ - mp_int tmp; - - tmp = *a; - *a = *b; - *b = tmp; - -} /* end s_mp_exch() */ - -/* }}} */ - -/* }}} */ - -/* {{{ Arithmetic helpers */ - -/* {{{ s_mp_lshd(mp, p) */ - -/* - Shift mp leftward by p digits, growing if needed, and zero-filling - the in-shifted digits at the right end. This is a convenient - alternative to multiplication by powers of the radix - The value of USED(mp) must already have been set to the value for - the shifted result. - */ - -mp_err s_mp_lshd(mp_int *mp, mp_size p) -{ - mp_err res; - mp_size pos; - int ix; - - if(p == 0) - return MP_OKAY; - - if (MP_USED(mp) == 1 && MP_DIGIT(mp, 0) == 0) - return MP_OKAY; - - if((res = s_mp_pad(mp, USED(mp) + p)) != MP_OKAY) - return res; - - pos = USED(mp) - 1; - - /* Shift all the significant figures over as needed */ - for(ix = pos - p; ix >= 0; ix--) - DIGIT(mp, ix + p) = DIGIT(mp, ix); - - /* Fill the bottom digits with zeroes */ - for(ix = 0; ix < p; ix++) - DIGIT(mp, ix) = 0; - - return MP_OKAY; - -} /* end s_mp_lshd() */ - -/* }}} */ - -/* {{{ s_mp_mul_2d(mp, d) */ - -/* - Multiply the integer by 2^d, where d is a number of bits. This - amounts to a bitwise shift of the value. - */ -mp_err s_mp_mul_2d(mp_int *mp, mp_digit d) -{ - mp_err res; - mp_digit dshift, bshift; - mp_digit mask; - - ARGCHK(mp != NULL, MP_BADARG); - - dshift = d / MP_DIGIT_BIT; - bshift = d % MP_DIGIT_BIT; - /* bits to be shifted out of the top word */ - mask = ((mp_digit)~0 << (MP_DIGIT_BIT - bshift)); - mask &= MP_DIGIT(mp, MP_USED(mp) - 1); - - if (MP_OKAY != (res = s_mp_pad(mp, MP_USED(mp) + dshift + (mask != 0) ))) - return res; - - if (dshift && MP_OKAY != (res = s_mp_lshd(mp, dshift))) - return res; - - if (bshift) { - mp_digit *pa = MP_DIGITS(mp); - mp_digit *alim = pa + MP_USED(mp); - mp_digit prev = 0; - - for (pa += dshift; pa < alim; ) { - mp_digit x = *pa; - *pa++ = (x << bshift) | prev; - prev = x >> (DIGIT_BIT - bshift); - } - } - - s_mp_clamp(mp); - return MP_OKAY; -} /* end s_mp_mul_2d() */ - -/* {{{ s_mp_rshd(mp, p) */ - -/* - Shift mp rightward by p digits. Maintains the invariant that - digits above the precision are all zero. Digits shifted off the - end are lost. Cannot fail. - */ - -void s_mp_rshd(mp_int *mp, mp_size p) -{ - mp_size ix; - mp_digit *src, *dst; - - if(p == 0) - return; - - /* Shortcut when all digits are to be shifted off */ - if(p >= USED(mp)) { - s_mp_setz(DIGITS(mp), ALLOC(mp)); - USED(mp) = 1; - SIGN(mp) = ZPOS; - return; - } - - /* Shift all the significant figures over as needed */ - dst = MP_DIGITS(mp); - src = dst + p; - for (ix = USED(mp) - p; ix > 0; ix--) - *dst++ = *src++; - - MP_USED(mp) -= p; - /* Fill the top digits with zeroes */ - while (p-- > 0) - *dst++ = 0; - -#if 0 - /* Strip off any leading zeroes */ - s_mp_clamp(mp); -#endif - -} /* end s_mp_rshd() */ - -/* }}} */ - -/* {{{ s_mp_div_2(mp) */ - -/* Divide by two -- take advantage of radix properties to do it fast */ -void s_mp_div_2(mp_int *mp) -{ - s_mp_div_2d(mp, 1); - -} /* end s_mp_div_2() */ - -/* }}} */ - -/* {{{ s_mp_mul_2(mp) */ - -mp_err s_mp_mul_2(mp_int *mp) -{ - mp_digit *pd; - unsigned int ix, used; - mp_digit kin = 0; - - /* Shift digits leftward by 1 bit */ - used = MP_USED(mp); - pd = MP_DIGITS(mp); - for (ix = 0; ix < used; ix++) { - mp_digit d = *pd; - *pd++ = (d << 1) | kin; - kin = (d >> (DIGIT_BIT - 1)); - } - - /* Deal with rollover from last digit */ - if (kin) { - if (ix >= ALLOC(mp)) { - mp_err res; - if((res = s_mp_grow(mp, ALLOC(mp) + 1)) != MP_OKAY) - return res; - } - - DIGIT(mp, ix) = kin; - USED(mp) += 1; - } - - return MP_OKAY; - -} /* end s_mp_mul_2() */ - -/* }}} */ - -/* {{{ s_mp_mod_2d(mp, d) */ - -/* - Remainder the integer by 2^d, where d is a number of bits. This - amounts to a bitwise AND of the value, and does not require the full - division code - */ -void s_mp_mod_2d(mp_int *mp, mp_digit d) -{ - mp_size ndig = (d / DIGIT_BIT), nbit = (d % DIGIT_BIT); - mp_size ix; - mp_digit dmask; - - if(ndig >= USED(mp)) - return; - - /* Flush all the bits above 2^d in its digit */ - dmask = ((mp_digit)1 << nbit) - 1; - DIGIT(mp, ndig) &= dmask; - - /* Flush all digits above the one with 2^d in it */ - for(ix = ndig + 1; ix < USED(mp); ix++) - DIGIT(mp, ix) = 0; - - s_mp_clamp(mp); - -} /* end s_mp_mod_2d() */ - -/* }}} */ - -/* {{{ s_mp_div_2d(mp, d) */ - -/* - Divide the integer by 2^d, where d is a number of bits. This - amounts to a bitwise shift of the value, and does not require the - full division code (used in Barrett reduction, see below) - */ -void s_mp_div_2d(mp_int *mp, mp_digit d) -{ - int ix; - mp_digit save, next, mask; - - s_mp_rshd(mp, d / DIGIT_BIT); - d %= DIGIT_BIT; - if (d) { - mask = ((mp_digit)1 << d) - 1; - save = 0; - for(ix = USED(mp) - 1; ix >= 0; ix--) { - next = DIGIT(mp, ix) & mask; - DIGIT(mp, ix) = (DIGIT(mp, ix) >> d) | (save << (DIGIT_BIT - d)); - save = next; - } - } - s_mp_clamp(mp); - -} /* end s_mp_div_2d() */ - -/* }}} */ - -/* {{{ s_mp_norm(a, b, *d) */ - -/* - s_mp_norm(a, b, *d) - - Normalize a and b for division, where b is the divisor. In order - that we might make good guesses for quotient digits, we want the - leading digit of b to be at least half the radix, which we - accomplish by multiplying a and b by a power of 2. The exponent - (shift count) is placed in *pd, so that the remainder can be shifted - back at the end of the division process. - */ - -mp_err s_mp_norm(mp_int *a, mp_int *b, mp_digit *pd) -{ - mp_digit d; - mp_digit mask; - mp_digit b_msd; - mp_err res = MP_OKAY; - - d = 0; - mask = DIGIT_MAX & ~(DIGIT_MAX >> 1); /* mask is msb of digit */ - b_msd = DIGIT(b, USED(b) - 1); - while (!(b_msd & mask)) { - b_msd <<= 1; - ++d; - } - - if (d) { - MP_CHECKOK( s_mp_mul_2d(a, d) ); - MP_CHECKOK( s_mp_mul_2d(b, d) ); - } - - *pd = d; -CLEANUP: - return res; - -} /* end s_mp_norm() */ - -/* }}} */ - -/* }}} */ - -/* {{{ Primitive digit arithmetic */ - -/* {{{ s_mp_add_d(mp, d) */ - -/* Add d to |mp| in place */ -mp_err s_mp_add_d(mp_int *mp, mp_digit d) /* unsigned digit addition */ -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - mp_word w, k = 0; - mp_size ix = 1; - - w = (mp_word)DIGIT(mp, 0) + d; - DIGIT(mp, 0) = ACCUM(w); - k = CARRYOUT(w); - - while(ix < USED(mp) && k) { - w = (mp_word)DIGIT(mp, ix) + k; - DIGIT(mp, ix) = ACCUM(w); - k = CARRYOUT(w); - ++ix; - } - - if(k != 0) { - mp_err res; - - if((res = s_mp_pad(mp, USED(mp) + 1)) != MP_OKAY) - return res; - - DIGIT(mp, ix) = (mp_digit)k; - } - - return MP_OKAY; -#else - mp_digit * pmp = MP_DIGITS(mp); - mp_digit sum, mp_i, carry = 0; - mp_err res = MP_OKAY; - int used = (int)MP_USED(mp); - - mp_i = *pmp; - *pmp++ = sum = d + mp_i; - carry = (sum < d); - while (carry && --used > 0) { - mp_i = *pmp; - *pmp++ = sum = carry + mp_i; - carry = !sum; - } - if (carry && !used) { - /* mp is growing */ - used = MP_USED(mp); - MP_CHECKOK( s_mp_pad(mp, used + 1) ); - MP_DIGIT(mp, used) = carry; - } -CLEANUP: - return res; -#endif -} /* end s_mp_add_d() */ - -/* }}} */ - -/* {{{ s_mp_sub_d(mp, d) */ - -/* Subtract d from |mp| in place, assumes |mp| > d */ -mp_err s_mp_sub_d(mp_int *mp, mp_digit d) /* unsigned digit subtract */ -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - mp_word w, b = 0; - mp_size ix = 1; - - /* Compute initial subtraction */ - w = (RADIX + (mp_word)DIGIT(mp, 0)) - d; - b = CARRYOUT(w) ? 0 : 1; - DIGIT(mp, 0) = ACCUM(w); - - /* Propagate borrows leftward */ - while(b && ix < USED(mp)) { - w = (RADIX + (mp_word)DIGIT(mp, ix)) - b; - b = CARRYOUT(w) ? 0 : 1; - DIGIT(mp, ix) = ACCUM(w); - ++ix; - } - - /* Remove leading zeroes */ - s_mp_clamp(mp); - - /* If we have a borrow out, it's a violation of the input invariant */ - if(b) - return MP_RANGE; - else - return MP_OKAY; -#else - mp_digit *pmp = MP_DIGITS(mp); - mp_digit mp_i, diff, borrow; - mp_size used = MP_USED(mp); - - mp_i = *pmp; - *pmp++ = diff = mp_i - d; - borrow = (diff > mp_i); - while (borrow && --used) { - mp_i = *pmp; - *pmp++ = diff = mp_i - borrow; - borrow = (diff > mp_i); - } - s_mp_clamp(mp); - return (borrow && !used) ? MP_RANGE : MP_OKAY; -#endif -} /* end s_mp_sub_d() */ - -/* }}} */ - -/* {{{ s_mp_mul_d(a, d) */ - -/* Compute a = a * d, single digit multiplication */ -mp_err s_mp_mul_d(mp_int *a, mp_digit d) -{ - mp_err res; - mp_size used; - int pow; - - if (!d) { - mp_zero(a); - return MP_OKAY; - } - if (d == 1) - return MP_OKAY; - if (0 <= (pow = s_mp_ispow2d(d))) { - return s_mp_mul_2d(a, (mp_digit)pow); - } - - used = MP_USED(a); - MP_CHECKOK( s_mp_pad(a, used + 1) ); - - s_mpv_mul_d(MP_DIGITS(a), used, d, MP_DIGITS(a)); - - s_mp_clamp(a); - -CLEANUP: - return res; - -} /* end s_mp_mul_d() */ - -/* }}} */ - -/* {{{ s_mp_div_d(mp, d, r) */ - -/* - s_mp_div_d(mp, d, r) - - Compute the quotient mp = mp / d and remainder r = mp mod d, for a - single digit d. If r is null, the remainder will be discarded. - */ - -mp_err s_mp_div_d(mp_int *mp, mp_digit d, mp_digit *r) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD) - mp_word w = 0, q; -#else - mp_digit w = 0, q; -#endif - int ix; - mp_err res; - mp_int quot; - mp_int rem; - - if(d == 0) - return MP_RANGE; - if (d == 1) { - if (r) - *r = 0; - return MP_OKAY; - } - /* could check for power of 2 here, but mp_div_d does that. */ - if (MP_USED(mp) == 1) { - mp_digit n = MP_DIGIT(mp,0); - mp_digit rem; - - q = n / d; - rem = n % d; - MP_DIGIT(mp,0) = q; - if (r) - *r = rem; - return MP_OKAY; - } - - MP_DIGITS(&rem) = 0; - MP_DIGITS(") = 0; - /* Make room for the quotient */ - MP_CHECKOK( mp_init_size(", USED(mp), FLAG(mp)) ); - -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD) - for(ix = USED(mp) - 1; ix >= 0; ix--) { - w = (w << DIGIT_BIT) | DIGIT(mp, ix); - - if(w >= d) { - q = w / d; - w = w % d; - } else { - q = 0; - } - - s_mp_lshd(", 1); - DIGIT(", 0) = (mp_digit)q; - } -#else - { - mp_digit p; -#if !defined(MP_ASSEMBLY_DIV_2DX1D) - mp_digit norm; -#endif - - MP_CHECKOK( mp_init_copy(&rem, mp) ); - -#if !defined(MP_ASSEMBLY_DIV_2DX1D) - MP_DIGIT(", 0) = d; - MP_CHECKOK( s_mp_norm(&rem, ", &norm) ); - if (norm) - d <<= norm; - MP_DIGIT(", 0) = 0; -#endif - - p = 0; - for (ix = USED(&rem) - 1; ix >= 0; ix--) { - w = DIGIT(&rem, ix); - - if (p) { - MP_CHECKOK( s_mpv_div_2dx1d(p, w, d, &q, &w) ); - } else if (w >= d) { - q = w / d; - w = w % d; - } else { - q = 0; - } - - MP_CHECKOK( s_mp_lshd(", 1) ); - DIGIT(", 0) = q; - p = w; - } -#if !defined(MP_ASSEMBLY_DIV_2DX1D) - if (norm) - w >>= norm; -#endif - } -#endif - - /* Deliver the remainder, if desired */ - if(r) - *r = (mp_digit)w; - - s_mp_clamp("); - mp_exch(", mp); -CLEANUP: - mp_clear("); - mp_clear(&rem); - - return res; -} /* end s_mp_div_d() */ - -/* }}} */ - - -/* }}} */ - -/* {{{ Primitive full arithmetic */ - -/* {{{ s_mp_add(a, b) */ - -/* Compute a = |a| + |b| */ -mp_err s_mp_add(mp_int *a, const mp_int *b) /* magnitude addition */ -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - mp_word w = 0; -#else - mp_digit d, sum, carry = 0; -#endif - mp_digit *pa, *pb; - mp_size ix; - mp_size used; - mp_err res; - - /* Make sure a has enough precision for the output value */ - if((USED(b) > USED(a)) && (res = s_mp_pad(a, USED(b))) != MP_OKAY) - return res; - - /* - Add up all digits up to the precision of b. If b had initially - the same precision as a, or greater, we took care of it by the - padding step above, so there is no problem. If b had initially - less precision, we'll have to make sure the carry out is duly - propagated upward among the higher-order digits of the sum. - */ - pa = MP_DIGITS(a); - pb = MP_DIGITS(b); - used = MP_USED(b); - for(ix = 0; ix < used; ix++) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - w = w + *pa + *pb++; - *pa++ = ACCUM(w); - w = CARRYOUT(w); -#else - d = *pa; - sum = d + *pb++; - d = (sum < d); /* detect overflow */ - *pa++ = sum += carry; - carry = d + (sum < carry); /* detect overflow */ -#endif - } - - /* If we run out of 'b' digits before we're actually done, make - sure the carries get propagated upward... - */ - used = MP_USED(a); -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - while (w && ix < used) { - w = w + *pa; - *pa++ = ACCUM(w); - w = CARRYOUT(w); - ++ix; - } -#else - while (carry && ix < used) { - sum = carry + *pa; - *pa++ = sum; - carry = !sum; - ++ix; - } -#endif - - /* If there's an overall carry out, increase precision and include - it. We could have done this initially, but why touch the memory - allocator unless we're sure we have to? - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - if (w) { - if((res = s_mp_pad(a, used + 1)) != MP_OKAY) - return res; - - DIGIT(a, ix) = (mp_digit)w; - } -#else - if (carry) { - if((res = s_mp_pad(a, used + 1)) != MP_OKAY) - return res; - - DIGIT(a, used) = carry; - } -#endif - - return MP_OKAY; -} /* end s_mp_add() */ - -/* }}} */ - -/* Compute c = |a| + |b| */ /* magnitude addition */ -mp_err s_mp_add_3arg(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_digit *pa, *pb, *pc; -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - mp_word w = 0; -#else - mp_digit sum, carry = 0, d; -#endif - mp_size ix; - mp_size used; - mp_err res; - - MP_SIGN(c) = MP_SIGN(a); - if (MP_USED(a) < MP_USED(b)) { - const mp_int *xch = a; - a = b; - b = xch; - } - - /* Make sure a has enough precision for the output value */ - if (MP_OKAY != (res = s_mp_pad(c, MP_USED(a)))) - return res; - - /* - Add up all digits up to the precision of b. If b had initially - the same precision as a, or greater, we took care of it by the - exchange step above, so there is no problem. If b had initially - less precision, we'll have to make sure the carry out is duly - propagated upward among the higher-order digits of the sum. - */ - pa = MP_DIGITS(a); - pb = MP_DIGITS(b); - pc = MP_DIGITS(c); - used = MP_USED(b); - for (ix = 0; ix < used; ix++) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - w = w + *pa++ + *pb++; - *pc++ = ACCUM(w); - w = CARRYOUT(w); -#else - d = *pa++; - sum = d + *pb++; - d = (sum < d); /* detect overflow */ - *pc++ = sum += carry; - carry = d + (sum < carry); /* detect overflow */ -#endif - } - - /* If we run out of 'b' digits before we're actually done, make - sure the carries get propagated upward... - */ - for (used = MP_USED(a); ix < used; ++ix) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - w = w + *pa++; - *pc++ = ACCUM(w); - w = CARRYOUT(w); -#else - *pc++ = sum = carry + *pa++; - carry = (sum < carry); -#endif - } - - /* If there's an overall carry out, increase precision and include - it. We could have done this initially, but why touch the memory - allocator unless we're sure we have to? - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - if (w) { - if((res = s_mp_pad(c, used + 1)) != MP_OKAY) - return res; - - DIGIT(c, used) = (mp_digit)w; - ++used; - } -#else - if (carry) { - if((res = s_mp_pad(c, used + 1)) != MP_OKAY) - return res; - - DIGIT(c, used) = carry; - ++used; - } -#endif - MP_USED(c) = used; - return MP_OKAY; -} -/* {{{ s_mp_add_offset(a, b, offset) */ - -/* Compute a = |a| + ( |b| * (RADIX ** offset) ) */ -mp_err s_mp_add_offset(mp_int *a, mp_int *b, mp_size offset) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - mp_word w, k = 0; -#else - mp_digit d, sum, carry = 0; -#endif - mp_size ib; - mp_size ia; - mp_size lim; - mp_err res; - - /* Make sure a has enough precision for the output value */ - lim = MP_USED(b) + offset; - if((lim > USED(a)) && (res = s_mp_pad(a, lim)) != MP_OKAY) - return res; - - /* - Add up all digits up to the precision of b. If b had initially - the same precision as a, or greater, we took care of it by the - padding step above, so there is no problem. If b had initially - less precision, we'll have to make sure the carry out is duly - propagated upward among the higher-order digits of the sum. - */ - lim = USED(b); - for(ib = 0, ia = offset; ib < lim; ib++, ia++) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - w = (mp_word)DIGIT(a, ia) + DIGIT(b, ib) + k; - DIGIT(a, ia) = ACCUM(w); - k = CARRYOUT(w); -#else - d = MP_DIGIT(a, ia); - sum = d + MP_DIGIT(b, ib); - d = (sum < d); - MP_DIGIT(a,ia) = sum += carry; - carry = d + (sum < carry); -#endif - } - - /* If we run out of 'b' digits before we're actually done, make - sure the carries get propagated upward... - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - for (lim = MP_USED(a); k && (ia < lim); ++ia) { - w = (mp_word)DIGIT(a, ia) + k; - DIGIT(a, ia) = ACCUM(w); - k = CARRYOUT(w); - } -#else - for (lim = MP_USED(a); carry && (ia < lim); ++ia) { - d = MP_DIGIT(a, ia); - MP_DIGIT(a,ia) = sum = d + carry; - carry = (sum < d); - } -#endif - - /* If there's an overall carry out, increase precision and include - it. We could have done this initially, but why touch the memory - allocator unless we're sure we have to? - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_ADD_WORD) - if(k) { - if((res = s_mp_pad(a, USED(a) + 1)) != MP_OKAY) - return res; - - DIGIT(a, ia) = (mp_digit)k; - } -#else - if (carry) { - if((res = s_mp_pad(a, lim + 1)) != MP_OKAY) - return res; - - DIGIT(a, lim) = carry; - } -#endif - s_mp_clamp(a); - - return MP_OKAY; - -} /* end s_mp_add_offset() */ - -/* }}} */ - -/* {{{ s_mp_sub(a, b) */ - -/* Compute a = |a| - |b|, assumes |a| >= |b| */ -mp_err s_mp_sub(mp_int *a, const mp_int *b) /* magnitude subtract */ -{ - mp_digit *pa, *pb, *limit; -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - mp_sword w = 0; -#else - mp_digit d, diff, borrow = 0; -#endif - - /* - Subtract and propagate borrow. Up to the precision of b, this - accounts for the digits of b; after that, we just make sure the - carries get to the right place. This saves having to pad b out to - the precision of a just to make the loops work right... - */ - pa = MP_DIGITS(a); - pb = MP_DIGITS(b); - limit = pb + MP_USED(b); - while (pb < limit) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - w = w + *pa - *pb++; - *pa++ = ACCUM(w); - w >>= MP_DIGIT_BIT; -#else - d = *pa; - diff = d - *pb++; - d = (diff > d); /* detect borrow */ - if (borrow && --diff == MP_DIGIT_MAX) - ++d; - *pa++ = diff; - borrow = d; -#endif - } - limit = MP_DIGITS(a) + MP_USED(a); -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - while (w && pa < limit) { - w = w + *pa; - *pa++ = ACCUM(w); - w >>= MP_DIGIT_BIT; - } -#else - while (borrow && pa < limit) { - d = *pa; - *pa++ = diff = d - borrow; - borrow = (diff > d); - } -#endif - - /* Clobber any leading zeroes we created */ - s_mp_clamp(a); - - /* - If there was a borrow out, then |b| > |a| in violation - of our input invariant. We've already done the work, - but we'll at least complain about it... - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - return w ? MP_RANGE : MP_OKAY; -#else - return borrow ? MP_RANGE : MP_OKAY; -#endif -} /* end s_mp_sub() */ - -/* }}} */ - -/* Compute c = |a| - |b|, assumes |a| >= |b| */ /* magnitude subtract */ -mp_err s_mp_sub_3arg(const mp_int *a, const mp_int *b, mp_int *c) -{ - mp_digit *pa, *pb, *pc; -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - mp_sword w = 0; -#else - mp_digit d, diff, borrow = 0; -#endif - int ix, limit; - mp_err res; - - MP_SIGN(c) = MP_SIGN(a); - - /* Make sure a has enough precision for the output value */ - if (MP_OKAY != (res = s_mp_pad(c, MP_USED(a)))) - return res; - - /* - Subtract and propagate borrow. Up to the precision of b, this - accounts for the digits of b; after that, we just make sure the - carries get to the right place. This saves having to pad b out to - the precision of a just to make the loops work right... - */ - pa = MP_DIGITS(a); - pb = MP_DIGITS(b); - pc = MP_DIGITS(c); - limit = MP_USED(b); - for (ix = 0; ix < limit; ++ix) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - w = w + *pa++ - *pb++; - *pc++ = ACCUM(w); - w >>= MP_DIGIT_BIT; -#else - d = *pa++; - diff = d - *pb++; - d = (diff > d); - if (borrow && --diff == MP_DIGIT_MAX) - ++d; - *pc++ = diff; - borrow = d; -#endif - } - for (limit = MP_USED(a); ix < limit; ++ix) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - w = w + *pa++; - *pc++ = ACCUM(w); - w >>= MP_DIGIT_BIT; -#else - d = *pa++; - *pc++ = diff = d - borrow; - borrow = (diff > d); -#endif - } - - /* Clobber any leading zeroes we created */ - MP_USED(c) = ix; - s_mp_clamp(c); - - /* - If there was a borrow out, then |b| > |a| in violation - of our input invariant. We've already done the work, - but we'll at least complain about it... - */ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_SUB_WORD) - return w ? MP_RANGE : MP_OKAY; -#else - return borrow ? MP_RANGE : MP_OKAY; -#endif -} -/* {{{ s_mp_mul(a, b) */ - -/* Compute a = |a| * |b| */ -mp_err s_mp_mul(mp_int *a, const mp_int *b) -{ - return mp_mul(a, b, a); -} /* end s_mp_mul() */ - -/* }}} */ - -#if defined(MP_USE_UINT_DIGIT) && defined(MP_USE_LONG_LONG_MULTIPLY) -/* This trick works on Sparc V8 CPUs with the Workshop compilers. */ -#define MP_MUL_DxD(a, b, Phi, Plo) \ - { unsigned long long product = (unsigned long long)a * b; \ - Plo = (mp_digit)product; \ - Phi = (mp_digit)(product >> MP_DIGIT_BIT); } -#elif defined(OSF1) -#define MP_MUL_DxD(a, b, Phi, Plo) \ - { Plo = asm ("mulq %a0, %a1, %v0", a, b);\ - Phi = asm ("umulh %a0, %a1, %v0", a, b); } -#else -#define MP_MUL_DxD(a, b, Phi, Plo) \ - { mp_digit a0b1, a1b0; \ - Plo = (a & MP_HALF_DIGIT_MAX) * (b & MP_HALF_DIGIT_MAX); \ - Phi = (a >> MP_HALF_DIGIT_BIT) * (b >> MP_HALF_DIGIT_BIT); \ - a0b1 = (a & MP_HALF_DIGIT_MAX) * (b >> MP_HALF_DIGIT_BIT); \ - a1b0 = (a >> MP_HALF_DIGIT_BIT) * (b & MP_HALF_DIGIT_MAX); \ - a1b0 += a0b1; \ - Phi += a1b0 >> MP_HALF_DIGIT_BIT; \ - if (a1b0 < a0b1) \ - Phi += MP_HALF_RADIX; \ - a1b0 <<= MP_HALF_DIGIT_BIT; \ - Plo += a1b0; \ - if (Plo < a1b0) \ - ++Phi; \ - } -#endif - -#if !defined(MP_ASSEMBLY_MULTIPLY) -/* c = a * b */ -void s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD) - mp_digit d = 0; - - /* Inner product: Digits of a */ - while (a_len--) { - mp_word w = ((mp_word)b * *a++) + d; - *c++ = ACCUM(w); - d = CARRYOUT(w); - } - *c = d; -#else - mp_digit carry = 0; - while (a_len--) { - mp_digit a_i = *a++; - mp_digit a0b0, a1b1; - - MP_MUL_DxD(a_i, b, a1b1, a0b0); - - a0b0 += carry; - if (a0b0 < carry) - ++a1b1; - *c++ = a0b0; - carry = a1b1; - } - *c = carry; -#endif -} - -/* c += a * b */ -void s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, - mp_digit *c) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD) - mp_digit d = 0; - - /* Inner product: Digits of a */ - while (a_len--) { - mp_word w = ((mp_word)b * *a++) + *c + d; - *c++ = ACCUM(w); - d = CARRYOUT(w); - } - *c = d; -#else - mp_digit carry = 0; - while (a_len--) { - mp_digit a_i = *a++; - mp_digit a0b0, a1b1; - - MP_MUL_DxD(a_i, b, a1b1, a0b0); - - a0b0 += carry; - if (a0b0 < carry) - ++a1b1; - a0b0 += a_i = *c; - if (a0b0 < a_i) - ++a1b1; - *c++ = a0b0; - carry = a1b1; - } - *c = carry; -#endif -} - -/* Presently, this is only used by the Montgomery arithmetic code. */ -/* c += a * b */ -void s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD) - mp_digit d = 0; - - /* Inner product: Digits of a */ - while (a_len--) { - mp_word w = ((mp_word)b * *a++) + *c + d; - *c++ = ACCUM(w); - d = CARRYOUT(w); - } - - while (d) { - mp_word w = (mp_word)*c + d; - *c++ = ACCUM(w); - d = CARRYOUT(w); - } -#else - mp_digit carry = 0; - while (a_len--) { - mp_digit a_i = *a++; - mp_digit a0b0, a1b1; - - MP_MUL_DxD(a_i, b, a1b1, a0b0); - - a0b0 += carry; - if (a0b0 < carry) - ++a1b1; - - a0b0 += a_i = *c; - if (a0b0 < a_i) - ++a1b1; - - *c++ = a0b0; - carry = a1b1; - } - while (carry) { - mp_digit c_i = *c; - carry += c_i; - *c++ = carry; - carry = carry < c_i; - } -#endif -} -#endif - -#if defined(MP_USE_UINT_DIGIT) && defined(MP_USE_LONG_LONG_MULTIPLY) -/* This trick works on Sparc V8 CPUs with the Workshop compilers. */ -#define MP_SQR_D(a, Phi, Plo) \ - { unsigned long long square = (unsigned long long)a * a; \ - Plo = (mp_digit)square; \ - Phi = (mp_digit)(square >> MP_DIGIT_BIT); } -#elif defined(OSF1) -#define MP_SQR_D(a, Phi, Plo) \ - { Plo = asm ("mulq %a0, %a0, %v0", a);\ - Phi = asm ("umulh %a0, %a0, %v0", a); } -#else -#define MP_SQR_D(a, Phi, Plo) \ - { mp_digit Pmid; \ - Plo = (a & MP_HALF_DIGIT_MAX) * (a & MP_HALF_DIGIT_MAX); \ - Phi = (a >> MP_HALF_DIGIT_BIT) * (a >> MP_HALF_DIGIT_BIT); \ - Pmid = (a & MP_HALF_DIGIT_MAX) * (a >> MP_HALF_DIGIT_BIT); \ - Phi += Pmid >> (MP_HALF_DIGIT_BIT - 1); \ - Pmid <<= (MP_HALF_DIGIT_BIT + 1); \ - Plo += Pmid; \ - if (Plo < Pmid) \ - ++Phi; \ - } -#endif - -#if !defined(MP_ASSEMBLY_SQUARE) -/* Add the squares of the digits of a to the digits of b. */ -void s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps) -{ -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_MUL_WORD) - mp_word w; - mp_digit d; - mp_size ix; - - w = 0; -#define ADD_SQUARE(n) \ - d = pa[n]; \ - w += (d * (mp_word)d) + ps[2*n]; \ - ps[2*n] = ACCUM(w); \ - w = (w >> DIGIT_BIT) + ps[2*n+1]; \ - ps[2*n+1] = ACCUM(w); \ - w = (w >> DIGIT_BIT) - - for (ix = a_len; ix >= 4; ix -= 4) { - ADD_SQUARE(0); - ADD_SQUARE(1); - ADD_SQUARE(2); - ADD_SQUARE(3); - pa += 4; - ps += 8; - } - if (ix) { - ps += 2*ix; - pa += ix; - switch (ix) { - case 3: ADD_SQUARE(-3); /* FALLTHRU */ - case 2: ADD_SQUARE(-2); /* FALLTHRU */ - case 1: ADD_SQUARE(-1); /* FALLTHRU */ - case 0: break; - } - } - while (w) { - w += *ps; - *ps++ = ACCUM(w); - w = (w >> DIGIT_BIT); - } -#else - mp_digit carry = 0; - while (a_len--) { - mp_digit a_i = *pa++; - mp_digit a0a0, a1a1; - - MP_SQR_D(a_i, a1a1, a0a0); - - /* here a1a1 and a0a0 constitute a_i ** 2 */ - a0a0 += carry; - if (a0a0 < carry) - ++a1a1; - - /* now add to ps */ - a0a0 += a_i = *ps; - if (a0a0 < a_i) - ++a1a1; - *ps++ = a0a0; - a1a1 += a_i = *ps; - carry = (a1a1 < a_i); - *ps++ = a1a1; - } - while (carry) { - mp_digit s_i = *ps; - carry += s_i; - *ps++ = carry; - carry = carry < s_i; - } -#endif -} -#endif - -#if (defined(MP_NO_MP_WORD) || defined(MP_NO_DIV_WORD)) \ -&& !defined(MP_ASSEMBLY_DIV_2DX1D) -/* -** Divide 64-bit (Nhi,Nlo) by 32-bit divisor, which must be normalized -** so its high bit is 1. This code is from NSPR. -*/ -mp_err s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo, mp_digit divisor, - mp_digit *qp, mp_digit *rp) -{ - mp_digit d1, d0, q1, q0; - mp_digit r1, r0, m; - - d1 = divisor >> MP_HALF_DIGIT_BIT; - d0 = divisor & MP_HALF_DIGIT_MAX; - r1 = Nhi % d1; - q1 = Nhi / d1; - m = q1 * d0; - r1 = (r1 << MP_HALF_DIGIT_BIT) | (Nlo >> MP_HALF_DIGIT_BIT); - if (r1 < m) { - q1--, r1 += divisor; - if (r1 >= divisor && r1 < m) { - q1--, r1 += divisor; - } - } - r1 -= m; - r0 = r1 % d1; - q0 = r1 / d1; - m = q0 * d0; - r0 = (r0 << MP_HALF_DIGIT_BIT) | (Nlo & MP_HALF_DIGIT_MAX); - if (r0 < m) { - q0--, r0 += divisor; - if (r0 >= divisor && r0 < m) { - q0--, r0 += divisor; - } - } - if (qp) - *qp = (q1 << MP_HALF_DIGIT_BIT) | q0; - if (rp) - *rp = r0 - m; - return MP_OKAY; -} -#endif - -#if MP_SQUARE -/* {{{ s_mp_sqr(a) */ - -mp_err s_mp_sqr(mp_int *a) -{ - mp_err res; - mp_int tmp; - tmp.flag = (mp_sign)0; - - if((res = mp_init_size(&tmp, 2 * USED(a), FLAG(a))) != MP_OKAY) - return res; - res = mp_sqr(a, &tmp); - if (res == MP_OKAY) { - s_mp_exch(&tmp, a); - } - mp_clear(&tmp); - return res; -} - -/* }}} */ -#endif - -/* {{{ s_mp_div(a, b) */ - -/* - s_mp_div(a, b) - - Compute a = a / b and b = a mod b. Assumes b > a. - */ - -mp_err s_mp_div(mp_int *rem, /* i: dividend, o: remainder */ - mp_int *div, /* i: divisor */ - mp_int *quot) /* i: 0; o: quotient */ -{ - mp_int part, t; -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD) - mp_word q_msd; -#else - mp_digit q_msd; -#endif - mp_err res; - mp_digit d; - mp_digit div_msd; - int ix; - - t.dp = (mp_digit *)NULL; - - if(mp_cmp_z(div) == 0) - return MP_RANGE; - - /* Shortcut if divisor is power of two */ - if((ix = s_mp_ispow2(div)) >= 0) { - MP_CHECKOK( mp_copy(rem, quot) ); - s_mp_div_2d(quot, (mp_digit)ix); - s_mp_mod_2d(rem, (mp_digit)ix); - - return MP_OKAY; - } - - DIGITS(&t) = 0; - MP_SIGN(rem) = ZPOS; - MP_SIGN(div) = ZPOS; - - /* A working temporary for division */ - MP_CHECKOK( mp_init_size(&t, MP_ALLOC(rem), FLAG(rem))); - - /* Normalize to optimize guessing */ - MP_CHECKOK( s_mp_norm(rem, div, &d) ); - - part = *rem; - - /* Perform the division itself...woo! */ - MP_USED(quot) = MP_ALLOC(quot); - - /* Find a partial substring of rem which is at least div */ - /* If we didn't find one, we're finished dividing */ - while (MP_USED(rem) > MP_USED(div) || s_mp_cmp(rem, div) >= 0) { - int i; - int unusedRem; - - unusedRem = MP_USED(rem) - MP_USED(div); - MP_DIGITS(&part) = MP_DIGITS(rem) + unusedRem; - MP_ALLOC(&part) = MP_ALLOC(rem) - unusedRem; - MP_USED(&part) = MP_USED(div); - if (s_mp_cmp(&part, div) < 0) { - -- unusedRem; -#if MP_ARGCHK == 2 - assert(unusedRem >= 0); -#endif - -- MP_DIGITS(&part); - ++ MP_USED(&part); - ++ MP_ALLOC(&part); - } - - /* Compute a guess for the next quotient digit */ - q_msd = MP_DIGIT(&part, MP_USED(&part) - 1); - div_msd = MP_DIGIT(div, MP_USED(div) - 1); - if (q_msd >= div_msd) { - q_msd = 1; - } else if (MP_USED(&part) > 1) { -#if !defined(MP_NO_MP_WORD) && !defined(MP_NO_DIV_WORD) - q_msd = (q_msd << MP_DIGIT_BIT) | MP_DIGIT(&part, MP_USED(&part) - 2); - q_msd /= div_msd; - if (q_msd == RADIX) - --q_msd; -#else - mp_digit r; - MP_CHECKOK( s_mpv_div_2dx1d(q_msd, MP_DIGIT(&part, MP_USED(&part) - 2), - div_msd, &q_msd, &r) ); -#endif - } else { - q_msd = 0; - } -#if MP_ARGCHK == 2 - assert(q_msd > 0); /* This case should never occur any more. */ -#endif - if (q_msd <= 0) - break; - - /* See what that multiplies out to */ - mp_copy(div, &t); - MP_CHECKOK( s_mp_mul_d(&t, (mp_digit)q_msd) ); - - /* - If it's too big, back it off. We should not have to do this - more than once, or, in rare cases, twice. Knuth describes a - method by which this could be reduced to a maximum of once, but - I didn't implement that here. - * When using s_mpv_div_2dx1d, we may have to do this 3 times. - */ - for (i = 4; s_mp_cmp(&t, &part) > 0 && i > 0; --i) { - --q_msd; - s_mp_sub(&t, div); /* t -= div */ - } - if (i < 0) { - res = MP_RANGE; - goto CLEANUP; - } - - /* At this point, q_msd should be the right next digit */ - MP_CHECKOK( s_mp_sub(&part, &t) ); /* part -= t */ - s_mp_clamp(rem); - - /* - Include the digit in the quotient. We allocated enough memory - for any quotient we could ever possibly get, so we should not - have to check for failures here - */ - MP_DIGIT(quot, unusedRem) = (mp_digit)q_msd; - } - - /* Denormalize remainder */ - if (d) { - s_mp_div_2d(rem, d); - } - - s_mp_clamp(quot); - -CLEANUP: - mp_clear(&t); - - return res; - -} /* end s_mp_div() */ - - -/* }}} */ - -/* {{{ s_mp_2expt(a, k) */ - -mp_err s_mp_2expt(mp_int *a, mp_digit k) -{ - mp_err res; - mp_size dig, bit; - - dig = k / DIGIT_BIT; - bit = k % DIGIT_BIT; - - mp_zero(a); - if((res = s_mp_pad(a, dig + 1)) != MP_OKAY) - return res; - - DIGIT(a, dig) |= ((mp_digit)1 << bit); - - return MP_OKAY; - -} /* end s_mp_2expt() */ - -/* }}} */ - -/* {{{ s_mp_reduce(x, m, mu) */ - -/* - Compute Barrett reduction, x (mod m), given a precomputed value for - mu = b^2k / m, where b = RADIX and k = #digits(m). This should be - faster than straight division, when many reductions by the same - value of m are required (such as in modular exponentiation). This - can nearly halve the time required to do modular exponentiation, - as compared to using the full integer divide to reduce. - - This algorithm was derived from the _Handbook of Applied - Cryptography_ by Menezes, Oorschot and VanStone, Ch. 14, - pp. 603-604. - */ - -mp_err s_mp_reduce(mp_int *x, const mp_int *m, const mp_int *mu) -{ - mp_int q; - mp_err res; - - if((res = mp_init_copy(&q, x)) != MP_OKAY) - return res; - - s_mp_rshd(&q, USED(m) - 1); /* q1 = x / b^(k-1) */ - s_mp_mul(&q, mu); /* q2 = q1 * mu */ - s_mp_rshd(&q, USED(m) + 1); /* q3 = q2 / b^(k+1) */ - - /* x = x mod b^(k+1), quick (no division) */ - s_mp_mod_2d(x, DIGIT_BIT * (USED(m) + 1)); - - /* q = q * m mod b^(k+1), quick (no division) */ - s_mp_mul(&q, m); - s_mp_mod_2d(&q, DIGIT_BIT * (USED(m) + 1)); - - /* x = x - q */ - if((res = mp_sub(x, &q, x)) != MP_OKAY) - goto CLEANUP; - - /* If x < 0, add b^(k+1) to it */ - if(mp_cmp_z(x) < 0) { - mp_set(&q, 1); - if((res = s_mp_lshd(&q, USED(m) + 1)) != MP_OKAY) - goto CLEANUP; - if((res = mp_add(x, &q, x)) != MP_OKAY) - goto CLEANUP; - } - - /* Back off if it's too big */ - while(mp_cmp(x, m) >= 0) { - if((res = s_mp_sub(x, m)) != MP_OKAY) - break; - } - - CLEANUP: - mp_clear(&q); - - return res; - -} /* end s_mp_reduce() */ - -/* }}} */ - -/* }}} */ - -/* {{{ Primitive comparisons */ - -/* {{{ s_mp_cmp(a, b) */ - -/* Compare |a| <=> |b|, return 0 if equal, <0 if a0 if a>b */ -int s_mp_cmp(const mp_int *a, const mp_int *b) -{ - mp_size used_a = MP_USED(a); - { - mp_size used_b = MP_USED(b); - - if (used_a > used_b) - goto IS_GT; - if (used_a < used_b) - goto IS_LT; - } - { - mp_digit *pa, *pb; - mp_digit da = 0, db = 0; - -#define CMP_AB(n) if ((da = pa[n]) != (db = pb[n])) goto done - - pa = MP_DIGITS(a) + used_a; - pb = MP_DIGITS(b) + used_a; - while (used_a >= 4) { - pa -= 4; - pb -= 4; - used_a -= 4; - CMP_AB(3); - CMP_AB(2); - CMP_AB(1); - CMP_AB(0); - } - while (used_a-- > 0 && ((da = *--pa) == (db = *--pb))) - /* do nothing */; -done: - if (da > db) - goto IS_GT; - if (da < db) - goto IS_LT; - } - return MP_EQ; -IS_LT: - return MP_LT; -IS_GT: - return MP_GT; -} /* end s_mp_cmp() */ - -/* }}} */ - -/* {{{ s_mp_cmp_d(a, d) */ - -/* Compare |a| <=> d, return 0 if equal, <0 if a0 if a>d */ -int s_mp_cmp_d(const mp_int *a, mp_digit d) -{ - if(USED(a) > 1) - return MP_GT; - - if(DIGIT(a, 0) < d) - return MP_LT; - else if(DIGIT(a, 0) > d) - return MP_GT; - else - return MP_EQ; - -} /* end s_mp_cmp_d() */ - -/* }}} */ - -/* {{{ s_mp_ispow2(v) */ - -/* - Returns -1 if the value is not a power of two; otherwise, it returns - k such that v = 2^k, i.e. lg(v). - */ -int s_mp_ispow2(const mp_int *v) -{ - mp_digit d; - int extra = 0, ix; - - ix = MP_USED(v) - 1; - d = MP_DIGIT(v, ix); /* most significant digit of v */ - - extra = s_mp_ispow2d(d); - if (extra < 0 || ix == 0) - return extra; - - while (--ix >= 0) { - if (DIGIT(v, ix) != 0) - return -1; /* not a power of two */ - extra += MP_DIGIT_BIT; - } - - return extra; - -} /* end s_mp_ispow2() */ - -/* }}} */ - -/* {{{ s_mp_ispow2d(d) */ - -int s_mp_ispow2d(mp_digit d) -{ - if ((d != 0) && ((d & (d-1)) == 0)) { /* d is a power of 2 */ - int pow = 0; -#if defined (MP_USE_UINT_DIGIT) - if (d & 0xffff0000U) - pow += 16; - if (d & 0xff00ff00U) - pow += 8; - if (d & 0xf0f0f0f0U) - pow += 4; - if (d & 0xccccccccU) - pow += 2; - if (d & 0xaaaaaaaaU) - pow += 1; -#elif defined(MP_USE_LONG_LONG_DIGIT) - if (d & 0xffffffff00000000ULL) - pow += 32; - if (d & 0xffff0000ffff0000ULL) - pow += 16; - if (d & 0xff00ff00ff00ff00ULL) - pow += 8; - if (d & 0xf0f0f0f0f0f0f0f0ULL) - pow += 4; - if (d & 0xccccccccccccccccULL) - pow += 2; - if (d & 0xaaaaaaaaaaaaaaaaULL) - pow += 1; -#elif defined(MP_USE_LONG_DIGIT) - if (d & 0xffffffff00000000UL) - pow += 32; - if (d & 0xffff0000ffff0000UL) - pow += 16; - if (d & 0xff00ff00ff00ff00UL) - pow += 8; - if (d & 0xf0f0f0f0f0f0f0f0UL) - pow += 4; - if (d & 0xccccccccccccccccUL) - pow += 2; - if (d & 0xaaaaaaaaaaaaaaaaUL) - pow += 1; -#else -#error "unknown type for mp_digit" -#endif - return pow; - } - return -1; - -} /* end s_mp_ispow2d() */ - -/* }}} */ - -/* }}} */ - -/* {{{ Primitive I/O helpers */ - -/* {{{ s_mp_tovalue(ch, r) */ - -/* - Convert the given character to its digit value, in the given radix. - If the given character is not understood in the given radix, -1 is - returned. Otherwise the digit's numeric value is returned. - - The results will be odd if you use a radix < 2 or > 62, you are - expected to know what you're up to. - */ -int s_mp_tovalue(char ch, int r) -{ - int val, xch; - - if(r > 36) - xch = ch; - else - xch = toupper(ch); - - if(isdigit(xch)) - val = xch - '0'; - else if(isupper(xch)) - val = xch - 'A' + 10; - else if(islower(xch)) - val = xch - 'a' + 36; - else if(xch == '+') - val = 62; - else if(xch == '/') - val = 63; - else - return -1; - - if(val < 0 || val >= r) - return -1; - - return val; - -} /* end s_mp_tovalue() */ - -/* }}} */ - -/* {{{ s_mp_todigit(val, r, low) */ - -/* - Convert val to a radix-r digit, if possible. If val is out of range - for r, returns zero. Otherwise, returns an ASCII character denoting - the value in the given radix. - - The results may be odd if you use a radix < 2 or > 64, you are - expected to know what you're doing. - */ - -char s_mp_todigit(mp_digit val, int r, int low) -{ - char ch; - - if(val >= (unsigned int)r) - return 0; - - ch = s_dmap_1[val]; - - if(r <= 36 && low) - ch = tolower(ch); - - return ch; - -} /* end s_mp_todigit() */ - -/* }}} */ - -/* {{{ s_mp_outlen(bits, radix) */ - -/* - Return an estimate for how long a string is needed to hold a radix - r representation of a number with 'bits' significant bits, plus an - extra for a zero terminator (assuming C style strings here) - */ -int s_mp_outlen(int bits, int r) -{ - return (int)((double)bits * LOG_V_2(r) + 1.5) + 1; - -} /* end s_mp_outlen() */ - -/* }}} */ - -/* }}} */ - -/* {{{ mp_read_unsigned_octets(mp, str, len) */ -/* mp_read_unsigned_octets(mp, str, len) - Read in a raw value (base 256) into the given mp_int - No sign bit, number is positive. Leading zeros ignored. - */ - -mp_err -mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len) -{ - int count; - mp_err res; - mp_digit d; - - ARGCHK(mp != NULL && str != NULL && len > 0, MP_BADARG); - - mp_zero(mp); - - count = len % sizeof(mp_digit); - if (count) { - for (d = 0; count-- > 0; --len) { - d = (d << 8) | *str++; - } - MP_DIGIT(mp, 0) = d; - } - - /* Read the rest of the digits */ - for(; len > 0; len -= sizeof(mp_digit)) { - for (d = 0, count = sizeof(mp_digit); count > 0; --count) { - d = (d << 8) | *str++; - } - if (MP_EQ == mp_cmp_z(mp)) { - if (!d) - continue; - } else { - if((res = s_mp_lshd(mp, 1)) != MP_OKAY) - return res; - } - MP_DIGIT(mp, 0) = d; - } - return MP_OKAY; -} /* end mp_read_unsigned_octets() */ -/* }}} */ - -/* {{{ mp_unsigned_octet_size(mp) */ -int -mp_unsigned_octet_size(const mp_int *mp) -{ - int bytes; - int ix; - mp_digit d = 0; - - ARGCHK(mp != NULL, MP_BADARG); - ARGCHK(MP_ZPOS == SIGN(mp), MP_BADARG); - - bytes = (USED(mp) * sizeof(mp_digit)); - - /* subtract leading zeros. */ - /* Iterate over each digit... */ - for(ix = USED(mp) - 1; ix >= 0; ix--) { - d = DIGIT(mp, ix); - if (d) - break; - bytes -= sizeof(d); - } - if (!bytes) - return 1; - - /* Have MSD, check digit bytes, high order first */ - for(ix = sizeof(mp_digit) - 1; ix >= 0; ix--) { - unsigned char x = (unsigned char)(d >> (ix * CHAR_BIT)); - if (x) - break; - --bytes; - } - return bytes; -} /* end mp_unsigned_octet_size() */ -/* }}} */ - -/* {{{ mp_to_unsigned_octets(mp, str) */ -/* output a buffer of big endian octets no longer than specified. */ -mp_err -mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen) -{ - int ix, pos = 0; - unsigned int bytes; - - ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG); - - bytes = mp_unsigned_octet_size(mp); - ARGCHK(bytes <= maxlen, MP_BADARG); - - /* Iterate over each digit... */ - for(ix = USED(mp) - 1; ix >= 0; ix--) { - mp_digit d = DIGIT(mp, ix); - int jx; - - /* Unpack digit bytes, high order first */ - for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) { - unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT)); - if (!pos && !x) /* suppress leading zeros */ - continue; - str[pos++] = x; - } - } - if (!pos) - str[pos++] = 0; - return pos; -} /* end mp_to_unsigned_octets() */ -/* }}} */ - -/* {{{ mp_to_signed_octets(mp, str) */ -/* output a buffer of big endian octets no longer than specified. */ -mp_err -mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen) -{ - int ix, pos = 0; - unsigned int bytes; - - ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG); - - bytes = mp_unsigned_octet_size(mp); - ARGCHK(bytes <= maxlen, MP_BADARG); - - /* Iterate over each digit... */ - for(ix = USED(mp) - 1; ix >= 0; ix--) { - mp_digit d = DIGIT(mp, ix); - int jx; - - /* Unpack digit bytes, high order first */ - for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) { - unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT)); - if (!pos) { - if (!x) /* suppress leading zeros */ - continue; - if (x & 0x80) { /* add one leading zero to make output positive. */ - ARGCHK(bytes + 1 <= maxlen, MP_BADARG); - if (bytes + 1 > maxlen) - return MP_BADARG; - str[pos++] = 0; - } - } - str[pos++] = x; - } - } - if (!pos) - str[pos++] = 0; - return pos; -} /* end mp_to_signed_octets() */ -/* }}} */ - -/* {{{ mp_to_fixlen_octets(mp, str) */ -/* output a buffer of big endian octets exactly as long as requested. */ -mp_err -mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size length) -{ - int ix, pos = 0; - unsigned int bytes; - - ARGCHK(mp != NULL && str != NULL && !SIGN(mp), MP_BADARG); - - bytes = mp_unsigned_octet_size(mp); - ARGCHK(bytes <= length, MP_BADARG); - - /* place any needed leading zeros */ - for (;length > bytes; --length) { - *str++ = 0; - } - - /* Iterate over each digit... */ - for(ix = USED(mp) - 1; ix >= 0; ix--) { - mp_digit d = DIGIT(mp, ix); - int jx; - - /* Unpack digit bytes, high order first */ - for(jx = sizeof(mp_digit) - 1; jx >= 0; jx--) { - unsigned char x = (unsigned char)(d >> (jx * CHAR_BIT)); - if (!pos && !x) /* suppress leading zeros */ - continue; - str[pos++] = x; - } - } - if (!pos) - str[pos++] = 0; - return MP_OKAY; -} /* end mp_to_fixlen_octets() */ -/* }}} */ - - -/*------------------------------------------------------------------------*/ -/* HERE THERE BE DRAGONS */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.h deleted file mode 100644 index 4a8eb2c5c0320..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpi.h +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Netscape Communications Corporation - * - *********************************************************************** */ - -/* Arbitrary precision integer arithmetic library */ - -#ifndef _MPI_H -#define _MPI_H - -/* $Id: mpi.h,v 1.22 2004/04/27 23:04:36 gerv%gerv.net Exp $ */ - -#include "mpi-config.h" - -#ifndef _WIN32 -#include -#endif /* _WIN32 */ - -#ifdef _KERNEL -#include -#include -#define assert ASSERT -#define labs(a) (a >= 0 ? a : -a) -#define UCHAR_MAX 255 -#define memset(s, c, n) bzero(s, n) -#define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c) -/* - * Generic #define's to cover missing things in the kernel - */ -#ifndef isdigit -#define isdigit(x) ((x) >= '0' && (x) <= '9') -#endif -#ifndef isupper -#define isupper(x) (((unsigned)(x) >= 'A') && ((unsigned)(x) <= 'Z')) -#endif -#ifndef islower -#define islower(x) (((unsigned)(x) >= 'a') && ((unsigned)(x) <= 'z')) -#endif -#ifndef isalpha -#define isalpha(x) (isupper(x) || islower(x)) -#endif -#ifndef toupper -#define toupper(x) (islower(x) ? (x) - 'a' + 'A' : (x)) -#endif -#ifndef tolower -#define tolower(x) (isupper(x) ? (x) + 'a' - 'A' : (x)) -#endif -#ifndef isspace -#define isspace(x) (((x) == ' ') || ((x) == '\r') || ((x) == '\n') || \ - ((x) == '\t') || ((x) == '\b')) -#endif -#endif /* _KERNEL */ - -#if MP_DEBUG -#undef MP_IOFUNC -#define MP_IOFUNC 1 -#endif - -#if MP_IOFUNC -#include -#include -#endif - -#ifndef _KERNEL -#include -#endif - -#if defined(BSDI) -#undef ULLONG_MAX -#endif - -#if defined( macintosh ) -#include -#elif defined( _WIN32_WCE) -/* #include What do we need here ?? */ -#else -#include -#endif - -#define MP_NEG 1 -#define MP_ZPOS 0 - -#define MP_OKAY 0 /* no error, all is well */ -#define MP_YES 0 /* yes (boolean result) */ -#define MP_NO -1 /* no (boolean result) */ -#define MP_MEM -2 /* out of memory */ -#define MP_RANGE -3 /* argument out of range */ -#define MP_BADARG -4 /* invalid parameter */ -#define MP_UNDEF -5 /* answer is undefined */ -#define MP_LAST_CODE MP_UNDEF - -typedef unsigned int mp_sign; -typedef unsigned int mp_size; -typedef int mp_err; -typedef int mp_flag; - -#define MP_32BIT_MAX 4294967295U - -#if !defined(ULONG_MAX) -#error "ULONG_MAX not defined" -#elif !defined(UINT_MAX) -#error "UINT_MAX not defined" -#elif !defined(USHRT_MAX) -#error "USHRT_MAX not defined" -#endif - -#if defined(ULONG_LONG_MAX) /* GCC, HPUX */ -#define MP_ULONG_LONG_MAX ULONG_LONG_MAX -#elif defined(ULLONG_MAX) /* Solaris */ -#define MP_ULONG_LONG_MAX ULLONG_MAX -/* MP_ULONG_LONG_MAX was defined to be ULLONG_MAX */ -#elif defined(ULONGLONG_MAX) /* IRIX, AIX */ -#define MP_ULONG_LONG_MAX ULONGLONG_MAX -#endif - -/* We only use unsigned long for mp_digit iff long is more than 32 bits. */ -#if !defined(MP_USE_UINT_DIGIT) && ULONG_MAX > MP_32BIT_MAX -typedef unsigned long mp_digit; -#define MP_DIGIT_MAX ULONG_MAX -#define MP_DIGIT_FMT "%016lX" /* printf() format for 1 digit */ -#define MP_HALF_DIGIT_MAX UINT_MAX -#undef MP_NO_MP_WORD -#define MP_NO_MP_WORD 1 -#undef MP_USE_LONG_DIGIT -#define MP_USE_LONG_DIGIT 1 -#undef MP_USE_LONG_LONG_DIGIT - -#elif !defined(MP_USE_UINT_DIGIT) && defined(MP_ULONG_LONG_MAX) -typedef unsigned long long mp_digit; -#define MP_DIGIT_MAX MP_ULONG_LONG_MAX -#define MP_DIGIT_FMT "%016llX" /* printf() format for 1 digit */ -#define MP_HALF_DIGIT_MAX UINT_MAX -#undef MP_NO_MP_WORD -#define MP_NO_MP_WORD 1 -#undef MP_USE_LONG_LONG_DIGIT -#define MP_USE_LONG_LONG_DIGIT 1 -#undef MP_USE_LONG_DIGIT - -#else -typedef unsigned int mp_digit; -#define MP_DIGIT_MAX UINT_MAX -#define MP_DIGIT_FMT "%08X" /* printf() format for 1 digit */ -#define MP_HALF_DIGIT_MAX USHRT_MAX -#undef MP_USE_UINT_DIGIT -#define MP_USE_UINT_DIGIT 1 -#undef MP_USE_LONG_LONG_DIGIT -#undef MP_USE_LONG_DIGIT -#endif - -#if !defined(MP_NO_MP_WORD) -#if defined(MP_USE_UINT_DIGIT) && \ - (defined(MP_ULONG_LONG_MAX) || (ULONG_MAX > UINT_MAX)) - -#if (ULONG_MAX > UINT_MAX) -typedef unsigned long mp_word; -typedef long mp_sword; -#define MP_WORD_MAX ULONG_MAX - -#else -typedef unsigned long long mp_word; -typedef long long mp_sword; -#define MP_WORD_MAX MP_ULONG_LONG_MAX -#endif - -#else -#define MP_NO_MP_WORD 1 -#endif -#endif /* !defined(MP_NO_MP_WORD) */ - -#if !defined(MP_WORD_MAX) && defined(MP_DEFINE_SMALL_WORD) -typedef unsigned int mp_word; -typedef int mp_sword; -#define MP_WORD_MAX UINT_MAX -#endif - -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif - -#define MP_DIGIT_BIT (CHAR_BIT*sizeof(mp_digit)) -#define MP_WORD_BIT (CHAR_BIT*sizeof(mp_word)) -#define MP_RADIX (1+(mp_word)MP_DIGIT_MAX) - -#define MP_HALF_DIGIT_BIT (MP_DIGIT_BIT/2) -#define MP_HALF_RADIX (1+(mp_digit)MP_HALF_DIGIT_MAX) -/* MP_HALF_RADIX really ought to be called MP_SQRT_RADIX, but it's named -** MP_HALF_RADIX because it's the radix for MP_HALF_DIGITs, and it's -** consistent with the other _HALF_ names. -*/ - - -/* Macros for accessing the mp_int internals */ -#define MP_FLAG(MP) ((MP)->flag) -#define MP_SIGN(MP) ((MP)->sign) -#define MP_USED(MP) ((MP)->used) -#define MP_ALLOC(MP) ((MP)->alloc) -#define MP_DIGITS(MP) ((MP)->dp) -#define MP_DIGIT(MP,N) (MP)->dp[(N)] - -/* This defines the maximum I/O base (minimum is 2) */ -#define MP_MAX_RADIX 64 - -typedef struct { - mp_sign flag; /* KM_SLEEP/KM_NOSLEEP */ - mp_sign sign; /* sign of this quantity */ - mp_size alloc; /* how many digits allocated */ - mp_size used; /* how many digits used */ - mp_digit *dp; /* the digits themselves */ -} mp_int; - -/* Default precision */ -mp_size mp_get_prec(void); -void mp_set_prec(mp_size prec); - -/* Memory management */ -mp_err mp_init(mp_int *mp, int kmflag); -mp_err mp_init_size(mp_int *mp, mp_size prec, int kmflag); -mp_err mp_init_copy(mp_int *mp, const mp_int *from); -mp_err mp_copy(const mp_int *from, mp_int *to); -void mp_exch(mp_int *mp1, mp_int *mp2); -void mp_clear(mp_int *mp); -void mp_zero(mp_int *mp); -void mp_set(mp_int *mp, mp_digit d); -mp_err mp_set_int(mp_int *mp, long z); -#define mp_set_long(mp,z) mp_set_int(mp,z) -mp_err mp_set_ulong(mp_int *mp, unsigned long z); - -/* Single digit arithmetic */ -mp_err mp_add_d(const mp_int *a, mp_digit d, mp_int *b); -mp_err mp_sub_d(const mp_int *a, mp_digit d, mp_int *b); -mp_err mp_mul_d(const mp_int *a, mp_digit d, mp_int *b); -mp_err mp_mul_2(const mp_int *a, mp_int *c); -mp_err mp_div_d(const mp_int *a, mp_digit d, mp_int *q, mp_digit *r); -mp_err mp_div_2(const mp_int *a, mp_int *c); -mp_err mp_expt_d(const mp_int *a, mp_digit d, mp_int *c); - -/* Sign manipulations */ -mp_err mp_abs(const mp_int *a, mp_int *b); -mp_err mp_neg(const mp_int *a, mp_int *b); - -/* Full arithmetic */ -mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c); -mp_err mp_sub(const mp_int *a, const mp_int *b, mp_int *c); -mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c); -#if MP_SQUARE -mp_err mp_sqr(const mp_int *a, mp_int *b); -#else -#define mp_sqr(a, b) mp_mul(a, a, b) -#endif -mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); -mp_err mp_div_2d(const mp_int *a, mp_digit d, mp_int *q, mp_int *r); -mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c); -mp_err mp_2expt(mp_int *a, mp_digit k); -mp_err mp_sqrt(const mp_int *a, mp_int *b); - -/* Modular arithmetic */ -#if MP_MODARITH -mp_err mp_mod(const mp_int *a, const mp_int *m, mp_int *c); -mp_err mp_mod_d(const mp_int *a, mp_digit d, mp_digit *c); -mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c); -mp_err mp_submod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c); -mp_err mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c); -#if MP_SQUARE -mp_err mp_sqrmod(const mp_int *a, const mp_int *m, mp_int *c); -#else -#define mp_sqrmod(a, m, c) mp_mulmod(a, a, m, c) -#endif -mp_err mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *m, mp_int *c); -mp_err mp_exptmod_d(const mp_int *a, mp_digit d, const mp_int *m, mp_int *c); -#endif /* MP_MODARITH */ - -/* Comparisons */ -int mp_cmp_z(const mp_int *a); -int mp_cmp_d(const mp_int *a, mp_digit d); -int mp_cmp(const mp_int *a, const mp_int *b); -int mp_cmp_mag(mp_int *a, mp_int *b); -int mp_cmp_int(const mp_int *a, long z, int kmflag); -int mp_isodd(const mp_int *a); -int mp_iseven(const mp_int *a); - -/* Number theoretic */ -#if MP_NUMTH -mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c); -mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c); -mp_err mp_xgcd(const mp_int *a, const mp_int *b, mp_int *g, mp_int *x, mp_int *y); -mp_err mp_invmod(const mp_int *a, const mp_int *m, mp_int *c); -mp_err mp_invmod_xgcd(const mp_int *a, const mp_int *m, mp_int *c); -#endif /* end MP_NUMTH */ - -/* Input and output */ -#if MP_IOFUNC -void mp_print(mp_int *mp, FILE *ofp); -#endif /* end MP_IOFUNC */ - -/* Base conversion */ -mp_err mp_read_raw(mp_int *mp, char *str, int len); -int mp_raw_size(mp_int *mp); -mp_err mp_toraw(mp_int *mp, char *str); -mp_err mp_read_radix(mp_int *mp, const char *str, int radix); -mp_err mp_read_variable_radix(mp_int *a, const char * str, int default_radix); -int mp_radix_size(mp_int *mp, int radix); -mp_err mp_toradix(mp_int *mp, char *str, int radix); -int mp_tovalue(char ch, int r); - -#define mp_tobinary(M, S) mp_toradix((M), (S), 2) -#define mp_tooctal(M, S) mp_toradix((M), (S), 8) -#define mp_todecimal(M, S) mp_toradix((M), (S), 10) -#define mp_tohex(M, S) mp_toradix((M), (S), 16) - -/* Error strings */ -const char *mp_strerror(mp_err ec); - -/* Octet string conversion functions */ -mp_err mp_read_unsigned_octets(mp_int *mp, const unsigned char *str, mp_size len); -int mp_unsigned_octet_size(const mp_int *mp); -mp_err mp_to_unsigned_octets(const mp_int *mp, unsigned char *str, mp_size maxlen); -mp_err mp_to_signed_octets(const mp_int *mp, unsigned char *str, mp_size maxlen); -mp_err mp_to_fixlen_octets(const mp_int *mp, unsigned char *str, mp_size len); - -/* Miscellaneous */ -mp_size mp_trailing_zeros(const mp_int *mp); - -#define MP_CHECKOK(x) if (MP_OKAY > (res = (x))) goto CLEANUP -#define MP_CHECKERR(x) if (MP_OKAY > (res = (x))) goto CLEANUP - -#if defined(MP_API_COMPATIBLE) -#define NEG MP_NEG -#define ZPOS MP_ZPOS -#define DIGIT_MAX MP_DIGIT_MAX -#define DIGIT_BIT MP_DIGIT_BIT -#define DIGIT_FMT MP_DIGIT_FMT -#define RADIX MP_RADIX -#define MAX_RADIX MP_MAX_RADIX -#define FLAG(MP) MP_FLAG(MP) -#define SIGN(MP) MP_SIGN(MP) -#define USED(MP) MP_USED(MP) -#define ALLOC(MP) MP_ALLOC(MP) -#define DIGITS(MP) MP_DIGITS(MP) -#define DIGIT(MP,N) MP_DIGIT(MP,N) - -#if MP_ARGCHK == 1 -#define ARGCHK(X,Y) {if(!(X)){return (Y);}} -#elif MP_ARGCHK == 2 -#ifdef _KERNEL -#define ARGCHK(X,Y) ASSERT(X) -#else -#include -#define ARGCHK(X,Y) assert(X) -#endif -#else -#define ARGCHK(X,Y) /* */ -#endif -#endif /* defined MP_API_COMPATIBLE */ - -#endif /* _MPI_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.c b/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.c deleted file mode 100644 index ba4408633c32c..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - *********************************************************************** */ - -/* Bitwise logical operations on MPI values */ - -#include "mpi-priv.h" -#include "mplogic.h" - -/* {{{ Lookup table for population count */ - -static unsigned char bitc[] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 -}; - -/* }}} */ - -/* - mpl_rsh(a, b, d) - b = a >> d - mpl_lsh(a, b, d) - b = a << d - */ - -/* {{{ mpl_rsh(a, b, d) */ - -mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_copy(a, b)) != MP_OKAY) - return res; - - s_mp_div_2d(b, d); - - return MP_OKAY; - -} /* end mpl_rsh() */ - -/* }}} */ - -/* {{{ mpl_lsh(a, b, d) */ - -mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d) -{ - mp_err res; - - ARGCHK(a != NULL && b != NULL, MP_BADARG); - - if((res = mp_copy(a, b)) != MP_OKAY) - return res; - - return s_mp_mul_2d(b, d); - -} /* end mpl_lsh() */ - -/* }}} */ - -/*------------------------------------------------------------------------*/ -/* - mpl_set_bit - - Returns MP_OKAY or some error code. - Grows a if needed to set a bit to 1. - */ -mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value) -{ - mp_size ix; - mp_err rv; - mp_digit mask; - - ARGCHK(a != NULL, MP_BADARG); - - ix = bitNum / MP_DIGIT_BIT; - if (ix + 1 > MP_USED(a)) { - rv = s_mp_pad(a, ix + 1); - if (rv != MP_OKAY) - return rv; - } - - bitNum = bitNum % MP_DIGIT_BIT; - mask = (mp_digit)1 << bitNum; - if (value) - MP_DIGIT(a,ix) |= mask; - else - MP_DIGIT(a,ix) &= ~mask; - s_mp_clamp(a); - return MP_OKAY; -} - -/* - mpl_get_bit - - returns 0 or 1 or some (negative) error code. - */ -mp_err mpl_get_bit(const mp_int *a, mp_size bitNum) -{ - mp_size bit, ix; - mp_err rv; - - ARGCHK(a != NULL, MP_BADARG); - - ix = bitNum / MP_DIGIT_BIT; - ARGCHK(ix <= MP_USED(a) - 1, MP_RANGE); - - bit = bitNum % MP_DIGIT_BIT; - rv = (mp_err)(MP_DIGIT(a, ix) >> bit) & 1; - return rv; -} - -/* - mpl_get_bits - - Extracts numBits bits from a, where the least significant extracted bit - is bit lsbNum. Returns a negative value if error occurs. - - Because sign bit is used to indicate error, maximum number of bits to - be returned is the lesser of (a) the number of bits in an mp_digit, or - (b) one less than the number of bits in an mp_err. - - lsbNum + numbits can be greater than the number of significant bits in - integer a, as long as bit lsbNum is in the high order digit of a. - */ -mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits) -{ - mp_size rshift = (lsbNum % MP_DIGIT_BIT); - mp_size lsWndx = (lsbNum / MP_DIGIT_BIT); - mp_digit * digit = MP_DIGITS(a) + lsWndx; - mp_digit mask = ((1 << numBits) - 1); - - ARGCHK(numBits < CHAR_BIT * sizeof mask, MP_BADARG); - ARGCHK(MP_HOWMANY(lsbNum, MP_DIGIT_BIT) <= MP_USED(a), MP_RANGE); - - if ((numBits + lsbNum % MP_DIGIT_BIT <= MP_DIGIT_BIT) || - (lsWndx + 1 >= MP_USED(a))) { - mask &= (digit[0] >> rshift); - } else { - mask &= ((digit[0] >> rshift) | (digit[1] << (MP_DIGIT_BIT - rshift))); - } - return (mp_err)mask; -} - -/* - mpl_significant_bits - returns number of significnant bits in abs(a). - returns 1 if value is zero. - */ -mp_err mpl_significant_bits(const mp_int *a) -{ - mp_err bits = 0; - int ix; - - ARGCHK(a != NULL, MP_BADARG); - - ix = MP_USED(a); - for (ix = MP_USED(a); ix > 0; ) { - mp_digit d; - d = MP_DIGIT(a, --ix); - if (d) { - while (d) { - ++bits; - d >>= 1; - } - break; - } - } - bits += ix * MP_DIGIT_BIT; - if (!bits) - bits = 1; - return bits; -} - -/*------------------------------------------------------------------------*/ -/* HERE THERE BE DRAGONS */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.h deleted file mode 100644 index fda4f32d6498a..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mplogic.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - *********************************************************************** */ - -/* Bitwise logical operations on MPI values */ - -#ifndef _MPLOGIC_H -#define _MPLOGIC_H - -/* $Id: mplogic.h,v 1.7 2004/04/27 23:04:36 gerv%gerv.net Exp $ */ - -#include "mpi.h" - -/* - The logical operations treat an mp_int as if it were a bit vector, - without regard to its sign (an mp_int is represented in a signed - magnitude format). Values are treated as if they had an infinite - string of zeros left of the most-significant bit. - */ - -/* Parity results */ - -#define MP_EVEN MP_YES -#define MP_ODD MP_NO - -/* Bitwise functions */ - -mp_err mpl_not(mp_int *a, mp_int *b); /* one's complement */ -mp_err mpl_and(mp_int *a, mp_int *b, mp_int *c); /* bitwise AND */ -mp_err mpl_or(mp_int *a, mp_int *b, mp_int *c); /* bitwise OR */ -mp_err mpl_xor(mp_int *a, mp_int *b, mp_int *c); /* bitwise XOR */ - -/* Shift functions */ - -mp_err mpl_rsh(const mp_int *a, mp_int *b, mp_digit d); /* right shift */ -mp_err mpl_lsh(const mp_int *a, mp_int *b, mp_digit d); /* left shift */ - -/* Bit count and parity */ - -mp_err mpl_num_set(mp_int *a, int *num); /* count set bits */ -mp_err mpl_num_clear(mp_int *a, int *num); /* count clear bits */ -mp_err mpl_parity(mp_int *a); /* determine parity */ - -/* Get & Set the value of a bit */ - -mp_err mpl_set_bit(mp_int *a, mp_size bitNum, mp_size value); -mp_err mpl_get_bit(const mp_int *a, mp_size bitNum); -mp_err mpl_get_bits(const mp_int *a, mp_size lsbNum, mp_size numBits); -mp_err mpl_significant_bits(const mp_int *a); - -#endif /* _MPLOGIC_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpmontg.c b/src/jdk.crypto.ec/share/native/libsunec/impl/mpmontg.c deleted file mode 100644 index 4c848a39276d0..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpmontg.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Sheueling Chang Shantz , - * Stephen Fung , and - * Douglas Stebila of Sun Laboratories. - * - *********************************************************************** */ - -/* This file implements moduluar exponentiation using Montgomery's - * method for modular reduction. This file implements the method - * described as "Improvement 1" in the paper "A Cryptogrpahic Library for - * the Motorola DSP56000" by Stephen R. Dusse' and Burton S. Kaliski Jr. - * published in "Advances in Cryptology: Proceedings of EUROCRYPT '90" - * "Lecture Notes in Computer Science" volume 473, 1991, pg 230-244, - * published by Springer Verlag. - */ - -#define MP_USING_CACHE_SAFE_MOD_EXP 1 -#ifndef _KERNEL -#include -#include /* ptrdiff_t */ -#endif -#include "mpi-priv.h" -#include "mplogic.h" -#include "mpprime.h" -#ifdef MP_USING_MONT_MULF -#include "montmulf.h" -#endif - -/* if MP_CHAR_STORE_SLOW is defined, we */ -/* need to know endianness of this platform. */ -#ifdef MP_CHAR_STORE_SLOW -#if !defined(MP_IS_BIG_ENDIAN) && !defined(MP_IS_LITTLE_ENDIAN) -#error "You must define MP_IS_BIG_ENDIAN or MP_IS_LITTLE_ENDIAN\n" \ - " if you define MP_CHAR_STORE_SLOW." -#endif -#endif - -#ifndef STATIC -#define STATIC -#endif - -#define MAX_ODD_INTS 32 /* 2 ** (WINDOW_BITS - 1) */ - -#ifndef _KERNEL -#if defined(_WIN32_WCE) -#define ABORT res = MP_UNDEF; goto CLEANUP -#else -#define ABORT abort() -#endif -#else -#define ABORT res = MP_UNDEF; goto CLEANUP -#endif /* _KERNEL */ - -/* computes T = REDC(T), 2^b == R */ -mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm) -{ - mp_err res; - mp_size i; - - i = MP_USED(T) + MP_USED(&mmm->N) + 2; - MP_CHECKOK( s_mp_pad(T, i) ); - for (i = 0; i < MP_USED(&mmm->N); ++i ) { - mp_digit m_i = MP_DIGIT(T, i) * mmm->n0prime; - /* T += N * m_i * (MP_RADIX ** i); */ - MP_CHECKOK( s_mp_mul_d_add_offset(&mmm->N, m_i, T, i) ); - } - s_mp_clamp(T); - - /* T /= R */ - s_mp_div_2d(T, mmm->b); - - if ((res = s_mp_cmp(T, &mmm->N)) >= 0) { - /* T = T - N */ - MP_CHECKOK( s_mp_sub(T, &mmm->N) ); -#ifdef DEBUG - if ((res = mp_cmp(T, &mmm->N)) >= 0) { - res = MP_UNDEF; - goto CLEANUP; - } -#endif - } - res = MP_OKAY; -CLEANUP: - return res; -} - -#if !defined(MP_ASSEMBLY_MUL_MONT) && !defined(MP_MONT_USE_MP_MUL) -mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c, - mp_mont_modulus *mmm) -{ - mp_digit *pb; - mp_digit m_i; - mp_err res; - mp_size ib; - mp_size useda, usedb; - - ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG); - - if (MP_USED(a) < MP_USED(b)) { - const mp_int *xch = b; /* switch a and b, to do fewer outer loops */ - b = a; - a = xch; - } - - MP_USED(c) = 1; MP_DIGIT(c, 0) = 0; - ib = MP_USED(a) + MP_MAX(MP_USED(b), MP_USED(&mmm->N)) + 2; - if((res = s_mp_pad(c, ib)) != MP_OKAY) - goto CLEANUP; - - useda = MP_USED(a); - pb = MP_DIGITS(b); - s_mpv_mul_d(MP_DIGITS(a), useda, *pb++, MP_DIGITS(c)); - s_mp_setz(MP_DIGITS(c) + useda + 1, ib - (useda + 1)); - m_i = MP_DIGIT(c, 0) * mmm->n0prime; - s_mp_mul_d_add_offset(&mmm->N, m_i, c, 0); - - /* Outer loop: Digits of b */ - usedb = MP_USED(b); - for (ib = 1; ib < usedb; ib++) { - mp_digit b_i = *pb++; - - /* Inner product: Digits of a */ - if (b_i) - s_mpv_mul_d_add_prop(MP_DIGITS(a), useda, b_i, MP_DIGITS(c) + ib); - m_i = MP_DIGIT(c, ib) * mmm->n0prime; - s_mp_mul_d_add_offset(&mmm->N, m_i, c, ib); - } - if (usedb < MP_USED(&mmm->N)) { - for (usedb = MP_USED(&mmm->N); ib < usedb; ++ib ) { - m_i = MP_DIGIT(c, ib) * mmm->n0prime; - s_mp_mul_d_add_offset(&mmm->N, m_i, c, ib); - } - } - s_mp_clamp(c); - s_mp_div_2d(c, mmm->b); - if (s_mp_cmp(c, &mmm->N) >= 0) { - MP_CHECKOK( s_mp_sub(c, &mmm->N) ); - } - res = MP_OKAY; - -CLEANUP: - return res; -} -#endif diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/mpprime.h b/src/jdk.crypto.ec/share/native/libsunec/impl/mpprime.h deleted file mode 100644 index d4cea9486180c..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/mpprime.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the MPI Arbitrary Precision Integer Arithmetic library. - * - * The Initial Developer of the Original Code is - * Michael J. Fromberger. - * Portions created by the Initial Developer are Copyright (C) 1997 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - *********************************************************************** */ - -/* Utilities for finding and working with prime and pseudo-prime integers */ - -#ifndef _MP_PRIME_H -#define _MP_PRIME_H - -#include "mpi.h" - -extern const int prime_tab_size; /* number of primes available */ -extern const mp_digit prime_tab[]; - -/* Tests for divisibility */ -mp_err mpp_divis(mp_int *a, mp_int *b); -mp_err mpp_divis_d(mp_int *a, mp_digit d); - -/* Random selection */ -mp_err mpp_random(mp_int *a); -mp_err mpp_random_size(mp_int *a, mp_size prec); - -/* Pseudo-primality testing */ -mp_err mpp_divis_vector(mp_int *a, const mp_digit *vec, int size, int *which); -mp_err mpp_divis_primes(mp_int *a, mp_digit *np); -mp_err mpp_fermat(mp_int *a, mp_digit w); -mp_err mpp_fermat_list(mp_int *a, const mp_digit *primes, mp_size nPrimes); -mp_err mpp_pprime(mp_int *a, int nt); -mp_err mpp_sieve(mp_int *trial, const mp_digit *primes, mp_size nPrimes, - unsigned char *sieve, mp_size nSieve); -mp_err mpp_make_prime(mp_int *start, mp_size nBits, mp_size strong, - unsigned long * nTries); - -#endif /* _MP_PRIME_H */ diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/oid.c b/src/jdk.crypto.ec/share/native/libsunec/impl/oid.c deleted file mode 100644 index 3d899dcf1f783..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/oid.c +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1994-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta , Sun Microsystems Laboratories - * - * Last Modified Date from the Original Code: March 2012 - *********************************************************************** */ - -#include - -#ifndef _WIN32 -#if !defined(__linux__) && !defined(_ALLBSD_SOURCE) -#include -#endif /* __linux__ || _ALLBSD_SOURCE */ -#include -#endif /* _WIN32 */ - -#ifdef _KERNEL -#include -#else -#include -#endif -#include "ec.h" -#include "ecl-curve.h" -#include "ecc_impl.h" -#include "secoidt.h" - -#define CERTICOM_OID 0x2b, 0x81, 0x04 -#define SECG_OID CERTICOM_OID, 0x00 - -#define ANSI_X962_OID 0x2a, 0x86, 0x48, 0xce, 0x3d -#define ANSI_X962_CURVE_OID ANSI_X962_OID, 0x03 -#define ANSI_X962_GF2m_OID ANSI_X962_CURVE_OID, 0x00 -#define ANSI_X962_GFp_OID ANSI_X962_CURVE_OID, 0x01 - -#define TELETRUST_ALGO_OID 0x2b, 0x24, 0x03 -#define ECC_BRAINPOOL TELETRUST_ALGO_OID, 0x03, 0x02, 0x08 -#define ECC_BRAINPOOL_EC_V1 ECC_BRAINPOOL, 0x01, 0x01 - -#define CONST_OID static const unsigned char - -/* ANSI X9.62 prime curve OIDs */ -/* NOTE: prime192v1 is the same as secp192r1, prime256v1 is the - * same as secp256r1 - */ -CONST_OID ansiX962prime192v1[] = { ANSI_X962_GFp_OID, 0x01 }; -CONST_OID ansiX962prime192v2[] = { ANSI_X962_GFp_OID, 0x02 }; -CONST_OID ansiX962prime192v3[] = { ANSI_X962_GFp_OID, 0x03 }; -CONST_OID ansiX962prime239v1[] = { ANSI_X962_GFp_OID, 0x04 }; -CONST_OID ansiX962prime239v2[] = { ANSI_X962_GFp_OID, 0x05 }; -CONST_OID ansiX962prime239v3[] = { ANSI_X962_GFp_OID, 0x06 }; -CONST_OID ansiX962prime256v1[] = { ANSI_X962_GFp_OID, 0x07 }; - -/* SECG prime curve OIDs */ -CONST_OID secgECsecp112r1[] = { SECG_OID, 0x06 }; -CONST_OID secgECsecp112r2[] = { SECG_OID, 0x07 }; -CONST_OID secgECsecp128r1[] = { SECG_OID, 0x1c }; -CONST_OID secgECsecp128r2[] = { SECG_OID, 0x1d }; -CONST_OID secgECsecp160k1[] = { SECG_OID, 0x09 }; -CONST_OID secgECsecp160r1[] = { SECG_OID, 0x08 }; -CONST_OID secgECsecp160r2[] = { SECG_OID, 0x1e }; -CONST_OID secgECsecp192k1[] = { SECG_OID, 0x1f }; -CONST_OID secgECsecp224k1[] = { SECG_OID, 0x20 }; -CONST_OID secgECsecp224r1[] = { SECG_OID, 0x21 }; -CONST_OID secgECsecp256k1[] = { SECG_OID, 0x0a }; -CONST_OID secgECsecp384r1[] = { SECG_OID, 0x22 }; -CONST_OID secgECsecp521r1[] = { SECG_OID, 0x23 }; - -/* SECG characterisitic two curve OIDs */ -CONST_OID secgECsect113r1[] = {SECG_OID, 0x04 }; -CONST_OID secgECsect113r2[] = {SECG_OID, 0x05 }; -CONST_OID secgECsect131r1[] = {SECG_OID, 0x16 }; -CONST_OID secgECsect131r2[] = {SECG_OID, 0x17 }; -CONST_OID secgECsect163k1[] = {SECG_OID, 0x01 }; -CONST_OID secgECsect163r1[] = {SECG_OID, 0x02 }; -CONST_OID secgECsect163r2[] = {SECG_OID, 0x0f }; -CONST_OID secgECsect193r1[] = {SECG_OID, 0x18 }; -CONST_OID secgECsect193r2[] = {SECG_OID, 0x19 }; -CONST_OID secgECsect233k1[] = {SECG_OID, 0x1a }; -CONST_OID secgECsect233r1[] = {SECG_OID, 0x1b }; -CONST_OID secgECsect239k1[] = {SECG_OID, 0x03 }; -CONST_OID secgECsect283k1[] = {SECG_OID, 0x10 }; -CONST_OID secgECsect283r1[] = {SECG_OID, 0x11 }; -CONST_OID secgECsect409k1[] = {SECG_OID, 0x24 }; -CONST_OID secgECsect409r1[] = {SECG_OID, 0x25 }; -CONST_OID secgECsect571k1[] = {SECG_OID, 0x26 }; -CONST_OID secgECsect571r1[] = {SECG_OID, 0x27 }; - -/* ANSI X9.62 characteristic two curve OIDs */ -CONST_OID ansiX962c2pnb163v1[] = { ANSI_X962_GF2m_OID, 0x01 }; -CONST_OID ansiX962c2pnb163v2[] = { ANSI_X962_GF2m_OID, 0x02 }; -CONST_OID ansiX962c2pnb163v3[] = { ANSI_X962_GF2m_OID, 0x03 }; -CONST_OID ansiX962c2pnb176v1[] = { ANSI_X962_GF2m_OID, 0x04 }; -CONST_OID ansiX962c2tnb191v1[] = { ANSI_X962_GF2m_OID, 0x05 }; -CONST_OID ansiX962c2tnb191v2[] = { ANSI_X962_GF2m_OID, 0x06 }; -CONST_OID ansiX962c2tnb191v3[] = { ANSI_X962_GF2m_OID, 0x07 }; -CONST_OID ansiX962c2onb191v4[] = { ANSI_X962_GF2m_OID, 0x08 }; -CONST_OID ansiX962c2onb191v5[] = { ANSI_X962_GF2m_OID, 0x09 }; -CONST_OID ansiX962c2pnb208w1[] = { ANSI_X962_GF2m_OID, 0x0a }; -CONST_OID ansiX962c2tnb239v1[] = { ANSI_X962_GF2m_OID, 0x0b }; -CONST_OID ansiX962c2tnb239v2[] = { ANSI_X962_GF2m_OID, 0x0c }; -CONST_OID ansiX962c2tnb239v3[] = { ANSI_X962_GF2m_OID, 0x0d }; -CONST_OID ansiX962c2onb239v4[] = { ANSI_X962_GF2m_OID, 0x0e }; -CONST_OID ansiX962c2onb239v5[] = { ANSI_X962_GF2m_OID, 0x0f }; -CONST_OID ansiX962c2pnb272w1[] = { ANSI_X962_GF2m_OID, 0x10 }; -CONST_OID ansiX962c2pnb304w1[] = { ANSI_X962_GF2m_OID, 0x11 }; -CONST_OID ansiX962c2tnb359v1[] = { ANSI_X962_GF2m_OID, 0x12 }; -CONST_OID ansiX962c2pnb368w1[] = { ANSI_X962_GF2m_OID, 0x13 }; -CONST_OID ansiX962c2tnb431r1[] = { ANSI_X962_GF2m_OID, 0x14 }; - -/* TeleTrusT ECC Brainpool prime curve OIDs */ -CONST_OID brainpoolP160r1[] = { ECC_BRAINPOOL_EC_V1, 0x01 }; -CONST_OID brainpoolP160t1[] = { ECC_BRAINPOOL_EC_V1, 0x02 }; -CONST_OID brainpoolP192r1[] = { ECC_BRAINPOOL_EC_V1, 0x03 }; -CONST_OID brainpoolP192t1[] = { ECC_BRAINPOOL_EC_V1, 0x04 }; -CONST_OID brainpoolP224r1[] = { ECC_BRAINPOOL_EC_V1, 0x05 }; -CONST_OID brainpoolP224t1[] = { ECC_BRAINPOOL_EC_V1, 0x06 }; -CONST_OID brainpoolP256r1[] = { ECC_BRAINPOOL_EC_V1, 0x07 }; -CONST_OID brainpoolP256t1[] = { ECC_BRAINPOOL_EC_V1, 0x08 }; -CONST_OID brainpoolP320r1[] = { ECC_BRAINPOOL_EC_V1, 0x09 }; -CONST_OID brainpoolP320t1[] = { ECC_BRAINPOOL_EC_V1, 0x0a }; -CONST_OID brainpoolP384r1[] = { ECC_BRAINPOOL_EC_V1, 0x0b }; -CONST_OID brainpoolP384t1[] = { ECC_BRAINPOOL_EC_V1, 0x0c }; -CONST_OID brainpoolP512r1[] = { ECC_BRAINPOOL_EC_V1, 0x0d }; -CONST_OID brainpoolP512t1[] = { ECC_BRAINPOOL_EC_V1, 0x0e }; - -#define OI(x) { siDEROID, (unsigned char *)x, sizeof x } -#ifndef SECOID_NO_STRINGS -#define OD(oid,tag,desc,mech,ext) { OI(oid), tag, desc, mech, ext } -#else -#define OD(oid,tag,desc,mech,ext) { OI(oid), tag, 0, mech, ext } -#endif - -#define CKM_INVALID_MECHANISM 0xffffffffUL - -/* XXX this is incorrect */ -#define INVALID_CERT_EXTENSION 1 - -#define CKM_ECDSA 0x00001041 -#define CKM_ECDSA_SHA1 0x00001042 -#define CKM_ECDH1_DERIVE 0x00001050 - -static SECOidData ANSI_prime_oids[] = { - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - - OD( ansiX962prime192v1, ECCurve_NIST_P192, - "ANSI X9.62 elliptic curve prime192v1 (aka secp192r1, NIST P-192)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime192v2, ECCurve_X9_62_PRIME_192V2, - "ANSI X9.62 elliptic curve prime192v2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime192v3, ECCurve_X9_62_PRIME_192V3, - "ANSI X9.62 elliptic curve prime192v3", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime239v1, ECCurve_X9_62_PRIME_239V1, - "ANSI X9.62 elliptic curve prime239v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime239v2, ECCurve_X9_62_PRIME_239V2, - "ANSI X9.62 elliptic curve prime239v2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime239v3, ECCurve_X9_62_PRIME_239V3, - "ANSI X9.62 elliptic curve prime239v3", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962prime256v1, ECCurve_NIST_P256, - "ANSI X9.62 elliptic curve prime256v1 (aka secp256r1, NIST P-256)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ) -}; - -static SECOidData SECG_oids[] = { - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - - OD( secgECsect163k1, ECCurve_NIST_K163, - "SECG elliptic curve sect163k1 (aka NIST K-163)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect163r1, ECCurve_SECG_CHAR2_163R1, - "SECG elliptic curve sect163r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect239k1, ECCurve_SECG_CHAR2_239K1, - "SECG elliptic curve sect239k1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect113r1, ECCurve_SECG_CHAR2_113R1, - "SECG elliptic curve sect113r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect113r2, ECCurve_SECG_CHAR2_113R2, - "SECG elliptic curve sect113r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp112r1, ECCurve_SECG_PRIME_112R1, - "SECG elliptic curve secp112r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp112r2, ECCurve_SECG_PRIME_112R2, - "SECG elliptic curve secp112r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp160r1, ECCurve_SECG_PRIME_160R1, - "SECG elliptic curve secp160r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp160k1, ECCurve_SECG_PRIME_160K1, - "SECG elliptic curve secp160k1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp256k1, ECCurve_SECG_PRIME_256K1, - "SECG elliptic curve secp256k1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( secgECsect163r2, ECCurve_NIST_B163, - "SECG elliptic curve sect163r2 (aka NIST B-163)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect283k1, ECCurve_NIST_K283, - "SECG elliptic curve sect283k1 (aka NIST K-283)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect283r1, ECCurve_NIST_B283, - "SECG elliptic curve sect283r1 (aka NIST B-283)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( secgECsect131r1, ECCurve_SECG_CHAR2_131R1, - "SECG elliptic curve sect131r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect131r2, ECCurve_SECG_CHAR2_131R2, - "SECG elliptic curve sect131r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect193r1, ECCurve_SECG_CHAR2_193R1, - "SECG elliptic curve sect193r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect193r2, ECCurve_SECG_CHAR2_193R2, - "SECG elliptic curve sect193r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect233k1, ECCurve_NIST_K233, - "SECG elliptic curve sect233k1 (aka NIST K-233)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect233r1, ECCurve_NIST_B233, - "SECG elliptic curve sect233r1 (aka NIST B-233)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp128r1, ECCurve_SECG_PRIME_128R1, - "SECG elliptic curve secp128r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp128r2, ECCurve_SECG_PRIME_128R2, - "SECG elliptic curve secp128r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp160r2, ECCurve_SECG_PRIME_160R2, - "SECG elliptic curve secp160r2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp192k1, ECCurve_SECG_PRIME_192K1, - "SECG elliptic curve secp192k1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp224k1, ECCurve_SECG_PRIME_224K1, - "SECG elliptic curve secp224k1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp224r1, ECCurve_NIST_P224, - "SECG elliptic curve secp224r1 (aka NIST P-224)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp384r1, ECCurve_NIST_P384, - "SECG elliptic curve secp384r1 (aka NIST P-384)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsecp521r1, ECCurve_NIST_P521, - "SECG elliptic curve secp521r1 (aka NIST P-521)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect409k1, ECCurve_NIST_K409, - "SECG elliptic curve sect409k1 (aka NIST K-409)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect409r1, ECCurve_NIST_B409, - "SECG elliptic curve sect409r1 (aka NIST B-409)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect571k1, ECCurve_NIST_K571, - "SECG elliptic curve sect571k1 (aka NIST K-571)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( secgECsect571r1, ECCurve_NIST_B571, - "SECG elliptic curve sect571r1 (aka NIST B-571)", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ) -}; - -static SECOidData ANSI_oids[] = { - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - - /* ANSI X9.62 named elliptic curves (characteristic two field) */ - OD( ansiX962c2pnb163v1, ECCurve_X9_62_CHAR2_PNB163V1, - "ANSI X9.62 elliptic curve c2pnb163v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2pnb163v2, ECCurve_X9_62_CHAR2_PNB163V2, - "ANSI X9.62 elliptic curve c2pnb163v2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2pnb163v3, ECCurve_X9_62_CHAR2_PNB163V3, - "ANSI X9.62 elliptic curve c2pnb163v3", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2pnb176v1, ECCurve_X9_62_CHAR2_PNB176V1, - "ANSI X9.62 elliptic curve c2pnb176v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb191v1, ECCurve_X9_62_CHAR2_TNB191V1, - "ANSI X9.62 elliptic curve c2tnb191v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb191v2, ECCurve_X9_62_CHAR2_TNB191V2, - "ANSI X9.62 elliptic curve c2tnb191v2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb191v3, ECCurve_X9_62_CHAR2_TNB191V3, - "ANSI X9.62 elliptic curve c2tnb191v3", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( ansiX962c2pnb208w1, ECCurve_X9_62_CHAR2_PNB208W1, - "ANSI X9.62 elliptic curve c2pnb208w1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb239v1, ECCurve_X9_62_CHAR2_TNB239V1, - "ANSI X9.62 elliptic curve c2tnb239v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb239v2, ECCurve_X9_62_CHAR2_TNB239V2, - "ANSI X9.62 elliptic curve c2tnb239v2", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb239v3, ECCurve_X9_62_CHAR2_TNB239V3, - "ANSI X9.62 elliptic curve c2tnb239v3", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( ansiX962c2pnb272w1, ECCurve_X9_62_CHAR2_PNB272W1, - "ANSI X9.62 elliptic curve c2pnb272w1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2pnb304w1, ECCurve_X9_62_CHAR2_PNB304W1, - "ANSI X9.62 elliptic curve c2pnb304w1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb359v1, ECCurve_X9_62_CHAR2_TNB359V1, - "ANSI X9.62 elliptic curve c2tnb359v1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2pnb368w1, ECCurve_X9_62_CHAR2_PNB368W1, - "ANSI X9.62 elliptic curve c2pnb368w1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - OD( ansiX962c2tnb431r1, ECCurve_X9_62_CHAR2_TNB431R1, - "ANSI X9.62 elliptic curve c2tnb431r1", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ) -}; - -static SECOidData BRAINPOOL_oids[] = { - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - - /* RFC 5639 Brainpool named elliptic curves */ - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( brainpoolP256r1, ECCurve_BrainpoolP256r1, - "brainpoolP256r1 domain parameter set", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( brainpoolP320r1, ECCurve_BrainpoolP320r1, - "brainpoolP320r1 domain parameter set", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( brainpoolP384r1, ECCurve_BrainpoolP384r1, - "brainpoolP384r1 domain parameter set", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION }, - OD( brainpoolP512r1, ECCurve_BrainpoolP512r1, - "brainpoolP512r1 domain parameter set", - CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION ), - { { siDEROID, NULL, 0 }, ECCurve_noName, - "Unknown OID", CKM_INVALID_MECHANISM, - INVALID_CERT_EXTENSION } -}; - -int -oideql(unsigned char *reqoid, unsigned char *foundoid, size_t reqlen, size_t foundlen) -{ - if (!reqoid || !foundoid) { - return 0; - } - - if (reqlen != foundlen) { - return 0; - } - - return memcmp(reqoid, foundoid, reqlen) == 0; -} - -SECOidData * -SECOID_FindOID(const SECItem *oid) -{ - SECOidData *po; - SECOidData *ret = NULL; - int reqlen = oid->len; - - if (reqlen == 8) { - if (oid->data[6] == 0x00) { - /* XXX bounds check */ - po = &ANSI_oids[oid->data[7]]; - if (oideql(oid->data, po->oid.data, reqlen, po->oid.len)) { - ret = po; - } - } - if (oid->data[6] == 0x01) { - /* XXX bounds check */ - po = &ANSI_prime_oids[oid->data[7]]; - if (oideql(oid->data, po->oid.data, reqlen, po->oid.len)) { - ret = po; - } - } - } else if (reqlen == 5) { - /* XXX bounds check */ - po = &SECG_oids[oid->data[4]]; - if (oideql(oid->data, po->oid.data, reqlen, po->oid.len)) { - ret = po; - } - } else if (reqlen == 9) { - /* XXX bounds check */ - po = &BRAINPOOL_oids[oid->data[8]]; - if (oideql(oid->data, po->oid.data, reqlen, po->oid.len)) { - ret = po; - } - } - return(ret); -} - -ECCurveName -SECOID_FindOIDTag(const SECItem *oid) -{ - SECOidData *oiddata; - - oiddata = SECOID_FindOID (oid); - if (oiddata == NULL) - return ECCurve_noName; - - return oiddata->offset; -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/secitem.c b/src/jdk.crypto.ec/share/native/libsunec/impl/secitem.c deleted file mode 100644 index fab4415f26b07..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/secitem.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1994-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Last Modified Date from the Original Code: March 2012 - *********************************************************************** */ - -/* - * Support routines for SECItem data structure. - * - * $Id: secitem.c,v 1.14 2006/05/22 22:24:34 wtchang%redhat.com Exp $ - */ - -#include - -#ifndef _WIN32 -#if !defined(__linux__) && !defined(_ALLBSD_SOURCE) -#include -#endif /* __linux__ || _ALLBSD_SOURCE */ -#include -#endif /* _WIN32 */ - -#ifdef _KERNEL -#include -#else -#include - -#ifndef _WIN32 -#include -#endif /* _WIN32 */ - -#include -#endif -#include "ec.h" -#include "ecl-curve.h" -#include "ecc_impl.h" - -void SECITEM_FreeItem(SECItem *, PRBool); - -SECItem * -SECITEM_AllocItem(PRArenaPool *arena, SECItem *item, unsigned int len, - int kmflag) -{ - SECItem *result = NULL; - void *mark = NULL; - - if (arena != NULL) { - mark = PORT_ArenaMark(arena); - } - - if (item == NULL) { - if (arena != NULL) { - result = PORT_ArenaZAlloc(arena, sizeof(SECItem), kmflag); - } else { - result = PORT_ZAlloc(sizeof(SECItem), kmflag); - } - if (result == NULL) { - goto loser; - } - } else { - PORT_Assert(item->data == NULL); - result = item; - } - - result->len = len; - if (len) { - if (arena != NULL) { - result->data = PORT_ArenaAlloc(arena, len, kmflag); - } else { - result->data = PORT_Alloc(len, kmflag); - } - if (result->data == NULL) { - goto loser; - } - } else { - result->data = NULL; - } - - if (mark) { - PORT_ArenaUnmark(arena, mark); - } - return(result); - -loser: - if ( arena != NULL ) { - if (mark) { - PORT_ArenaRelease(arena, mark); - } - if (item != NULL) { - item->data = NULL; - item->len = 0; - } - } else { - if (result != NULL) { - SECITEM_FreeItem(result, (item == NULL) ? PR_TRUE : PR_FALSE); - } - /* - * If item is not NULL, the above has set item->data and - * item->len to 0. - */ - } - return(NULL); -} - -SECStatus -SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, const SECItem *from, - int kmflag) -{ - to->type = from->type; - if (from->data && from->len) { - if ( arena ) { - to->data = (unsigned char*) PORT_ArenaAlloc(arena, from->len, - kmflag); - } else { - to->data = (unsigned char*) PORT_Alloc(from->len, kmflag); - } - - if (!to->data) { - return SECFailure; - } - PORT_Memcpy(to->data, from->data, from->len); - to->len = from->len; - } else { - to->data = 0; - to->len = 0; - } - return SECSuccess; -} - -void -SECITEM_FreeItem(SECItem *zap, PRBool freeit) -{ - if (zap) { -#ifdef _KERNEL - kmem_free(zap->data, zap->len); -#else - free(zap->data); -#endif - zap->data = 0; - zap->len = 0; - if (freeit) { -#ifdef _KERNEL - kmem_free(zap, sizeof (SECItem)); -#else - free(zap); -#endif - } - } -} diff --git a/src/jdk.crypto.ec/share/native/libsunec/impl/secoidt.h b/src/jdk.crypto.ec/share/native/libsunec/impl/secoidt.h deleted file mode 100644 index 58dde3bbe3c61..0000000000000 --- a/src/jdk.crypto.ec/share/native/libsunec/impl/secoidt.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, 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. - */ - -/* ********************************************************************* - * - * The Original Code is the Netscape security libraries. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1994-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dr Vipul Gupta , Sun Microsystems Laboratories - * - *********************************************************************** */ - -#ifndef _SECOIDT_H_ -#define _SECOIDT_H_ - -/* - * secoidt.h - public data structures for ASN.1 OID functions - * - * $Id: secoidt.h,v 1.23 2007/05/05 22:45:16 nelson%bolyard.com Exp $ - */ - -typedef struct SECOidDataStr SECOidData; -typedef struct SECAlgorithmIDStr SECAlgorithmID; - -/* -** An X.500 algorithm identifier -*/ -struct SECAlgorithmIDStr { - SECItem algorithm; - SECItem parameters; -}; - -#define SEC_OID_SECG_EC_SECP192R1 SEC_OID_ANSIX962_EC_PRIME192V1 -#define SEC_OID_SECG_EC_SECP256R1 SEC_OID_ANSIX962_EC_PRIME256V1 -#define SEC_OID_PKCS12_KEY_USAGE SEC_OID_X509_KEY_USAGE - -/* fake OID for DSS sign/verify */ -#define SEC_OID_SHA SEC_OID_MISS_DSS - -typedef enum { - INVALID_CERT_EXTENSION = 0, - UNSUPPORTED_CERT_EXTENSION = 1, - SUPPORTED_CERT_EXTENSION = 2 -} SECSupportExtenTag; - -struct SECOidDataStr { - SECItem oid; - ECCurveName offset; - const char * desc; - unsigned long mechanism; - SECSupportExtenTag supportedExtension; - /* only used for x.509 v3 extensions, so - that we can print the names of those - extensions that we don't even support */ -}; - -#endif /* _SECOIDT_H_ */ diff --git a/test/jdk/java/security/KeyAgreement/KeyAgreementTest.java b/test/jdk/java/security/KeyAgreement/KeyAgreementTest.java index 713eecae4d4cf..1e16c157fed2e 100644 --- a/test/jdk/java/security/KeyAgreement/KeyAgreementTest.java +++ b/test/jdk/java/security/KeyAgreement/KeyAgreementTest.java @@ -31,8 +31,6 @@ * this test file was covered before with JDK-4936763. * @run main/othervm -Djdk.crypto.KeyAgreement.legacyKDF=true KeyAgreementTest * DiffieHellman DH SunJCE - * @run main/othervm -Djdk.sunec.disableNative=false KeyAgreementTest - * ECDHNative EC SunEC * @run main KeyAgreementTest ECDH EC SunEC * @run main KeyAgreementTest XDH XDH SunEC */ @@ -56,10 +54,6 @@ public static void main(String[] args) throws Exception { String provider = args[2]; System.out.println("Testing " + kaAlgo); AlgoSpec aSpec = AlgoSpec.valueOf(AlgoSpec.class, kaAlgo); - // Switch kaAlgo to ECDH as it is used for algorithm names - if (kaAlgo.equals("ECDHNative")) { - kaAlgo = "ECDH"; - } List specs = aSpec.getAlgorithmParameterSpecs(); for (AlgorithmParameterSpec spec : specs) { testKeyAgreement(provider, kaAlgo, kpgAlgo, spec); @@ -74,26 +68,7 @@ private enum AlgoSpec { // EC curve supported for KeyGeneration can found between intersection // of curves define in // "java.base/share/classes/sun/security/util/CurveDB.java" - // and - // "jdk.crypto.ec/share/native/libsunec/impl/ecdecode.c" - ECDHNative( - // SEC2 prime curves - "secp112r1", "secp112r2", "secp128r1", "secp128r2", "secp160k1", - "secp160r1", "secp192k1", "secp192r1", "secp224k1", "secp224r1", - "secp256k1", "secp256r1", "secp384r1", "secp521r1", "SECP521R1", - // ANSI X9.62 prime curves - "X9.62 prime192v2", "X9.62 prime192v3", "X9.62 prime239v1", - "X9.62 prime239v2", "X9.62 prime239v3", - // SEC2 binary curves - "sect113r1", "sect113r2", "sect131r1", "sect131r2", "sect163k1", - "sect163r1", "sect163r2", "sect193r1", "sect193r2", "sect233k1", - "sect233r1", "sect239k1", "sect283k1", "sect283r1", "sect409k1", - "sect409r1", "sect571k1", "sect571r1", - // ANSI X9.62 binary curves - "X9.62 c2tnb191v1", "X9.62 c2tnb191v2", "X9.62 c2tnb191v3", - "X9.62 c2tnb239v1", "X9.62 c2tnb239v2", "X9.62 c2tnb239v3", - "X9.62 c2tnb359v1", "X9.62 c2tnb431r1" - ), + ECDH("secp256r1", "secp384r1", "secp521r1"), XDH("X25519", "X448", "x25519"), // There is no curve for DiffieHellman @@ -105,7 +80,6 @@ private AlgoSpec(String... curves) { // Generate AlgorithmParameterSpec for each KeyExchangeAlgorithm for (String crv : curves) { switch (this.name()) { - case "ECDHNative": case "ECDH": specs.add(new ECGenParameterSpec(crv)); break; @@ -128,7 +102,7 @@ public List getAlgorithmParameterSpecs() { } /** - * Perform KeyAgreement operation using native as well as JCE provider. + * Perform KeyAgreement operation */ private static void testKeyAgreement(String provider, String kaAlgo, String kpgAlgo, AlgorithmParameterSpec spec) throws Exception { diff --git a/test/jdk/java/security/KeyAgreement/KeySizeTest.java b/test/jdk/java/security/KeyAgreement/KeySizeTest.java index 23d0fc95f3cf3..492f64abd8b1a 100644 --- a/test/jdk/java/security/KeyAgreement/KeySizeTest.java +++ b/test/jdk/java/security/KeyAgreement/KeySizeTest.java @@ -37,9 +37,9 @@ * @run main KeySizeTest DiffieHellman SunJCE DiffieHellman 4096 * @run main KeySizeTest DiffieHellman SunJCE DiffieHellman 6144 * @run main KeySizeTest DiffieHellman SunJCE DiffieHellman 8192 - * @run main/othervm -Djdk.sunec.disableNative=false KeySizeTest ECDH SunEC EC 128 - * @run main/othervm -Djdk.sunec.disableNative=false KeySizeTest ECDH SunEC EC 192 * @run main/othervm KeySizeTest ECDH SunEC EC 256 + * @run main/othervm KeySizeTest ECDH SunEC EC 384 + * @run main/othervm KeySizeTest ECDH SunEC EC 521 * @run main KeySizeTest XDH SunEC XDH 255 * @run main KeySizeTest XDH SunEC XDH 448 */ diff --git a/test/jdk/javax/net/ssl/templates/SSLSocketTemplate.java b/test/jdk/javax/net/ssl/templates/SSLSocketTemplate.java index e27bf9bdaae12..c1ec829b8237d 100644 --- a/test/jdk/javax/net/ssl/templates/SSLSocketTemplate.java +++ b/test/jdk/javax/net/ssl/templates/SSLSocketTemplate.java @@ -372,14 +372,12 @@ protected void doClientSide() throws Exception { // Trusted certificates. protected final static Cert[] TRUSTED_CERTS = { Cert.CA_ECDSA_SECP256R1, - Cert.CA_ECDSA_SECT283R1, Cert.CA_RSA_2048, Cert.CA_DSA_2048 }; // End entity certificate. protected final static Cert[] END_ENTITY_CERTS = { Cert.EE_ECDSA_SECP256R1, - Cert.EE_ECDSA_SECT283R1, Cert.EE_RSA_2048, Cert.EE_EC_RSA_SECP256R1, Cert.EE_DSA_2048 }; @@ -705,32 +703,6 @@ public static enum Cert { "p1YdWENftmDoNTJ3O6TNlXb90jKWgAirCXNBUompPtHKkO592eDyGcT1h8qjrKlm\n" + "Kw=="), - CA_ECDSA_SECT283R1( - "EC", - // SHA1withECDSA, curve sect283r1 - // Validity - // Not Before: May 26 06:06:52 2020 GMT - // Not After : May 21 06:06:52 2040 GMT - // Subject Key Identifier: - // CF:A3:99:ED:4C:6E:04:41:09:21:31:33:B6:80:D5:A7:BF:2B:98:04 - "-----BEGIN CERTIFICATE-----\n" + - "MIIB8TCCAY+gAwIBAgIJANQFsBngZ3iMMAsGByqGSM49BAEFADBdMQswCQYDVQQG\n" + - "EwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNBMQ8wDQYDVQQKEwZPcmFjbGUx\n" + - "DzANBgNVBAsTBkpQR1NRRTESMBAGA1UEAxMJc2VjdDI4M3IxMB4XDTIwMDUyNjE4\n" + - "MDY1MloXDTQwMDUyMTE4MDY1MlowXTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNB\n" + - "MQswCQYDVQQHEwJTQTEPMA0GA1UEChMGT3JhY2xlMQ8wDQYDVQQLEwZKUEdTUUUx\n" + - "EjAQBgNVBAMTCXNlY3QyODNyMTBeMBAGByqGSM49AgEGBSuBBAARA0oABALatmDt\n" + - "QIhjpK4vJjv4GgC8CUH/VAWLUSQRU7yGGQ3NF8rVBARv0aehiII0nzjDVX5KrP/A\n" + - "w/DmW7q8PfEAIktuaA/tcKv/OKMyMDAwHQYDVR0OBBYEFM+jme1MbgRBCSExM7aA\n" + - "1ae/K5gEMA8GA1UdEwEB/wQFMAMBAf8wCwYHKoZIzj0EAQUAA08AMEwCJAGHsAP8\n" + - "HlcVqszra+fxq35juTxHJIfxTKIr7f54Ywtz7AJowgIkAxydv8g+dkuniOUAj0Xt\n" + - "FnGVp6HzKX5KM1zLpfqmix8ZPP/A\n" + - "-----END CERTIFICATE-----", - "MIGQAgEAMBAGByqGSM49AgEGBSuBBAARBHkwdwIBAQQkAdcyn/FxiNvuTsSgDehq\n" + - "SGFiTxAKNMMJfmsO6GHekzszFqjPoUwDSgAEAtq2YO1AiGOkri8mO/gaALwJQf9U\n" + - "BYtRJBFTvIYZDc0XytUEBG/Rp6GIgjSfOMNVfkqs/8DD8OZburw98QAiS25oD+1w\n" + - "q/84"), - CA_RSA_2048( "RSA", // SHA256withRSA, 2048 bits @@ -917,33 +889,6 @@ public static enum Cert { "MEcCAQAwBQYDK2VxBDsEOd6/hRZqkUyTlJSwdN5gO/HnoWYda1fD83YUm5j6m2Bg\n" + "hAQi+QadFsQLD7R6PI/4Q0twXqlKnxU5Ug=="), - EE_ECDSA_SECT283R1( - "EC", - // SHA1withECDSA, curve sect283r1 - // Validity - // Not Before: May 26 06:08:15 2020 GMT - // Not After : May 21 06:08:15 2040 GMT - // Authority Key Identifier: - // CF:A3:99:ED:4C:6E:04:41:09:21:31:33:B6:80:D5:A7:BF:2B:98:04 - "-----BEGIN CERTIFICATE-----\n" + - "MIICFTCCAbOgAwIBAgIJAM0Dd9zxR9CeMAsGByqGSM49BAEFADBdMQswCQYDVQQG\n" + - "EwJVUzELMAkGA1UECBMCQ0ExCzAJBgNVBAcTAlNBMQ8wDQYDVQQKEwZPcmFjbGUx\n" + - "DzANBgNVBAsTBkpQR1NRRTESMBAGA1UEAxMJc2VjdDI4M3IxMB4XDTIwMDUyNjE4\n" + - "MDgxNVoXDTQwMDUyMTE4MDgxNVowYDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNB\n" + - "MQswCQYDVQQHEwJTQTEPMA0GA1UEChMGT3JhY2xlMQ8wDQYDVQQLEwZKUEdTUUUx\n" + - "FTATBgNVBAMMDHNlY3QyODNyMV9lZTBeMBAGByqGSM49AgEGBSuBBAARA0oABAMP\n" + - "oaMP2lIiCrNaFSePtZA8nBnqJXSGCz8kosKeYTqz/SPE1AN6BvM4xl0kPQZvJWMz\n" + - "fyTcm2Ar0PdbIh8f22vJfO+0JpfhnqNTMFEwHQYDVR0OBBYEFOzDGNWQhslU5ei4\n" + - "SYda/ro9DickMA8GA1UdEwQIMAYBAf8CAQAwHwYDVR0jBBgwFoAUz6OZ7UxuBEEJ\n" + - "ITEztoDVp78rmAQwCwYHKoZIzj0EAQUAA08AMEwCJALYBWSYdbhRiW4mNulQh6/v\n" + - "dfHG3y/oMjzJEmT/A0WYl96ohgIkAbDC0Ke632RXtCZ4xa2FrmzP41Vb80mSH1iY\n" + - "FCJ3LVoTEUgN\n" + - "-----END CERTIFICATE-----", - "MIGQAgEAMBAGByqGSM49AgEGBSuBBAARBHkwdwIBAQQkAXq9LPYU+XSrImPzgO1e\n" + - "hsgjfTBXlWGveFUtn0OHPtbp7hzpoUwDSgAEAw+how/aUiIKs1oVJ4+1kDycGeol\n" + - "dIYLPySiwp5hOrP9I8TUA3oG8zjGXSQ9Bm8lYzN/JNybYCvQ91siHx/ba8l877Qm\n" + - "l+Ge"), - EE_ECDSA_SECP256R1( "EC", // SHA256withECDSA, curve secp256r1 diff --git a/test/jdk/jdk/security/jarsigner/Spec.java b/test/jdk/jdk/security/jarsigner/Spec.java index 908138762bd63..e04f278c5aae2 100644 --- a/test/jdk/jdk/security/jarsigner/Spec.java +++ b/test/jdk/jdk/security/jarsigner/Spec.java @@ -31,7 +31,7 @@ * jdk.jartool * jdk.crypto.ec * @build jdk.test.lib.util.JarUtils - * @run main/othervm -Djdk.sunec.disableNative=false Spec + * @run main/othervm Spec */ import com.sun.jarsigner.ContentSigner; @@ -190,7 +190,7 @@ public static void main(String[] args) throws Exception { .equals("SHA256withDSA")); kpg = KeyPairGenerator.getInstance("EC"); - kpg.initialize(192); + kpg.initialize(256); assertTrue(JarSigner.Builder .getDefaultSignatureAlgorithm(kpg.generateKeyPair().getPrivate()) .equals("SHA256withECDSA")); @@ -198,7 +198,7 @@ public static void main(String[] args) throws Exception { assertTrue(JarSigner.Builder .getDefaultSignatureAlgorithm(kpg.generateKeyPair().getPrivate()) .equals("SHA384withECDSA")); - kpg.initialize(571); + kpg.initialize(521); assertTrue(JarSigner.Builder .getDefaultSignatureAlgorithm(kpg.generateKeyPair().getPrivate()) .equals("SHA512withECDSA")); diff --git a/test/jdk/sun/security/ec/ECDSAJavaVerify.java b/test/jdk/sun/security/ec/ECDSAJavaVerify.java index ac4e5cdc5eedd..77aad015b8b7a 100644 --- a/test/jdk/sun/security/ec/ECDSAJavaVerify.java +++ b/test/jdk/sun/security/ec/ECDSAJavaVerify.java @@ -66,10 +66,7 @@ public class ECDSAJavaVerify { "SHA1withECDSA", "SHA256withECDSA", "SHA384withECDSA", "SHA512withECDSA"}; static final String[] ALL_CURVES = new String[] { - "secp128r1", "secp256k1", "secp256r1", "secp384r1", "secp521r1"}; - - static final List ALL_JAVA_CURVES - = List.of("secp256r1", "secp384r1", "secp521r1"); + "secp256r1", "secp384r1", "secp521r1"}; public static void main(String[] args) throws Exception { if (args.length == 1) { @@ -100,8 +97,7 @@ static void debug() throws Exception { = launchingConnector.defaultArguments(); arguments.get("main").setValue(ECDSAJavaVerify.class.getName()); arguments.get("options").setValue( - "-cp " + System.getProperty("test.classes") + - " -Djdk.sunec.disableNative=false"); + "-cp " + System.getProperty("test.classes")); VirtualMachine vm = launchingConnector.launch(arguments); MethodEntryRequest req = vm.eventRequestManager() @@ -117,7 +113,7 @@ static void debug() throws Exception { int pos = 0; for (String dummy : ALL_ALGS) { for (String curve : ALL_CURVES) { - char caller = ALL_JAVA_CURVES.contains(curve) ? 'J' : 'N'; + char caller = 'J'; // For each case, Signature::verify is called twice expected[pos++] = caller; expected[pos++] = caller; @@ -150,9 +146,6 @@ static void debug() throws Exception { case "verifySignedDigestImpl": // the java impl result[pos] = expected[pos] != 'J' ? 'x' : 'v'; break; - case "verifySignedDigest": // the native impl - result[pos] = expected[pos] != 'N' ? 'x' : 'v'; - break; } } vm.resume(); diff --git a/test/jdk/sun/security/ec/SignatureDigestTruncate.java b/test/jdk/sun/security/ec/SignatureDigestTruncate.java index 549ffc4af53ca..384568eda0f46 100644 --- a/test/jdk/sun/security/ec/SignatureDigestTruncate.java +++ b/test/jdk/sun/security/ec/SignatureDigestTruncate.java @@ -36,7 +36,7 @@ * group order. * @library /test/lib * @build jdk.test.lib.Convert - * @run main/othervm -Djdk.sunec.disableNative=false SignatureDigestTruncate + * @run main/othervm SignatureDigestTruncate */ public class SignatureDigestTruncate { @@ -117,12 +117,12 @@ private static void runTest(String alg, String curveName, } public static void main(String[] args) throws Exception { - runTest("SHA384withECDSAinP1363Format", "sect283r1", + runTest("SHA384withECDSAinP1363Format", "secp256r1", "abcdef10234567", "010203040506070809", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d" + - "1e1f20212223", - "01d7544b5d3935216bd45e2f8042537e1e0296a11e0eb96666199281b409" + - "42abccd5358a035de8a314d3e6c2a97614daebf5fb1313540eec3f9a3272" + - "068aa10922ccae87d255c84c"); + "1e1f20212223", + "d83534beccde787f9a4c6b0408337d9b9ca2e0a0259228526c15cc17a1d6" + + "4da6b34bf21b3bc4488c591d8ac9c33d93c7c6137e2ab4c503a42da7" + + "2fe0b6dda4c4"); } } diff --git a/test/jdk/sun/security/ec/TestEC.java b/test/jdk/sun/security/ec/TestEC.java index c9e44a6b954d4..36b5608b3e28d 100644 --- a/test/jdk/sun/security/ec/TestEC.java +++ b/test/jdk/sun/security/ec/TestEC.java @@ -48,13 +48,12 @@ /* * Leverage the collection of EC tests used by PKCS11 * - * NOTE: the following 6 files were copied here from the PKCS11 EC Test area + * NOTE: the following 5 files were copied here from the PKCS11 EC Test area * and must be kept in sync with the originals: * * ../pkcs11/ec/p12passwords.txt * ../pkcs11/ec/certs/sunlabscerts.pem * ../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p12 - * ../pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12 * ../pkcs11/sslecc/keystore * ../pkcs11/sslecc/truststore */ @@ -99,14 +98,21 @@ public static void main0(String[] args) throws Exception { * The entry point used for each test is its instance method * called main (not its static method called main). */ + System.out.println("TestECDH"); new TestECDH().main(p); + System.out.println("TestECDSA"); new TestECDSA().main(p); + System.out.println("TestCurves"); new TestCurves().main(p); + System.out.println("TestKeyFactory"); new TestKeyFactory().main(p); + System.out.println("TestECGenSpec"); new TestECGenSpec().main(p); + System.out.println("ReadPKCS12"); new ReadPKCS12().main(p); + System.out.println("ReadCertificate"); new ReadCertificates().main(p); - + System.out.println("ClientJSSEServerJSSE"); new ClientJSSEServerJSSE().main(p); long stop = System.currentTimeMillis(); diff --git a/test/jdk/sun/security/ec/keystore b/test/jdk/sun/security/ec/keystore index b59a2ab43c61b99c5d72a943aec13b090f111b62..c8a09d1a6de3961953d3da5f1a5071581e4a889b 100644 GIT binary patch delta 47 zcmX@0I8U1A-`jt085kItfS7qBPb2tdCjxJ`M4A%5x2w6IIW~_AS{S zAuH~9c;`pM;6t37cJr-2Dzd@2isNt8&O42>Y<3=bx#*9J+WOBkTK6kGJ9qi8ld1pr z@;3@HYQ^hL9^ELtd3S_PL&%P8tY;LC{cf%WTFl768lh)uUR~W3U*Wgd2jM`cD2bb*my-vOrykk4Gjzo4NZ&;jSYZYgT@UoQ}hfB^dP3FqnLst z%qCA|*Qoa}5MW~mI_jJ)6C)d|b|VXe1hWYP3&Y+Cwpa5~&3rHJu5!>3-#B4ba vT9?v<;0soD7k2k2@%5H(?&0{yB69lkrYR>{miDx&96ravqh7j2(>xIXU0B;- diff --git a/test/jdk/sun/security/ec/pkcs12/sect193r1server-rsa1024ca.p12 b/test/jdk/sun/security/ec/pkcs12/sect193r1server-rsa1024ca.p12 deleted file mode 100644 index ed4d861e4ca49cf3a574a67f52b8848306f69fe2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1252 zcmXqLVtK&C$ZXKWvW$&WtIebBJ1-+U zf*B7y*8H!PHP@--pWdg159{8oE>R6m)wk>WC-#}!CAi~)#Qe3%t3G7RHLhB6G3VBr zsam~pr$b~JoqaD@f3ww-*_7&(^@0CU%AUK9TNozJy;J zA7PNCc`xB|X#PBgLcL|dihD|5Imy2b+;5xJy86Q6Ko{;bcGD>-0XH9O>^{9?%CyrFNPi9h6tIuZC|cW?f$#JkV`Pc@HGT<*c7BJ*hBjd$%U zuH^Zo$i-^BSK(NAO@8O=yXTmHy%#FlW4PiRXYwm9MN98S+wG|)qOvB8J=a3}51jQ& zdUff@_AO$SR*pM;H~#v!$nV&rFUJk9HyUkYn3NqEIYl{LncUU=DVDG7Y{OL+$*Mz)HLGI&igYeIp}a+FUfw3f%!@%El>e5}w$GFM?9bMJwFcw4$72LN&vV>2*wAd==+ruV(-DRqiv#?1DNU!NVr)y=ohx{-$o~4PX}e z!=!n5PJPnx@ch@^k#p2SrY_I=mVbxMhx<|28nKOTF-A#q?_9f(v7lt;iR%Ji|4rQ3 z_w>;R!wdsuxKB7m4aHbQ%(i78Tos*n{`+?GnHwY2G7II;tuSyzC=xL=kuzc_W=Lg7 zW+-7WWUyo~W+(#EAdw=5GBBwNWEC?c0!0lNj2KLSDiaM14HOMH*;uvtn3<$l8CXPw m=X>2;aJj?&kK>Uw>3dZEw|#JxVBv_JE&b=r+-3_ len ; len++) { - System.out.println("Length "+keyLengths[len]); + for (int len : keyLengths) { + System.out.println("Length " + len); KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p); - kpg.initialize(keyLengths[len]); + kpg.initialize(len); KeyPair kp = kpg.generateKeyPair(); test(kf, kp.getPrivate()); test(kf, kp.getPublic()); diff --git a/test/jdk/sun/security/pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12 b/test/jdk/sun/security/pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12 deleted file mode 100644 index ed4d861e4ca49cf3a574a67f52b8848306f69fe2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1252 zcmXqLVtK&C$ZXKWvW$&WtIebBJ1-+U zf*B7y*8H!PHP@--pWdg159{8oE>R6m)wk>WC-#}!CAi~)#Qe3%t3G7RHLhB6G3VBr zsam~pr$b~JoqaD@f3ww-*_7&(^@0CU%AUK9TNozJy;J zA7PNCc`xB|X#PBgLcL|dihD|5Imy2b+;5xJy86Q6Ko{;bcGD>-0XH9O>^{9?%CyrFNPi9h6tIuZC|cW?f$#JkV`Pc@HGT<*c7BJ*hBjd$%U zuH^Zo$i-^BSK(NAO@8O=yXTmHy%#FlW4PiRXYwm9MN98S+wG|)qOvB8J=a3}51jQ& zdUff@_AO$SR*pM;H~#v!$nV&rFUJk9HyUkYn3NqEIYl{LncUU=DVDG7Y{OL+$*Mz)HLGI&igYeIp}a+FUfw3f%!@%El>e5}w$GFM?9bMJwFcw4$72LN&vV>2*wAd==+ruV(-DRqiv#?1DNU!NVr)y=ohx{-$o~4PX}e z!=!n5PJPnx@ch@^k#p2SrY_I=mVbxMhx<|28nKOTF-A#q?_9f(v7lt;iR%Ji|4rQ3 z_w>;R!wdsuxKB7m4aHbQ%(i78Tos*n{`+?GnHwY2G7II;tuSyzC=xL=kuzc_W=Lg7 zW+-7WWUyo~W+(#EAdw=5GBBwNWEC?c0!0lNj2KLSDiaM14HOMH*;uvtn3<$l8CXPw m=X>2;aJj?&kK>Uw>3dZEw|#JxVBv_JE&b=r+-3_2tdCjxJ`M4A%5x2w6IIW~_AS{S zAuH~9c;`pM;6t37cJr-2Dzd@2isNt8&O42>Y<3=bx#*9J+WOBkTK6kGJ9qi8ld1pr z@;3@HYQ^hL9^ELtd3S_PL&%P8tY;LC{cf%WTFl768lh)uUR~W3U*Wgd2jM`cD2bb*my-vOrykk4Gjzo4NZ&;jSYZYgT@UoQ}hfB^dP3FqnLst z%qCA|*Qoa}5MW~mI_jJ)6C)d|b|VXe1hWYP3&Y+Cwpa5~&3rHJu5!>3-#B4ba vT9?v<;0soD7k2k2@%5H(?&0{yB69lkrYR>{miDx&96ravqh7j2(>xIXU0B;- diff --git a/test/jdk/sun/security/provider/KeyStore/DKSTest.java b/test/jdk/sun/security/provider/KeyStore/DKSTest.java index dc63e82ecbd2b..56e8c37cd0077 100644 --- a/test/jdk/sun/security/provider/KeyStore/DKSTest.java +++ b/test/jdk/sun/security/provider/KeyStore/DKSTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2020, 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 @@ -52,8 +52,6 @@ public class DKSTest { new KeyStore.PasswordProtection("test12".toCharArray())); put("eckeystore1", new KeyStore.PasswordProtection("password".toCharArray())); - put("eckeystore2", - new KeyStore.PasswordProtection("password".toCharArray())); put("truststore", new KeyStore.PasswordProtection("changeit".toCharArray())); put("empty", @@ -69,8 +67,6 @@ public class DKSTest { new KeyStore.PasswordProtection("wrong".toCharArray())); put("eckeystore1", new KeyStore.PasswordProtection("wrong".toCharArray())); - put("eckeystore2", - new KeyStore.PasswordProtection("wrong".toCharArray())); }}; public static void main(String[] args) throws Exception { @@ -154,7 +150,7 @@ public static void main(String[] args) throws Exception { * domain keystore: keystores */ config = new URI(CONFIG + "#keystores"); - expected = 2 + 1 + 1 + 1; + expected = 2 + 1 + 1; keystore = KeyStore.getInstance("DKS"); // load entries keystore.load(new DomainLoadStoreParameter(config, PASSWORDS)); diff --git a/test/jdk/sun/security/provider/KeyStore/domains.cfg b/test/jdk/sun/security/provider/KeyStore/domains.cfg index f26d6f08fe1fe..da739377a7da7 100644 --- a/test/jdk/sun/security/provider/KeyStore/domains.cfg +++ b/test/jdk/sun/security/provider/KeyStore/domains.cfg @@ -25,8 +25,6 @@ domain keystores keystoreType="CaseExactJKS" keystoreURI="${test.src}/pw.jks"; keystore eckeystore1 - keystoreURI="${test.src}/../../pkcs11/ec/pkcs12/sect193r1server-rsa1024ca.p12"; - keystore eckeystore2 keystoreURI="${test.src}/../../pkcs11/ec/pkcs12/secp256r1server-secp384r1ca.p12"; }; @@ -40,8 +38,6 @@ domain keystores_tmp keystoreType="CaseExactJKS" keystoreURI="${user.dir}/pw.jks_tmp"; keystore eckeystore1 - keystoreURI="${user.dir}/sect193r1server-rsa1024ca.p12_tmp"; - keystore eckeystore2 keystoreURI="${user.dir}/secp256r1server-secp384r1ca.p12_tmp"; }; diff --git a/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java b/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java index 620b11b773eb6..49b6105eff4c9 100644 --- a/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java +++ b/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java @@ -25,10 +25,10 @@ * @test * @bug 8246330 * @library /javax/net/ssl/templates - * @run main/othervm -Djdk.tls.namedGroups="sect283r1" + * @run main/othervm -Djdk.tls.namedGroups="secp384r1" DisabledCurve DISABLE_NONE PASS - * @run main/othervm -Djdk.tls.namedGroups="sect283r1" - DisabledCurve sect283r1 FAIL + * @run main/othervm -Djdk.tls.namedGroups="secp384r1" + DisabledCurve secp384r1 FAIL */ import java.security.Security; import java.util.Arrays; @@ -49,18 +49,18 @@ public class DisabledCurve extends SSLSocketTemplate { protected SSLContext createClientSSLContext() throws Exception { return createSSLContext( new SSLSocketTemplate.Cert[] { - SSLSocketTemplate.Cert.CA_ECDSA_SECT283R1 }, + SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 }, new SSLSocketTemplate.Cert[] { - SSLSocketTemplate.Cert.EE_ECDSA_SECT283R1 }, + SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 }, getClientContextParameters()); } protected SSLContext createServerSSLContext() throws Exception { return createSSLContext( new SSLSocketTemplate.Cert[] { - SSLSocketTemplate.Cert.CA_ECDSA_SECT283R1 }, + SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 }, new SSLSocketTemplate.Cert[] { - SSLSocketTemplate.Cert.EE_ECDSA_SECT283R1 }, + SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 }, getServerContextParameters()); } @@ -89,22 +89,23 @@ protected void configureServerSocket(SSLServerSocket serverSocket) { public static void main(String[] args) throws Exception { String expected = args[1]; String disabledName = ("DISABLE_NONE".equals(args[0]) ? "" : args[0]); + boolean disabled = false; if (disabledName.equals("")) { Security.setProperty("jdk.disabled.namedCurves", ""); + } else { + disabled = true; + Security.setProperty("jdk.certpath.disabledAlgorithms", "secp384r1"); } - System.setProperty("jdk.sunec.disableNative", "false"); for (index = 0; index < protocols.length; index++) { try { (new DisabledCurve()).run(); if (expected.equals("FAIL")) { throw new RuntimeException( - "The test case should not reach here"); + "Expected test to fail, but it passed"); } } catch (SSLException | IllegalStateException ssle) { - if ((expected.equals("FAIL")) - && Security.getProperty("jdk.disabled.namedCurves") - .contains(disabledName)) { + if (expected.equals("FAIL") && disabled) { System.out.println( "Expected exception was thrown: TEST PASSED"); } else { diff --git a/test/jdk/sun/security/tools/jarsigner/RestrictedAlgo.java b/test/jdk/sun/security/tools/jarsigner/RestrictedAlgo.java index 07dc2e47b4b42..65fb1374bdce5 100644 --- a/test/jdk/sun/security/tools/jarsigner/RestrictedAlgo.java +++ b/test/jdk/sun/security/tools/jarsigner/RestrictedAlgo.java @@ -93,11 +93,6 @@ public static void main(String[] args) throws Exception { System.out.println("\nTesting DSA Keysize: DSA keySize < 1024\n"); test("DSA", "SHA256withDSA", "KeySizeDSA", "SHA256", true, "-keysize", "512"); - - System.out.println("\nTesting Native Curve:" - + " include jdk.disabled.namedCurves\n"); - test("EC", "SHA256withECDSA", "curve", "SHA256", true, - "-groupname", "secp112r1"); } private static void test(String keyAlg, String sigAlg, String aliasPrefix, @@ -123,8 +118,7 @@ private static void testKeytool(String keyAlg, String sigAlg, String alias, "-ext", "bc:c", "-keyalg", keyAlg, "-sigalg", sigAlg, - "-alias", alias, - "-J-Djdk.sunec.disableNative=false"); + "-alias", alias); for (String additionalCMDArg : additionalCmdArgs) { cmd.add(additionalCMDArg); } @@ -147,8 +141,7 @@ private static void testJarSignerSigning(String sigAlg, String alias, "-digestalg", digestAlg, "-signedjar", SIGNED_JARFILE, UNSIGNED_JARFILE, - alias, - "-J-Djdk.sunec.disableNative=false"); + alias); OutputAnalyzer analyzer = SecurityTools.jarsigner(cmd) .shouldHaveExitValue(0); @@ -162,8 +155,7 @@ private static void testJarSignerVerification() System.out.println("\nTesting JarSigner Verification\n"); List cmd = prepareCommand( "-verify", - SIGNED_JARFILE, - "-J-Djdk.sunec.disableNative=false"); + SIGNED_JARFILE); OutputAnalyzer analyzer = SecurityTools.jarsigner(cmd) .shouldHaveExitValue(0); diff --git a/test/jdk/sun/security/tools/keytool/GroupName.java b/test/jdk/sun/security/tools/keytool/GroupName.java index 6b8c57dd98c10..2251ca47fe95b 100644 --- a/test/jdk/sun/security/tools/keytool/GroupName.java +++ b/test/jdk/sun/security/tools/keytool/GroupName.java @@ -65,11 +65,6 @@ public static void main(String[] args) throws Throwable { .shouldNotContain("Specifying -keysize for generating EC keys is deprecated"); checkCurveName("e", "secp256r1"); - gen("f", "-J-Djdk.sunec.disableNative=false -keyalg EC -groupname brainpoolP256r1") - .shouldHaveExitValue(0) - .shouldNotContain("Specifying -keysize for generating EC keys is deprecated"); - checkCurveName("f", "brainpoolP256r1"); - kt("-list -v") .shouldHaveExitValue(0) .shouldContain("Subject Public Key Algorithm: 256-bit EC (secp256r1) key"); diff --git a/test/jdk/sun/security/tools/keytool/KeyAlg.java b/test/jdk/sun/security/tools/keytool/KeyAlg.java index 5a85ece04f9d1..044568ca624c5 100644 --- a/test/jdk/sun/security/tools/keytool/KeyAlg.java +++ b/test/jdk/sun/security/tools/keytool/KeyAlg.java @@ -41,10 +41,6 @@ public static void main(String[] args) throws Exception { keytool("-printcert -file user.crt") .shouldMatch("Signature algorithm name:.*SHA1withECDSA") .shouldMatch("Subject Public Key Algorithm:.*1024.*RSA"); - keytool("-genkeypair -alias e -dname CN=e " + - "-J-Djdk.sunec.disableNative=false -keyalg EC " + - "-groupname brainpoolP256r1") - .shouldContain("Generating 256 bit EC (brainpoolP256r1) key pair"); keytool("-genkeypair -alias f -dname CN=f -keyalg EC") .shouldContain("Generating 256 bit EC (secp256r1) key pair"); keytool("-genkeypair -alias g -dname CN=g -keyalg EC -keysize 384") diff --git a/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java b/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java index fbe8e63bdf030..b4ae0e21c76be 100644 --- a/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java +++ b/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java @@ -55,11 +55,9 @@ public static void main(String[] args) throws Exception { check("DSA", 1024, null, "SHA256withDSA"); check("DSA", 3072, null, "SHA256withDSA"); - check("EC", 192, null, "SHA256withECDSA"); check("EC", 384, null, "SHA384withECDSA"); - check("EC", 571, null, "SHA512withECDSA"); - check("EC", 571, "SHA256withECDSA", "SHA256withECDSA"); + check("EC", 384, "SHA256withECDSA", "SHA256withECDSA"); } private static void check(String keyAlg, int keySize, @@ -82,8 +80,7 @@ private static void check(String keyAlg, int keySize, static OutputAnalyzer genkeypair(String alias, String options) throws Exception { - String patchArg = "-J-Djdk.sunec.disableNative=false " + - "-J--patch-module=java.base=" + String patchArg = "-J--patch-module=java.base=" + System.getProperty("test.classes") + File.separator + "patches" + File.separator + "java.base" + " -J--patch-module=jdk.crypto.ec=" diff --git a/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java b/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java index 68da125087f09..f688da1c63572 100644 --- a/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java +++ b/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -58,14 +58,6 @@ public void initialize(AlgorithmParameterSpec params, SecureRandom random) public KeyPair generateKeyPair() { BigInteger s, x, y; switch (keySize) { - case 192: - s = new BigInteger("144089953963995451666433763881605261867377" - + "0287449914970417"); - x = new BigInteger("527580219290493448707803038403444129676461" - + "560927008883862"); - y = new BigInteger("171489247081620145247240656640887886126295" - + "376102134763235"); - break; case 384: s = new BigInteger("230878276322370828604837367594276033697165" + "328633328282930557390817326627704675451851870430805" @@ -77,22 +69,10 @@ public KeyPair generateKeyPair() { + "792287657810480793861620950159864617021540168828129" + "97920015041145259782242"); break; - case 571: - s = new BigInteger("102950007413729156017516513076331886543538" - + "947044937190140406420556321983301533699021909556189" - + "150601557539520495361099574425100081169640300555562" - + "4280643194744140660275077121"); - x = new BigInteger("640598847385582251482893323029655037929442" - + "593800810090252942944624854811134311418807076811195" - + "132373308708007447666896675761104237802118413642543" - + "8277858107132017492037336593"); - y = new BigInteger("254271270803422773271985083014247202480077" - + "131823713050110789460550383275777195766342550786766" - + "080401402424961690914429074822281551140068729472439" - + "477216613432839953714415981"); - break; default: - throw new AssertionError("Unsupported keysize " + keySize); + throw new AssertionError("SunEC ECKeyPairGenerator" + + "has been patched. Key size " + keySize + + " is not supported"); } ECParameterSpec ecParams = ECUtil.getECParameterSpec(null, keySize); try { From dcde95ba0d68a3aa3f2f405c6141d645a52c28e4 Mon Sep 17 00:00:00 2001 From: Roberto Castaneda Lozano Date: Fri, 25 Sep 2020 06:53:48 +0000 Subject: [PATCH 10/79] 8253586: C2: Clean up unused PhaseIterGVN::init_worklist() Remove unused method PhaseIterGVN::init_worklist(Node *). Reviewed-by: thartmann, chagedorn, neliasso --- src/hotspot/share/opto/phaseX.cpp | 23 ----------------------- src/hotspot/share/opto/phaseX.hpp | 3 --- 2 files changed, 26 deletions(-) diff --git a/src/hotspot/share/opto/phaseX.cpp b/src/hotspot/share/opto/phaseX.cpp index 9f54458faf6f7..58f820d0c725a 100644 --- a/src/hotspot/share/opto/phaseX.cpp +++ b/src/hotspot/share/opto/phaseX.cpp @@ -975,29 +975,6 @@ PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), } } -/** - * Initialize worklist for each node. - */ -void PhaseIterGVN::init_worklist(Node* first) { - Unique_Node_List to_process; - to_process.push(first); - - while (to_process.size() > 0) { - Node* n = to_process.pop(); - if (!_worklist.member(n)) { - _worklist.push(n); - - uint cnt = n->req(); - for(uint i = 0; i < cnt; i++) { - Node* m = n->in(i); - if (m != NULL) { - to_process.push(m); - } - } - } - } -} - #ifndef PRODUCT void PhaseIterGVN::verify_step(Node* n) { if (VerifyIterativeGVN) { diff --git a/src/hotspot/share/opto/phaseX.hpp b/src/hotspot/share/opto/phaseX.hpp index 419d70b4d3edb..ec6ef2f78d56c 100644 --- a/src/hotspot/share/opto/phaseX.hpp +++ b/src/hotspot/share/opto/phaseX.hpp @@ -458,9 +458,6 @@ class PhaseIterGVN : public PhaseGVN { protected: - // Warm up hash table, type table and initial worklist - void init_worklist( Node *a_root ); - virtual const Type* saturate(const Type* new_type, const Type* old_type, const Type* limit_type) const; // Usually returns new_type. Returns old_type if new_type is only a slight From 37b70282b5bba1033eaa06fe64ac5438168c1be3 Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Fri, 25 Sep 2020 07:11:55 +0000 Subject: [PATCH 11/79] 8240556: Abort concurrent mark after effective eager reclamation of humongous objects Reviewed-by: sjohanss, ayang --- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 52 ++++--- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 13 +- src/hotspot/share/gc/g1/g1ConcurrentMark.cpp | 18 ++- src/hotspot/share/gc/g1/g1ConcurrentMark.hpp | 10 +- .../share/gc/g1/g1ConcurrentMarkThread.cpp | 43 ++++-- .../share/gc/g1/g1ConcurrentMarkThread.hpp | 36 +++-- .../gc/g1/g1ConcurrentMarkThread.inline.hpp | 21 +++ .../share/gc/g1/g1HeterogeneousHeapPolicy.cpp | 4 +- .../share/gc/g1/g1HeterogeneousHeapPolicy.hpp | 2 +- src/hotspot/share/gc/g1/g1Policy.cpp | 55 +++++--- src/hotspot/share/gc/g1/g1Policy.hpp | 15 +- src/hotspot/share/gc/g1/g1ServiceThread.cpp | 2 +- src/hotspot/share/prims/whitebox.cpp | 6 +- .../g1/TestHumongousConcurrentStartUndo.java | 129 ++++++++++++++++++ ...TestStressBigAllocationGCEventsWithG1.java | 46 ------- 15 files changed, 301 insertions(+), 151 deletions(-) create mode 100644 test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java delete mode 100644 test/hotspot/jtreg/gc/stress/jfr/TestStressBigAllocationGCEventsWithG1.java diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 710a34ca81681..b57ee35d9e6ef 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -850,7 +850,7 @@ HeapWord* G1CollectedHeap::attempt_allocation_humongous(size_t word_size) { // before the allocation is that we avoid having to keep track of the newly // allocated memory while we do a GC. if (policy()->need_to_start_conc_mark("concurrent humongous allocation", - word_size)) { + word_size)) { collect(GCCause::_g1_humongous_allocation); } @@ -2717,12 +2717,18 @@ HeapWord* G1CollectedHeap::do_collection_pause(size_t word_size, return result; } -void G1CollectedHeap::do_concurrent_mark() { +void G1CollectedHeap::start_concurrent_cycle(bool concurrent_operation_is_full_mark) { + assert(!_cm_thread->in_progress(), "Can not start concurrent operation while in progress"); + MutexLocker x(CGC_lock, Mutex::_no_safepoint_check_flag); - if (!_cm_thread->in_progress()) { - _cm_thread->set_started(); - CGC_lock->notify(); + if (concurrent_operation_is_full_mark) { + _cm->post_concurrent_mark_start(); + _cm_thread->start_full_mark(); + } else { + _cm->post_concurrent_undo_start(); + _cm_thread->start_undo_mark(); } + CGC_lock->notify(); } bool G1CollectedHeap::is_potential_eager_reclaim_candidate(HeapRegion* r) const { @@ -2975,13 +2981,11 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus // We also do not allow mixed GCs during marking. assert(!collector_state()->mark_or_rebuild_in_progress() || collector_state()->in_young_only_phase(), "sanity"); - // Record whether this pause is a concurrent start. When the current - // thread has completed its logging output and it's safe to signal - // the CM thread, the flag's value in the policy has been reset. - bool should_start_conc_mark = collector_state()->in_concurrent_start_gc(); - if (should_start_conc_mark) { - _cm->gc_tracer_cm()->set_gc_cause(gc_cause()); - } + // Record whether this pause may need to trigger a concurrent operation. Later, + // when we signal the G1ConcurrentMarkThread, the collector state has already + // been reset for the next pause. + bool should_start_concurrent_mark_operation = collector_state()->in_concurrent_start_gc(); + bool concurrent_operation_is_full_mark = false; // Inner scope for scope based logging, timers, and stats collection { @@ -3058,25 +3062,19 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus _survivor_evac_stats.adjust_desired_plab_sz(); _old_evac_stats.adjust_desired_plab_sz(); - if (should_start_conc_mark) { - // We have to do this before we notify the CM threads that - // they can start working to make sure that all the - // appropriate initialization is done on the CM object. - concurrent_mark()->post_concurrent_start(); - // Note that we don't actually trigger the CM thread at - // this point. We do that later when we're sure that - // the current thread has completed its logging output. - } - allocate_dummy_regions(); _allocator->init_mutator_alloc_regions(); expand_heap_after_young_collection(); + // Refine the type of a concurrent mark operation now that we did the + // evacuation, eventually aborting it. + concurrent_operation_is_full_mark = policy()->concurrent_operation_is_full_mark("Revise IHOP"); + double sample_end_time_sec = os::elapsedTime(); double pause_time_ms = (sample_end_time_sec - sample_start_time_sec) * MILLIUNITS; - policy()->record_collection_pause_end(pause_time_ms); + policy()->record_collection_pause_end(pause_time_ms, concurrent_operation_is_full_mark); } verify_after_young_collection(verify_type); @@ -3117,13 +3115,13 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus // without its logging output interfering with the logging output // that came from the pause. - if (should_start_conc_mark) { - // CAUTION: after the doConcurrentMark() call below, the concurrent marking + if (should_start_concurrent_mark_operation) { + // CAUTION: after the start_concurrent_cycle() call below, the concurrent marking // thread(s) could be running concurrently with us. Make sure that anything // after this point does not assume that we are the only GC thread running. // Note: of course, the actual marking work will not start until the safepoint // itself is released in SuspendibleThreadSet::desynchronize(). - do_concurrent_mark(); + start_concurrent_cycle(concurrent_operation_is_full_mark); ConcurrentGCBreakpoints::notify_idle_to_active(); } } @@ -3733,7 +3731,7 @@ void G1CollectedHeap::pre_evacuate_collection_set(G1EvacuationInfo& evacuation_i // Concurrent start needs claim bits to keep track of the marked-through CLDs. if (collector_state()->in_concurrent_start_gc()) { - concurrent_mark()->pre_concurrent_start(); + concurrent_mark()->pre_concurrent_start(gc_cause()); double start_clear_claimed_marks = os::elapsedTime(); diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 546a25e7c5d05..509d65bfa53aa 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -746,6 +746,9 @@ class G1CollectedHeap : public CollectedHeap { void reset_taskqueue_stats(); #endif // TASKQUEUE_STATS + // Start a concurrent cycle. + void start_concurrent_cycle(bool concurrent_operation_is_full_mark); + // Schedule the VM operation that will do an evacuation pause to // satisfy an allocation request of word_size. *succeeded will // return whether the VM operation was successful (it did do an @@ -1307,16 +1310,6 @@ class G1CollectedHeap : public CollectedHeap { bool check_young_list_empty(); #endif - // *** Stuff related to concurrent marking. It's not clear to me that so - // many of these need to be public. - - // The functions below are helper functions that a subclass of - // "CollectedHeap" can use in the implementation of its virtual - // functions. - // This performs a concurrent marking of the live objects in a - // bitmap off to the side. - void do_concurrent_mark(); - bool is_marked_next(oop obj) const; // Determine if an object is dead, given the object and also diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp index db39d0a3d315c..fa3502328468f 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp @@ -607,7 +607,7 @@ class G1ClearBitMapTask : public AbstractGangTask { // as asserts here to minimize their overhead on the product. However, we // will have them as guarantees at the beginning / end of the bitmap // clearing to get some checking in the product. - assert(_cm == NULL || _cm->cm_thread()->during_cycle(), "invariant"); + assert(_cm == NULL || _cm->cm_thread()->in_progress(), "invariant"); assert(_cm == NULL || !G1CollectedHeap::heap()->collector_state()->mark_or_rebuild_in_progress(), "invariant"); } assert(cur == end, "Must have completed iteration over the bitmap for region %u.", r->hrm_index()); @@ -656,7 +656,7 @@ void G1ConcurrentMark::clear_bitmap(G1CMBitMap* bitmap, WorkGang* workers, bool void G1ConcurrentMark::cleanup_for_next_mark() { // Make sure that the concurrent mark thread looks to still be in // the current cycle. - guarantee(cm_thread()->during_cycle(), "invariant"); + guarantee(cm_thread()->in_progress(), "invariant"); // We are finishing up the current cycle by clearing the next // marking bitmap and getting it ready for the next cycle. During @@ -667,7 +667,7 @@ void G1ConcurrentMark::cleanup_for_next_mark() { clear_bitmap(_next_mark_bitmap, _concurrent_workers, true); // Repeat the asserts from above. - guarantee(cm_thread()->during_cycle(), "invariant"); + guarantee(cm_thread()->in_progress(), "invariant"); guarantee(!_g1h->collector_state()->mark_or_rebuild_in_progress(), "invariant"); } @@ -684,7 +684,7 @@ class NoteStartOfMarkHRClosure : public HeapRegionClosure { } }; -void G1ConcurrentMark::pre_concurrent_start() { +void G1ConcurrentMark::pre_concurrent_start(GCCause::Cause cause) { assert_at_safepoint_on_vm_thread(); // Reset marking state. @@ -695,10 +695,12 @@ void G1ConcurrentMark::pre_concurrent_start() { _g1h->heap_region_iterate(&startcl); _root_regions.reset(); + + _gc_tracer_cm->set_gc_cause(cause); } -void G1ConcurrentMark::post_concurrent_start() { +void G1ConcurrentMark::post_concurrent_mark_start() { // Start Concurrent Marking weak-reference discovery. ReferenceProcessor* rp = _g1h->ref_processor_cm(); // enable ("weak") refs discovery @@ -719,6 +721,10 @@ void G1ConcurrentMark::post_concurrent_start() { // during it. No need to call it here. } +void G1ConcurrentMark::post_concurrent_undo_start() { + root_regions()->cancel_scan(); +} + /* * Notice that in the next two methods, we actually leave the STS * during the barrier sync and join it immediately afterwards. If we @@ -1956,7 +1962,7 @@ void G1ConcurrentMark::print_stats() { } void G1ConcurrentMark::concurrent_cycle_abort() { - if (!cm_thread()->during_cycle() || _has_aborted) { + if (!cm_thread()->in_progress() || _has_aborted) { // We haven't started a concurrent cycle or we have already aborted it. No need to do anything. return; } diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp index c5c7072eb10e3..6ac83ba49533f 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp @@ -30,12 +30,14 @@ #include "gc/g1/g1HeapVerifier.hpp" #include "gc/g1/g1RegionMarkStatsCache.hpp" #include "gc/g1/heapRegionSet.hpp" +#include "gc/shared/gcCause.hpp" #include "gc/shared/taskTerminator.hpp" #include "gc/shared/taskqueue.hpp" #include "gc/shared/verifyOption.hpp" #include "gc/shared/workgroup.hpp" #include "memory/allocation.hpp" #include "utilities/compilerWarnings.hpp" +#include "utilities/numberSeq.hpp" class ConcurrentGCTimer; class G1ConcurrentMarkThread; @@ -305,7 +307,7 @@ class G1ConcurrentMark : public CHeapObj { MemRegion const _heap; // Root region tracking and claiming - G1CMRootMemRegions _root_regions; + G1CMRootMemRegions _root_regions; // For grey objects G1CMMarkStack _global_mark_stack; // Grey objects behind global finger @@ -542,8 +544,9 @@ class G1ConcurrentMark : public CHeapObj { // These two methods do the work that needs to be done at the start and end of the // concurrent start pause. - void pre_concurrent_start(); - void post_concurrent_start(); + void pre_concurrent_start(GCCause::Cause cause); + void post_concurrent_mark_start(); + void post_concurrent_undo_start(); // Scan all the root regions and mark everything reachable from // them. @@ -594,7 +597,6 @@ class G1ConcurrentMark : public CHeapObj { inline bool is_marked_in_next_bitmap(oop p) const; ConcurrentGCTimer* gc_timer_cm() const { return _gc_timer_cm; } - G1OldTracer* gc_tracer_cm() const { return _gc_tracer_cm; } private: // Rebuilds the remembered sets for chosen regions in parallel and concurrently to the application. diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp index e204fb2d9bc52..c1b9fbbf19e9f 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.cpp @@ -42,6 +42,7 @@ #include "runtime/handles.inline.hpp" #include "runtime/vmThread.hpp" #include "utilities/debug.hpp" +#include "utilities/formatBuffer.hpp" #include "utilities/ticks.hpp" G1ConcurrentMarkThread::G1ConcurrentMarkThread(G1ConcurrentMark* cm) : @@ -135,13 +136,22 @@ void G1ConcurrentMarkThread::run_service() { _vtime_start = os::elapsedVTime(); while (wait_for_next_cycle()) { + assert(in_progress(), "must be"); GCIdMark gc_id_mark; - GCTraceConcTime(Info, gc) tt("Concurrent Cycle"); + GCTraceConcTime(Info, gc) tt(FormatBuffer<128>("Concurrent %s Cycle", + _state == FullMark ? "Mark" : "Undo")); concurrent_cycle_start(); - full_concurrent_cycle_do(); - concurrent_cycle_end(); + + if (_state == FullMark) { + concurrent_mark_cycle_do(); + } else { + assert(_state == UndoMark, "Must do undo mark but is %d", _state); + concurrent_undo_cycle_do(); + } + + concurrent_cycle_end(_state == FullMark && !_cm->has_aborted()); _vtime_accum = (os::elapsedVTime() - _vtime_start); } @@ -157,14 +167,10 @@ bool G1ConcurrentMarkThread::wait_for_next_cycle() { assert(!in_progress(), "should have been cleared"); MonitorLocker ml(CGC_lock, Mutex::_no_safepoint_check_flag); - while (!started() && !should_terminate()) { + while (!in_progress() && !should_terminate()) { ml.wait(); } - if (started()) { - set_in_progress(); - } - return !should_terminate(); } @@ -269,7 +275,7 @@ void G1ConcurrentMarkThread::concurrent_cycle_start() { _cm->concurrent_cycle_start(); } -void G1ConcurrentMarkThread::full_concurrent_cycle_do() { +void G1ConcurrentMarkThread::concurrent_mark_cycle_do() { HandleMark hm(Thread::current()); ResourceMark rm; @@ -289,6 +295,9 @@ void G1ConcurrentMarkThread::full_concurrent_cycle_do() { // // For the same reason ConcurrentGCBreakpoints (in the phase methods) before // here risk deadlock, because a young GC must wait for root region scanning. + // + // We can not easily abort before root region scan either because of the + // reasons mentioned in G1CollectedHeap::abort_concurrent_cycle(). // Phase 2: Scan root regions. if (phase_scan_root_regions()) return; @@ -309,14 +318,26 @@ void G1ConcurrentMarkThread::full_concurrent_cycle_do() { phase_clear_bitmap_for_next_mark(); } -void G1ConcurrentMarkThread::concurrent_cycle_end() { +void G1ConcurrentMarkThread::concurrent_undo_cycle_do() { + HandleMark hm(Thread::current()); + ResourceMark rm; + + // We can (and should) abort if there has been a concurrent cycle abort for + // some reason. + if (_cm->has_aborted()) { return; } + + // Phase 1: Clear bitmap for next mark. + phase_clear_bitmap_for_next_mark(); +} + +void G1ConcurrentMarkThread::concurrent_cycle_end(bool mark_cycle_completed) { // Update the number of full collections that have been // completed. This will also notify the G1OldGCCount_lock in case a // Java thread is waiting for a full GC to happen (e.g., it // called System.gc() with +ExplicitGCInvokesConcurrent). SuspendibleThreadSetJoiner sts_join; G1CollectedHeap::heap()->increment_old_marking_cycles_completed(true /* concurrent */, - !_cm->has_aborted()); + mark_cycle_completed /* heap_examined */); _cm->concurrent_cycle_end(); ConcurrentGCBreakpoints::notify_active_to_idle(); diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.hpp index 1ea73abc76c2f..cdf02a75b82f5 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.hpp @@ -40,15 +40,15 @@ class G1ConcurrentMarkThread: public ConcurrentGCThread { G1ConcurrentMark* _cm; - enum ServiceState { + enum ServiceState : uint { Idle, - Started, - InProgress + FullMark, + UndoMark }; volatile ServiceState _state; - // Wait for next cycle. Returns false if the service should be stopped. + // Wait for next cycle. Returns the command passed over. bool wait_for_next_cycle(); bool mark_loop_needs_restart() const; @@ -74,8 +74,10 @@ class G1ConcurrentMarkThread: public ConcurrentGCThread { void concurrent_cycle_start(); - void full_concurrent_cycle_do(); - void concurrent_cycle_end(); + void concurrent_mark_cycle_do(); + void concurrent_undo_cycle_do(); + + void concurrent_cycle_end(bool mark_cycle_completed); // Delay pauses to meet MMU. void delay_to_keep_mmu(bool remark); @@ -93,24 +95,20 @@ class G1ConcurrentMarkThread: public ConcurrentGCThread { // Marking virtual time so far this thread and concurrent marking tasks. double vtime_mark_accum(); - G1ConcurrentMark* cm() { return _cm; } + G1ConcurrentMark* cm() { return _cm; } - void set_idle() { assert(_state != Started, "must not be starting a new cycle"); _state = Idle; } - bool idle() { return _state == Idle; } - void set_started() { assert(_state == Idle, "cycle in progress"); _state = Started; } - bool started() { return _state == Started; } - void set_in_progress() { assert(_state == Started, "must be starting a cycle"); _state = InProgress; } - bool in_progress() { return _state == InProgress; } + void set_idle(); + void start_full_mark(); + void start_undo_mark(); + void set_in_progress(); - // Returns true from the moment a marking cycle is + bool idle() const; + // Returns true from the moment a concurrent cycle is // initiated (during the concurrent start pause when started() is set) // to the moment when the cycle completes (just after the next // marking bitmap has been cleared and in_progress() is - // cleared). While during_cycle() is true we will not start another cycle - // so that cycles do not overlap. We cannot use just in_progress() - // as the CM thread might take some time to wake up before noticing - // that started() is set and set in_progress(). - bool during_cycle() { return !idle(); } + // cleared). + bool in_progress() const; }; #endif // SHARE_GC_G1_G1CONCURRENTMARKTHREAD_HPP diff --git a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.inline.hpp b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.inline.hpp index 60769af0903a8..ee707cda22650 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.inline.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentMarkThread.inline.hpp @@ -38,4 +38,25 @@ inline double G1ConcurrentMarkThread::vtime_mark_accum() { return _cm->all_task_accum_vtime(); } +inline void G1ConcurrentMarkThread::set_idle() { + assert(_state == FullMark || _state == UndoMark, "must not be starting a new cycle"); + _state = Idle; +} + +inline void G1ConcurrentMarkThread::start_full_mark() { + assert(_state == Idle, "cycle in progress"); + _state = FullMark; +} + +inline void G1ConcurrentMarkThread::start_undo_mark() { + assert(_state == Idle, "cycle in progress"); + _state = UndoMark; +} + +inline bool G1ConcurrentMarkThread::idle() const { return _state == Idle; } + +inline bool G1ConcurrentMarkThread::in_progress() const { + return !idle(); +} + #endif // SHARE_GC_G1_G1CONCURRENTMARKTHREAD_INLINE_HPP diff --git a/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.cpp b/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.cpp index fba7eb2edab12..92aa996ef5c6b 100644 --- a/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.cpp +++ b/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.cpp @@ -39,8 +39,8 @@ void G1HeterogeneousHeapPolicy::init(G1CollectedHeap* g1h, G1CollectionSet* coll } // After a collection pause, young list target length is updated. So we need to make sure we have enough regions in dram for young gen. -void G1HeterogeneousHeapPolicy::record_collection_pause_end(double pause_time_ms) { - G1Policy::record_collection_pause_end(pause_time_ms); +void G1HeterogeneousHeapPolicy::record_collection_pause_end(double pause_time_ms, bool concurrent_operation_is_full_mark) { + G1Policy::record_collection_pause_end(pause_time_ms, concurrent_operation_is_full_mark); _manager->adjust_dram_regions((uint)young_list_target_length(), G1CollectedHeap::heap()->workers()); } diff --git a/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.hpp b/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.hpp index 88feca7b5a1fc..6051fc532b819 100644 --- a/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.hpp +++ b/src/hotspot/share/gc/g1/g1HeterogeneousHeapPolicy.hpp @@ -38,7 +38,7 @@ class G1HeterogeneousHeapPolicy : public G1Policy { // initialize policy virtual void init(G1CollectedHeap* g1h, G1CollectionSet* collection_set); // Record end of an evacuation pause. - virtual void record_collection_pause_end(double pause_time_ms); + virtual void record_collection_pause_end(double pause_time_ms, bool concurrent_operation_is_full_mark); // Record the end of full collection. virtual void record_full_collection_end(); diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index afde3853bde04..cd38cc684b692 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -452,7 +452,7 @@ void G1Policy::record_full_collection_end() { // transitions and make sure we start with young GCs after the Full GC. collector_state()->set_in_young_only_phase(true); collector_state()->set_in_young_gc_before_mixed(false); - collector_state()->set_initiate_conc_mark_if_possible(need_to_start_conc_mark("end of Full GC", 0)); + collector_state()->set_initiate_conc_mark_if_possible(need_to_start_conc_mark("end of Full GC")); collector_state()->set_in_concurrent_start_gc(false); collector_state()->set_mark_or_rebuild_in_progress(false); collector_state()->set_clearing_next_bitmap(false); @@ -547,7 +547,7 @@ void G1Policy::record_collection_pause_start(double start_time_sec) { assert(_g1h->collection_set()->verify_young_ages(), "region age verification failed"); } -void G1Policy::record_concurrent_mark_init_end(double mark_init_elapsed_time_ms) { +void G1Policy::record_concurrent_mark_init_end() { assert(!collector_state()->initiate_conc_mark_if_possible(), "we should have cleared it by now"); collector_state()->set_in_concurrent_start_gc(false); } @@ -591,7 +591,7 @@ double G1Policy::constant_other_time_ms(double pause_time_ms) const { } bool G1Policy::about_to_start_mixed_phase() const { - return _g1h->concurrent_mark()->cm_thread()->during_cycle() || collector_state()->in_young_gc_before_mixed(); + return _g1h->concurrent_mark()->cm_thread()->in_progress() || collector_state()->in_young_gc_before_mixed(); } bool G1Policy::need_to_start_conc_mark(const char* source, size_t alloc_word_size) { @@ -612,10 +612,14 @@ bool G1Policy::need_to_start_conc_mark(const char* source, size_t alloc_word_siz result ? "Request concurrent cycle initiation (occupancy higher than threshold)" : "Do not request concurrent cycle initiation (still doing mixed collections)", cur_used_bytes, alloc_byte_size, marking_initiating_used_threshold, (double) marking_initiating_used_threshold / _g1h->capacity() * 100, source); } - return result; } +bool G1Policy::concurrent_operation_is_full_mark(const char* msg) { + return collector_state()->in_concurrent_start_gc() && + ((_g1h->gc_cause() != GCCause::_g1_humongous_allocation) || need_to_start_conc_mark(msg)); +} + double G1Policy::logged_cards_processing_time() const { double all_cards_processing_time = average_time_ms(G1GCPhaseTimes::ScanHR) + average_time_ms(G1GCPhaseTimes::OptScanHR); size_t logged_dirty_cards = phase_times()->sum_thread_work_items(G1GCPhaseTimes::MergeLB, G1GCPhaseTimes::MergeLBDirtyCards); @@ -631,18 +635,18 @@ double G1Policy::logged_cards_processing_time() const { // Anything below that is considered to be zero #define MIN_TIMER_GRANULARITY 0.0000001 -void G1Policy::record_collection_pause_end(double pause_time_ms) { +void G1Policy::record_collection_pause_end(double pause_time_ms, bool concurrent_operation_is_full_mark) { G1GCPhaseTimes* p = phase_times(); double end_time_sec = os::elapsedTime(); double start_time_sec = phase_times()->cur_collection_start_sec(); - PauseKind this_pause = young_gc_pause_kind(); + PauseKind this_pause = young_gc_pause_kind(concurrent_operation_is_full_mark); bool update_stats = should_update_gc_stats(); if (is_concurrent_start_pause(this_pause)) { - record_concurrent_mark_init_end(0.0); + record_concurrent_mark_init_end(); } else { maybe_start_marking(); } @@ -781,7 +785,7 @@ void G1Policy::record_collection_pause_end(double pause_time_ms) { assert(!(is_concurrent_start_pause(this_pause) && collector_state()->mark_or_rebuild_in_progress()), "If the last pause has been concurrent start, we should not have been in the marking window"); if (is_concurrent_start_pause(this_pause)) { - collector_state()->set_mark_or_rebuild_in_progress(true); + collector_state()->set_mark_or_rebuild_in_progress(concurrent_operation_is_full_mark); } _free_regions_at_end_of_collection = _g1h->num_free_regions(); @@ -810,7 +814,7 @@ void G1Policy::record_collection_pause_end(double pause_time_ms) { // for completing the marking, i.e. are faster than expected. // This skews the predicted marking length towards smaller values which might cause // the mark start being too late. - _concurrent_start_to_mixed.reset(); + abort_time_to_mixed_tracking(); } // Note that _mmu_tracker->max_gc_time() returns the time in seconds. @@ -1025,7 +1029,7 @@ bool G1Policy::force_concurrent_start_if_outside_cycle(GCCause::Cause gc_cause) // We actually check whether we are marking here and not if we are in a // reclamation phase. This means that we will schedule a concurrent mark // even while we are still in the process of reclaiming memory. - bool during_cycle = _g1h->concurrent_mark()->cm_thread()->during_cycle(); + bool during_cycle = _g1h->concurrent_mark()->cm_thread()->in_progress(); if (!during_cycle) { log_debug(gc, ergo)("Request concurrent cycle initiation (requested by GC cause). " "GC cause: %s", @@ -1156,7 +1160,10 @@ bool G1Policy::is_young_only_pause(PauseKind kind) { assert(kind != FullGC, "must be"); assert(kind != Remark, "must be"); assert(kind != Cleanup, "must be"); - return kind == ConcurrentStartGC || kind == LastYoungGC || kind == YoungOnlyGC; + return kind == ConcurrentStartUndoGC || + kind == ConcurrentStartMarkGC || + kind == LastYoungGC || + kind == YoungOnlyGC; } bool G1Policy::is_mixed_pause(PauseKind kind) { @@ -1171,14 +1178,14 @@ bool G1Policy::is_last_young_pause(PauseKind kind) { } bool G1Policy::is_concurrent_start_pause(PauseKind kind) { - return kind == ConcurrentStartGC; + return kind == ConcurrentStartMarkGC || kind == ConcurrentStartUndoGC; } -G1Policy::PauseKind G1Policy::young_gc_pause_kind() const { +G1Policy::PauseKind G1Policy::young_gc_pause_kind(bool concurrent_operation_is_full_mark) const { assert(!collector_state()->in_full_gc(), "must be"); if (collector_state()->in_concurrent_start_gc()) { assert(!collector_state()->in_young_gc_before_mixed(), "must be"); - return ConcurrentStartGC; + return concurrent_operation_is_full_mark ? ConcurrentStartMarkGC : ConcurrentStartUndoGC; } else if (collector_state()->in_young_gc_before_mixed()) { assert(!collector_state()->in_concurrent_start_gc(), "must be"); return LastYoungGC; @@ -1214,7 +1221,9 @@ void G1Policy::update_gc_pause_time_ratios(PauseKind kind, double start_time_sec } } -void G1Policy::record_pause(PauseKind kind, double start, double end) { +void G1Policy::record_pause(PauseKind kind, + double start, + double end) { // Manage the MMU tracker. For some reason it ignores Full GCs. if (kind != FullGC) { _mmu_tracker->add_pause(start, end); @@ -1224,6 +1233,12 @@ void G1Policy::record_pause(PauseKind kind, double start, double end) { update_gc_pause_time_ratios(kind, start, end); } + update_time_to_mixed_tracking(kind, start, end); +} + +void G1Policy::update_time_to_mixed_tracking(PauseKind kind, + double start, + double end) { // Manage the mutator time tracking from concurrent start to first mixed gc. switch (kind) { case FullGC: @@ -1235,11 +1250,19 @@ void G1Policy::record_pause(PauseKind kind, double start, double end) { case LastYoungGC: _concurrent_start_to_mixed.add_pause(end - start); break; - case ConcurrentStartGC: + case ConcurrentStartMarkGC: + // Do not track time-to-mixed time for periodic collections as they are likely + // to be not representative to regular operation as the mutators are idle at + // that time. Also only track full concurrent mark cycles. if (_g1h->gc_cause() != GCCause::_g1_periodic_collection) { _concurrent_start_to_mixed.record_concurrent_start_end(end); } break; + case ConcurrentStartUndoGC: + assert(_g1h->gc_cause() == GCCause::_g1_humongous_allocation, + "GC cause must be humongous allocation but is %d", + _g1h->gc_cause()); + break; case MixedGC: _concurrent_start_to_mixed.record_mixed_gc_start(start); break; diff --git a/src/hotspot/share/gc/g1/g1Policy.hpp b/src/hotspot/share/gc/g1/g1Policy.hpp index 841ee81e1edc4..6062213e3f82f 100644 --- a/src/hotspot/share/gc/g1/g1Policy.hpp +++ b/src/hotspot/share/gc/g1/g1Policy.hpp @@ -264,12 +264,13 @@ class G1Policy: public CHeapObj { void maybe_start_marking(); // The kind of STW pause. - enum PauseKind { + enum PauseKind : uint { FullGC, YoungOnlyGC, MixedGC, LastYoungGC, - ConcurrentStartGC, + ConcurrentStartMarkGC, + ConcurrentStartUndoGC, Cleanup, Remark }; @@ -279,7 +280,9 @@ class G1Policy: public CHeapObj { static bool is_last_young_pause(PauseKind kind); static bool is_concurrent_start_pause(PauseKind kind); // Calculate PauseKind from internal state. - PauseKind young_gc_pause_kind() const; + PauseKind young_gc_pause_kind(bool concurrent_operation_is_full_mark) const; + // Manage time-to-mixed tracking. + void update_time_to_mixed_tracking(PauseKind pause, double start, double end); // Record the given STW pause with the given start and end times (in s). void record_pause(PauseKind kind, double start, double end); @@ -319,18 +322,20 @@ class G1Policy: public CHeapObj { bool need_to_start_conc_mark(const char* source, size_t alloc_word_size = 0); + bool concurrent_operation_is_full_mark(const char* msg = NULL); + bool about_to_start_mixed_phase() const; // Record the start and end of an evacuation pause. void record_collection_pause_start(double start_time_sec); - virtual void record_collection_pause_end(double pause_time_ms); + virtual void record_collection_pause_end(double pause_time_ms, bool concurrent_operation_is_full_mark); // Record the start and end of a full collection. void record_full_collection_start(); virtual void record_full_collection_end(); // Must currently be called while the world is stopped. - void record_concurrent_mark_init_end(double mark_init_elapsed_time_ms); + void record_concurrent_mark_init_end(); // Record start and end of remark. void record_concurrent_mark_remark_start(); diff --git a/src/hotspot/share/gc/g1/g1ServiceThread.cpp b/src/hotspot/share/gc/g1/g1ServiceThread.cpp index 3450abbcd93b6..0c7f91ab6d727 100644 --- a/src/hotspot/share/gc/g1/g1ServiceThread.cpp +++ b/src/hotspot/share/gc/g1/g1ServiceThread.cpp @@ -59,7 +59,7 @@ void G1ServiceThread::sleep_before_next_cycle() { bool G1ServiceThread::should_start_periodic_gc() { G1CollectedHeap* g1h = G1CollectedHeap::heap(); // If we are currently in a concurrent mark we are going to uncommit memory soon. - if (g1h->concurrent_mark()->cm_thread()->during_cycle()) { + if (g1h->concurrent_mark()->cm_thread()->in_progress()) { log_debug(gc, periodic)("Concurrent cycle in progress. Skipping."); return false; } diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 4022c81132669..e2d12cdf71f45 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -92,7 +92,7 @@ #include "gc/g1/g1Arguments.hpp" #include "gc/g1/g1CollectedHeap.inline.hpp" #include "gc/g1/g1ConcurrentMark.hpp" -#include "gc/g1/g1ConcurrentMarkThread.hpp" +#include "gc/g1/g1ConcurrentMarkThread.inline.hpp" #include "gc/g1/heapRegionRemSet.hpp" #include "gc/g1/heterogeneousHeapRegionManager.hpp" #endif // INCLUDE_G1GC @@ -473,7 +473,7 @@ WB_END WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) if (UseG1GC) { G1CollectedHeap* g1h = G1CollectedHeap::heap(); - return g1h->concurrent_mark()->cm_thread()->during_cycle(); + return g1h->concurrent_mark()->cm_thread()->in_progress(); } THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1InConcurrentMark: G1 GC is not enabled"); WB_END @@ -481,7 +481,7 @@ WB_END WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o)) if (UseG1GC) { G1CollectedHeap* g1h = G1CollectedHeap::heap(); - if (!g1h->concurrent_mark()->cm_thread()->during_cycle()) { + if (!g1h->concurrent_mark()->cm_thread()->in_progress()) { g1h->collect(GCCause::_wb_conc_mark); return true; } diff --git a/test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java b/test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java new file mode 100644 index 0000000000000..56bd25689e3da --- /dev/null +++ b/test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2020, 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. + */ + +package gc.g1; + +/* + * @test TestHumongousConcurrentStartUndo + * @summary Tests an alternating sequence of Concurrent Mark and Concurrent Undo + * cycles. + * reclaim heap occupancy falls below the IHOP value. + * @requires vm.gc.G1 + * @library /test/lib /testlibrary / + * @modules java.base/jdk.internal.misc + * java.management + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. + * gc.g1.TestHumongousConcurrentStartUndo + */ + +import gc.testlibrary.Helpers; + +import sun.hotspot.WhiteBox; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; + +public class TestHumongousConcurrentStartUndo { + // Heap sizes < 224 MB are increased to 224 MB if vm_page_size == 64K to + // fulfill alignment constraints. + private static final int HeapSize = 224; // MB + private static final int HeapRegionSize = 1; // MB + private static final int InitiatingHeapOccupancyPercent = 50; // % + private static final int YoungSize = HeapSize / 8; + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xbootclasspath/a:.", + "-XX:+UseG1GC", + "-Xms" + HeapSize + "m", + "-Xmx" + HeapSize + "m", + "-Xmn" + YoungSize + "m", + "-XX:G1HeapRegionSize=" + HeapRegionSize + "m", + "-XX:InitiatingHeapOccupancyPercent=" + InitiatingHeapOccupancyPercent, + "-XX:-G1UseAdaptiveIHOP", + "-XX:+UnlockDiagnosticVMOptions", + "-XX:+WhiteBoxAPI", + "-Xlog:gc*", + EdenObjectAllocatorWithHumongousAllocation.class.getName()); + + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("Pause Young (Concurrent Start) (G1 Humongous Allocation)"); + output.shouldContain("Concurrent Undo Cycle"); + output.shouldContain("Concurrent Mark Cycle"); + output.shouldHaveExitValue(0); + System.out.println(output.getStdout()); + } + + static class EdenObjectAllocatorWithHumongousAllocation { + private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); + + private static void allocateHumongous(int num, int objSize, Queue keeper) { + for (int i = 1; i <= num; i++) { + if (i % 10 == 0) { + System.out.println("Allocating humongous object " + i + "/" + num + + " of size " + objSize + " bytes"); + } + byte[] e = new byte[objSize]; + if (!keeper.offer(e)) { + keeper.remove(); + keeper.offer(e); + } + } + } + + public static void main(String [] args) throws Exception { + final int M = 1024 * 1024; + // Make humongous object size 75% of region size + final int humongousObjectSize = + (int)(HeapRegionSize * M * 0.75); + + // Number of objects to allocate to go above IHOP + final int humongousObjectAllocations = + (int)(((HeapSize - YoungSize) * 80 / 100.0) / HeapRegionSize); + + ArrayBlockingQueue a; + for (int iterate = 0; iterate < 3; iterate++) { + WHITE_BOX.fullGC(); + + a = new ArrayBlockingQueue(1); + allocateHumongous(humongousObjectAllocations, humongousObjectSize, a); + Helpers.waitTillCMCFinished(WHITE_BOX, 1); + a = null; + + a = new ArrayBlockingQueue(humongousObjectAllocations); + allocateHumongous(humongousObjectAllocations, humongousObjectSize, a); + Helpers.waitTillCMCFinished(WHITE_BOX, 1); + a = null; + + allocateHumongous(1, humongousObjectSize, new ArrayBlockingQueue(1)); + Helpers.waitTillCMCFinished(WHITE_BOX, 1); + } + } + } +} + diff --git a/test/hotspot/jtreg/gc/stress/jfr/TestStressBigAllocationGCEventsWithG1.java b/test/hotspot/jtreg/gc/stress/jfr/TestStressBigAllocationGCEventsWithG1.java deleted file mode 100644 index a271adba13b03..0000000000000 --- a/test/hotspot/jtreg/gc/stress/jfr/TestStressBigAllocationGCEventsWithG1.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package jdk.jfr.event.gc.detailed; - -/** - * @test - * @key randomness - * @summary Test allocates humongous objects with G1 GC. Objects - * considered humongous when it allocates equals or more than one region. As - * we're passing the size of byte array we need adjust it that entire structure - * fits exactly to one region, if not - G1 will allocate another almost empty - * region as a continue of humongous. Thus we will exhaust memory very fast and - * test will fail with OOME. - * @requires vm.hasJFR - * @requires vm.gc == "null" | vm.gc == "G1" - * @library /test/lib /test/jdk - * @run main/othervm -XX:+UseG1GC -XX:MaxNewSize=5m -Xmx256m -XX:G1HeapRegionSize=1048576 jdk.jfr.event.gc.detailed.TestStressBigAllocationGCEventsWithG1 1048544 - */ -public class TestStressBigAllocationGCEventsWithG1 { - - public static void main(String[] args) throws Exception { - new StressAllocationGCEvents().run(args); - } -} From cfa3f7493149170f2b23a516bc95110dab43fd06 Mon Sep 17 00:00:00 2001 From: Alexey Bakhtin Date: Fri, 25 Sep 2020 07:26:54 +0000 Subject: [PATCH 12/79] 8245527: LDAP Channel Binding support for Java GSS/Kerberos Reviewed-by: dfuchs, aefimov, mullan --- .../classes/com/sun/jndi/ldap/Connection.java | 62 +++++- .../com/sun/jndi/ldap/sasl/LdapSasl.java | 32 ++- .../sun/jndi/ldap/sasl/TlsChannelBinding.java | 146 +++++++++++++ .../share/classes/module-info.java | 14 ++ .../share/classes/module-info.java | 2 + .../sun/security/jgss/krb5/InitialToken.java | 20 +- .../krb5/internal/TlsChannelBindingImpl.java | 37 ++++ .../share/native/libj2gss/GSSLibStub.c | 35 +++- .../security/sasl/gsskerb/GssKrb5Client.java | 11 + .../sun/jndi/ldap/LdapCBPropertiesTest.java | 196 ++++++++++++++++++ 10 files changed, 543 insertions(+), 12 deletions(-) create mode 100644 src/java.naming/share/classes/com/sun/jndi/ldap/sasl/TlsChannelBinding.java create mode 100644 src/java.security.jgss/share/classes/sun/security/jgss/krb5/internal/TlsChannelBindingImpl.java create mode 100644 test/jdk/com/sun/jndi/ldap/LdapCBPropertiesTest.java diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java b/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java index b4c956946f5ba..6d0580c96de13 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java @@ -46,9 +46,17 @@ import java.lang.reflect.InvocationTargetException; import java.security.AccessController; import java.security.PrivilegedAction; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; import java.util.Arrays; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import javax.net.SocketFactory; import javax.net.ssl.SSLParameters; +import javax.net.ssl.HandshakeCompletedEvent; +import javax.net.ssl.HandshakeCompletedListener; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.security.sasl.SaslException; /** * A thread that creates a connection to an LDAP server. @@ -109,7 +117,7 @@ * @author Rosanna Lee * @author Jagane Sundar */ -public final class Connection implements Runnable { +public final class Connection implements Runnable, HandshakeCompletedListener { private static final boolean debug = false; private static final int dump = 0; // > 0 r, > 1 rw @@ -342,6 +350,7 @@ private Socket createSocket(String host, int port, String socketFactory, param.setEndpointIdentificationAlgorithm("LDAPS"); sslSocket.setSSLParameters(param); } + sslSocket.addHandshakeCompletedListener(this); if (connectTimeout > 0) { int socketTimeout = sslSocket.getSoTimeout(); sslSocket.setSoTimeout(connectTimeout); // reuse full timeout value @@ -637,6 +646,15 @@ void cleanup(Control[] reqCtls, boolean notifyParent) { ldr = ldr.next; } } + if (isTlsConnection()) { + if (closureReason != null) { + CommunicationException ce = new CommunicationException(); + ce.setRootCause(closureReason); + tlsHandshakeCompleted.completeExceptionally(ce); + } else { + tlsHandshakeCompleted.cancel(false); + } + } sock = null; } nparent = notifyParent; @@ -972,4 +990,46 @@ private static byte[] readFully(InputStream is, int length) } return buf; } + + private final CompletableFuture tlsHandshakeCompleted = + new CompletableFuture<>(); + + @Override + public void handshakeCompleted(HandshakeCompletedEvent event) { + try { + X509Certificate tlsServerCert = null; + Certificate[] certs; + if (event.getSocket().getUseClientMode()) { + certs = event.getPeerCertificates(); + } else { + certs = event.getLocalCertificates(); + } + if (certs != null && certs.length > 0 && + certs[0] instanceof X509Certificate) { + tlsServerCert = (X509Certificate) certs[0]; + } + tlsHandshakeCompleted.complete(tlsServerCert); + } catch (SSLPeerUnverifiedException ex) { + CommunicationException ce = new CommunicationException(); + ce.setRootCause(closureReason); + tlsHandshakeCompleted.completeExceptionally(ex); + } + } + + public boolean isTlsConnection() { + return sock instanceof SSLSocket; + } + + public X509Certificate getTlsServerCertificate() + throws SaslException { + try { + if (isTlsConnection()) + return tlsHandshakeCompleted.get(); + } catch (InterruptedException iex) { + throw new SaslException("TLS Handshake Exception ", iex); + } catch (ExecutionException eex) { + throw new SaslException("TLS Handshake Exception ", eex.getCause()); + } + return null; + } } diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java b/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java index ee85dd7bf6617..ce44770d3599b 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java @@ -26,6 +26,7 @@ package com.sun.jndi.ldap.sasl; import java.io.*; +import java.security.cert.X509Certificate; import java.util.Vector; import java.util.Hashtable; import java.util.StringTokenizer; @@ -41,6 +42,7 @@ import com.sun.jndi.ldap.Connection; import com.sun.jndi.ldap.LdapClient; import com.sun.jndi.ldap.LdapResult; +import com.sun.jndi.ldap.sasl.TlsChannelBinding.TlsChannelBindingType; /** * Handles SASL support. @@ -110,10 +112,38 @@ public static LdapResult saslBind(LdapClient clnt, Connection conn, String authzId = (env != null) ? (String)env.get(SASL_AUTHZ_ID) : null; String[] mechs = getSaslMechanismNames(authMech); + // Internal TLS Channel Binding property cannot be set explicitly + if (env.get(TlsChannelBinding.CHANNEL_BINDING) != null) { + throw new NamingException(TlsChannelBinding.CHANNEL_BINDING + + " property cannot be set explicitly"); + } + + Hashtable envProps = (Hashtable) env; + try { + // Prepare TLS Channel Binding data + if (conn.isTlsConnection()) { + TlsChannelBindingType cbType = + TlsChannelBinding.parseType( + (String)env.get(TlsChannelBinding.CHANNEL_BINDING_TYPE)); + if (cbType == TlsChannelBindingType.TLS_SERVER_END_POINT) { + // set tls-server-end-point channel binding + X509Certificate cert = conn.getTlsServerCertificate(); + if (cert != null) { + TlsChannelBinding tlsCB = + TlsChannelBinding.create(cert); + envProps = (Hashtable) env.clone(); + envProps.put(TlsChannelBinding.CHANNEL_BINDING, tlsCB.getData()); + } else { + throw new SaslException("No suitable certificate to generate " + + "TLS Channel Binding data"); + } + } + } + // Create SASL client to use using SASL package saslClnt = Sasl.createSaslClient( - mechs, authzId, "ldap", server, (Hashtable)env, cbh); + mechs, authzId, "ldap", server, envProps, cbh); if (saslClnt == null) { throw new AuthenticationNotSupportedException(authMech); diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/TlsChannelBinding.java b/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/TlsChannelBinding.java new file mode 100644 index 0000000000000..36f6c98982227 --- /dev/null +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/sasl/TlsChannelBinding.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2020, Azul Systems, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.jndi.ldap.sasl; + +import javax.naming.NamingException; +import javax.security.sasl.SaslException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateEncodingException; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.Hashtable; + +/** + * This class implements the Channel Binding for TLS as defined in + * + * Channel Bindings for TLS + * + * Format of the Channel Binding data is also defined in + * + * On the Use of Channel Bindings to Secure Channels + * section 2.1. + * + */ + +public class TlsChannelBinding { + + // TLS channel binding type property + public static final String CHANNEL_BINDING_TYPE = + "com.sun.jndi.ldap.tls.cbtype"; + + // internal TLS channel binding property + public static final String CHANNEL_BINDING = + "jdk.internal.sasl.tlschannelbinding"; + + public enum TlsChannelBindingType { + + /** + * Channel binding on the basis of TLS Finished message. + * TLS_UNIQUE is defined by RFC 5929 but is not supported + * by the current LDAP stack. + */ + TLS_UNIQUE("tls-unique"), + + /** + * Channel binding on the basis of TLS server certificate. + */ + TLS_SERVER_END_POINT("tls-server-end-point"); + + public String getName() { + return name; + } + + final private String name; + TlsChannelBindingType(String name) { + this.name = name; + } + } + + /** + * Parse value of "com.sun.jndi.ldap.tls.cbtype" property + * @param cbType + * @return TLS Channel Binding type or null if + * "com.sun.jndi.ldap.tls.cbtype" property has not been set. + * @throws NamingException + */ + public static TlsChannelBindingType parseType(String cbType) throws NamingException { + if (cbType != null) { + if (cbType.equals(TlsChannelBindingType.TLS_SERVER_END_POINT.getName())) { + return TlsChannelBindingType.TLS_SERVER_END_POINT; + } else { + throw new NamingException("Illegal value for " + + CHANNEL_BINDING_TYPE + " property."); + } + } + return null; + } + + final private TlsChannelBindingType cbType; + final private byte[] cbData; + + /** + * Construct tls-server-end-point Channel Binding data + * @param serverCertificate + * @throws SaslException + */ + public static TlsChannelBinding create(X509Certificate serverCertificate) throws SaslException { + try { + final byte[] prefix = + TlsChannelBindingType.TLS_SERVER_END_POINT.getName().concat(":").getBytes(); + String hashAlg = serverCertificate.getSigAlgName(). + replace("SHA", "SHA-").toUpperCase(); + int ind = hashAlg.indexOf("WITH"); + if (ind > 0) { + hashAlg = hashAlg.substring(0, ind); + if (hashAlg.equals("MD5") || hashAlg.equals("SHA-1")) { + hashAlg = "SHA-256"; + } + } else { + hashAlg = "SHA-256"; + } + MessageDigest md = MessageDigest.getInstance(hashAlg); + byte[] hash = md.digest(serverCertificate.getEncoded()); + byte[] cbData = Arrays.copyOf(prefix, prefix.length + hash.length ); + System.arraycopy(hash, 0, cbData, prefix.length, hash.length); + return new TlsChannelBinding(TlsChannelBindingType.TLS_SERVER_END_POINT, cbData); + } catch (NoSuchAlgorithmException | CertificateEncodingException e) { + throw new SaslException("Cannot create TLS channel binding data", e); + } + } + + private TlsChannelBinding(TlsChannelBindingType cbType, byte[] cbData) { + this.cbType = cbType; + this.cbData = cbData; + } + + public TlsChannelBindingType getType() { + return cbType; + } + + public byte[] getData() { + return cbData; + } +} diff --git a/src/java.naming/share/classes/module-info.java b/src/java.naming/share/classes/module-info.java index f56a5dff43802..4b89b55d3a330 100644 --- a/src/java.naming/share/classes/module-info.java +++ b/src/java.naming/share/classes/module-info.java @@ -59,6 +59,20 @@ *
If this property is not specified, the default is to wait * for the response until it is received. * + *
  • {@code com.sun.jndi.ldap.tls.cbtype}: + *
    The value of this property is the string representing the TLS + * Channel Binding type required for an LDAP connection over SSL/TLS. + * Possible value is : + *
      + *
    • "tls-server-end-point" - Channel Binding data is created on + * the basis of the TLS server certificate. + *
    • + *
    + *
    "tls-unique" TLS Channel Binding type is specified in RFC-5929 + * but not supported. + *
    If this property is not specified, the client does not send + * channel binding information to the server. + *
  • * * * @provides javax.naming.ldap.spi.LdapDnsProvider diff --git a/src/java.security.jgss/share/classes/module-info.java b/src/java.security.jgss/share/classes/module-info.java index 3b59cfe96d8b6..d9ad7ad4919ed 100644 --- a/src/java.security.jgss/share/classes/module-info.java +++ b/src/java.security.jgss/share/classes/module-info.java @@ -41,6 +41,8 @@ jdk.security.jgss; exports sun.security.jgss.krb5 to jdk.security.auth; + exports sun.security.jgss.krb5.internal to + jdk.security.jgss; exports sun.security.krb5 to jdk.security.auth; exports sun.security.krb5.internal to diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/InitialToken.java b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/InitialToken.java index e5b66bed48ddc..f491aecfe2faa 100644 --- a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/InitialToken.java +++ b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/InitialToken.java @@ -36,6 +36,7 @@ import java.util.Arrays; import sun.security.krb5.*; import sun.security.krb5.internal.Krb5; +import sun.security.jgss.krb5.internal.TlsChannelBindingImpl; abstract class InitialToken extends Krb5Token { @@ -57,6 +58,7 @@ abstract class InitialToken extends Krb5Token { private final byte[] CHECKSUM_FIRST_BYTES = {(byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00}; + private static final int CHANNEL_BINDING_AF_UNSPEC = 0; private static final int CHANNEL_BINDING_AF_INET = 2; private static final int CHANNEL_BINDING_AF_INET6 = 24; private static final int CHANNEL_BINDING_AF_NULL_ADDR = 255; @@ -333,8 +335,8 @@ public void setContextFlags(Krb5Context context) { } } - private int getAddrType(InetAddress addr) { - int addressType = CHANNEL_BINDING_AF_NULL_ADDR; + private int getAddrType(InetAddress addr, int defValue) { + int addressType = defValue; if (addr instanceof Inet4Address) addressType = CHANNEL_BINDING_AF_INET; @@ -344,7 +346,7 @@ else if (addr instanceof Inet6Address) } private byte[] getAddrBytes(InetAddress addr) throws GSSException { - int addressType = getAddrType(addr); + int addressType = getAddrType(addr, CHANNEL_BINDING_AF_NULL_ADDR); byte[] addressBytes = addr.getAddress(); if (addressBytes != null) { switch (addressType) { @@ -375,8 +377,16 @@ private byte[] computeChannelBinding(ChannelBinding channelBinding) InetAddress acceptorAddress = channelBinding.getAcceptorAddress(); int size = 5*4; - int initiatorAddressType = getAddrType(initiatorAddress); - int acceptorAddressType = getAddrType(acceptorAddress); + // LDAP TLS Channel Binding requires CHANNEL_BINDING_AF_UNSPEC address type + // for unspecified initiator and acceptor addresses. + // CHANNEL_BINDING_AF_NULL_ADDR value should be used for unspecified address + // in all other cases. + int initiatorAddressType = getAddrType(initiatorAddress, + (channelBinding instanceof TlsChannelBindingImpl) ? + CHANNEL_BINDING_AF_UNSPEC : CHANNEL_BINDING_AF_NULL_ADDR); + int acceptorAddressType = getAddrType(acceptorAddress, + (channelBinding instanceof TlsChannelBindingImpl) ? + CHANNEL_BINDING_AF_UNSPEC : CHANNEL_BINDING_AF_NULL_ADDR); byte[] initiatorAddressBytes = null; if (initiatorAddress != null) { diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/krb5/internal/TlsChannelBindingImpl.java b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/internal/TlsChannelBindingImpl.java new file mode 100644 index 0000000000000..e1da3acbc7c8e --- /dev/null +++ b/src/java.security.jgss/share/classes/sun/security/jgss/krb5/internal/TlsChannelBindingImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020, Azul Systems, Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package sun.security.jgss.krb5.internal; + +import org.ietf.jgss.ChannelBinding; + +/** + * TLS Channel Binding wrapper class to determine internal + * tls channel binding implementation. + */ +public class TlsChannelBindingImpl extends ChannelBinding { + public TlsChannelBindingImpl(byte[] appData) { + super(appData); + } +} diff --git a/src/java.security.jgss/share/native/libj2gss/GSSLibStub.c b/src/java.security.jgss/share/native/libj2gss/GSSLibStub.c index 68938249848f7..d6e1712a24fb6 100644 --- a/src/java.security.jgss/share/native/libj2gss/GSSLibStub.c +++ b/src/java.security.jgss/share/native/libj2gss/GSSLibStub.c @@ -34,6 +34,8 @@ const int TYPE_CRED_NAME = 10; const int TYPE_CRED_TIME = 11; const int TYPE_CRED_USAGE = 12; +static jclass tlsCBCl = NULL; + /* * Class: sun_security_jgss_wrapper_GSSLibStub * Method: init @@ -69,6 +71,17 @@ Java_sun_security_jgss_wrapper_GSSLibStub_init(JNIEnv *env, failed = loadNative(libName); (*env)->ReleaseStringUTFChars(env, jlibName, libName); + if (tlsCBCl == NULL) { + + /* initialize TLS Channel Binding class wrapper */ + jclass cl = (*env)->FindClass(env, + "sun/security/jgss/krb5/internal/TlsChannelBindingImpl"); + if (cl == NULL) { /* exception thrown */ + return JNI_FALSE; + } + tlsCBCl = (*env)->NewGlobalRef(env, cl); + } + if (!failed) { return JNI_TRUE; } else { @@ -154,11 +167,13 @@ void deleteGSSCB(gss_channel_bindings_t cb) { if (cb == GSS_C_NO_CHANNEL_BINDINGS) return; /* release initiator address */ - if (cb->initiator_addrtype != GSS_C_AF_NULLADDR) { + if (cb->initiator_addrtype != GSS_C_AF_NULLADDR && + cb->initiator_addrtype != GSS_C_AF_UNSPEC) { resetGSSBuffer(&(cb->initiator_address)); } /* release acceptor address */ - if (cb->acceptor_addrtype != GSS_C_AF_NULLADDR) { + if (cb->acceptor_addrtype != GSS_C_AF_NULLADDR && + cb->acceptor_addrtype != GSS_C_AF_UNSPEC) { resetGSSBuffer(&(cb->acceptor_address)); } /* release application data */ @@ -189,9 +204,19 @@ gss_channel_bindings_t newGSSCB(JNIEnv *env, jobject jcb) { } // initialize addrtype in CB first - cb->initiator_addrtype = GSS_C_AF_NULLADDR; - cb->acceptor_addrtype = GSS_C_AF_NULLADDR; - + // LDAP TLS Channel Binding requires GSS_C_AF_UNSPEC address type + // for unspecified initiator and acceptor addresses. + // GSS_C_AF_NULLADDR value should be used for unspecified address + // in all other cases. + + if ((*env)->IsInstanceOf(env, jcb, tlsCBCl)) { + // TLS Channel Binding requires unspecified addrtype=0 + cb->initiator_addrtype = GSS_C_AF_UNSPEC; + cb->acceptor_addrtype = GSS_C_AF_UNSPEC; + } else { + cb->initiator_addrtype = GSS_C_AF_NULLADDR; + cb->acceptor_addrtype = GSS_C_AF_NULLADDR; + } // addresses needs to be initialized to empty memset(&cb->initiator_address, 0, sizeof(cb->initiator_address)); memset(&cb->acceptor_address, 0, sizeof(cb->acceptor_address)); diff --git a/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java b/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java index 8534e242f0027..4d1b57d14cd8c 100644 --- a/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java +++ b/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/GssKrb5Client.java @@ -35,6 +35,7 @@ import javax.security.auth.callback.CallbackHandler; // JGSS +import sun.security.jgss.krb5.internal.TlsChannelBindingImpl; import org.ietf.jgss.*; /** @@ -150,6 +151,16 @@ final class GssKrb5Client extends GssKrb5Base implements SaslClient { } secCtx.requestMutualAuth(mutual); + if (props != null) { + // TLS Channel Binding + // Property name is defined in the TLSChannelBinding class of + // the java.naming module + byte[] tlsCB = (byte[])props.get("jdk.internal.sasl.tlschannelbinding"); + if (tlsCB != null) { + secCtx.setChannelBinding(new TlsChannelBindingImpl(tlsCB)); + } + } + // Always specify potential need for integrity and confidentiality // Decision will be made during final handshake secCtx.requestConf(true); diff --git a/test/jdk/com/sun/jndi/ldap/LdapCBPropertiesTest.java b/test/jdk/com/sun/jndi/ldap/LdapCBPropertiesTest.java new file mode 100644 index 0000000000000..16b4400310a2d --- /dev/null +++ b/test/jdk/com/sun/jndi/ldap/LdapCBPropertiesTest.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2020, Azul Systems, Inc. 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 8245527 + * @library lib/ /test/lib + * @run main/othervm LdapCBPropertiesTest true true com.sun.jndi.ldap.tls.cbtype tls-server-end-point + * @run main/othervm LdapCBPropertiesTest false false com.sun.jndi.ldap.tls.cbtype tls-server-end-point + * @run main/othervm LdapCBPropertiesTest true true com.sun.jndi.ldap.tls.cbtype tls-server-end-point com.sun.jndi.ldap.connect.timeout 2000 + * @run main/othervm LdapCBPropertiesTest false false com.sun.jndi.ldap.tls.cbtype tls-server-end-point com.sun.jndi.ldap.connect.timeout 2000 + * @run main/othervm LdapCBPropertiesTest false true com.sun.jndi.ldap.tls.cbtype tls-unknown + * @run main/othervm LdapCBPropertiesTest false true jdk.internal.sasl.tlschannelbinding value + * @summary test new JNDI property to control the Channel Binding data + */ + +import javax.naming.AuthenticationException; +import javax.naming.CommunicationException; +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.directory.DirContext; +import javax.naming.directory.InitialDirContext; +import java.net.InetAddress; +import java.net.URI; +import java.util.Hashtable; + +import org.ietf.jgss.GSSException; + +import javax.net.ssl.SSLException; +import javax.net.ssl.SSLServerSocket; +import javax.net.ssl.SSLServerSocketFactory; +import javax.security.sasl.SaslException; + +import jdk.test.lib.net.URIBuilder; + +public class LdapCBPropertiesTest { + /* + * Where do we find the keystores? + */ + static String pathToStores = "../../../../javax/net/ssl/etc"; + static String keyStoreFile = "keystore"; + static String trustStoreFile = "truststore"; + static String passwd = "passphrase"; + + static boolean debug = false; + + public static void main(String[] args) throws Exception { + String keyFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + keyStoreFile; + String trustFilename = + System.getProperty("test.src", "./") + "/" + pathToStores + + "/" + trustStoreFile; + + System.setProperty("javax.net.ssl.keyStore", keyFilename); + System.setProperty("javax.net.ssl.keyStorePassword", passwd); + System.setProperty("javax.net.ssl.trustStore", trustFilename); + System.setProperty("javax.net.ssl.trustStorePassword", passwd); + + if (debug) + System.setProperty("javax.net.debug", "all"); + + /* + * Start the tests. + */ + new LdapCBPropertiesTest(args); + } + + /* + * Primary constructor, used to drive remainder of the test. + */ + LdapCBPropertiesTest(String[] args) throws Exception { + InetAddress loopback = InetAddress.getLoopbackAddress(); + SSLServerSocketFactory sslssf = + (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); + SSLServerSocket sslServerSocket = + (SSLServerSocket) sslssf.createServerSocket(0, 0, loopback); + int serverPort = sslServerSocket.getLocalPort(); + + try (var ignore = new BaseLdapServer(sslServerSocket).start()) { + doClientSide(serverPort, args); + } + } + + /* + * Define the client side of the test. + * + * The server should start at this time already + */ + void doClientSide(int serverPort, String[] args) throws Exception { + boolean passed = false; + boolean shouldPass = Boolean.parseBoolean(args[0]); + boolean shouldConnect = Boolean.parseBoolean(args[1]); + // set disableEndpointIdentification to disable hostname verification + if (shouldConnect) { + System.setProperty( + "com.sun.jndi.ldap.object.disableEndpointIdentification", "true"); + } + + // Set up the environment for creating the initial context + Hashtable env = new Hashtable(); + URI uri = URIBuilder.newBuilder() + .scheme("ldaps") + .loopback() + .port(serverPort) + .build(); + env.put(Context.PROVIDER_URL, uri.toString()); + env.put(Context.INITIAL_CONTEXT_FACTORY, + "com.sun.jndi.ldap.LdapCtxFactory"); + env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI"); + + // read properties + for (int i = 2; i < args.length; i += 2) { + env.put(args[i], args[i + 1]); + if (debug) + System.out.println("Env=" + args[i] + "=" + args[i + 1]); + } + + try { + DirContext ctx = new InitialDirContext(env); + passed = shouldPass; + ctx.close(); + } catch (NamingException ne) { + // only NamingException is allowed + if (debug) + System.out.println("Exception=" + ne + " cause=" + ne.getRootCause()); + passed = handleNamingException(ne, shouldPass, shouldConnect); + } catch(Exception e) { + System.err.println("Failed: caught an unexpected Exception - " + e); + throw e; + } finally { + // test if internal property accessible to application + if(shouldPass && + env.get("jdk.internal.sasl.tlschannelbinding") != null) { + throw new Exception( + "Test FAILED: jdk.internal.sasl.tlschannelbinding should not be accessible"); + } + } + if (!passed) { + throw new Exception( + "Test FAILED: NamingException exception should be thrown"); + } + System.out.println("Test PASSED"); + } + + private static boolean handleNamingException(NamingException ne, boolean shouldPass, boolean shouldConnect) + throws NamingException { + if (ne instanceof AuthenticationException && + ne.getRootCause() instanceof SaslException) { + SaslException saslEx = (SaslException) ne.getRootCause(); + if (shouldConnect && saslEx.getCause() instanceof GSSException) { + // SSL connection successful, expected exception from SaslClient + if (shouldPass) + return true; + } + } + if (!shouldConnect) { + // SSL handshake fails + Exception ex = ne; + while(ex != null && !(ex instanceof CommunicationException)) { + ex = (Exception)ex.getCause(); + } + if (ex != null) { + if (ex.getCause() instanceof SSLException) { + if (!shouldPass) + return true; + } + } + } + if (!shouldPass && ne.getRootCause() == null) { + // Expected exception caused by Channel Binding parameter inconsistency + return true; + } + throw ne; + } +} From e12d94af0ba64389ed466c34c0c1d1a7e6a2093c Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 25 Sep 2020 09:12:38 +0000 Subject: [PATCH 13/79] 8253594: Remove CollectedHeap::supports_tlab_allocation Reviewed-by: sjohanss, pliden --- src/hotspot/share/gc/epsilon/epsilonHeap.hpp | 1 - src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 4 ---- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 1 - .../gc/parallel/parallelScavengeHeap.hpp | 2 -- src/hotspot/share/gc/shared/collectedHeap.hpp | 7 ------ .../share/gc/shared/genCollectedHeap.cpp | 23 +++++-------------- .../share/gc/shared/genCollectedHeap.hpp | 1 - .../share/gc/shenandoah/shenandoahHeap.hpp | 3 --- src/hotspot/share/gc/z/zCollectedHeap.cpp | 4 ---- src/hotspot/share/gc/z/zCollectedHeap.hpp | 1 - src/hotspot/share/memory/universe.cpp | 2 -- 11 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/hotspot/share/gc/epsilon/epsilonHeap.hpp b/src/hotspot/share/gc/epsilon/epsilonHeap.hpp index f08c67a3c89d9..2d90439a1eeba 100644 --- a/src/hotspot/share/gc/epsilon/epsilonHeap.hpp +++ b/src/hotspot/share/gc/epsilon/epsilonHeap.hpp @@ -95,7 +95,6 @@ class EpsilonHeap : public CollectedHeap { size_t* actual_size); // TLAB allocation - virtual bool supports_tlab_allocation() const { return true; } virtual size_t tlab_capacity(Thread* thr) const { return capacity(); } virtual size_t tlab_used(Thread* thr) const { return used(); } virtual size_t max_tlab_size() const { return _max_tlab_size; } diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index b57ee35d9e6ef..14c534527886f 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -2369,10 +2369,6 @@ bool G1CollectedHeap::block_is_obj(const HeapWord* addr) const { return hr->block_is_obj(addr); } -bool G1CollectedHeap::supports_tlab_allocation() const { - return true; -} - size_t G1CollectedHeap::tlab_capacity(Thread* ignored) const { return (_policy->young_list_target_length() - _survivor.length()) * HeapRegion::GrainBytes; } diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 509d65bfa53aa..94b1b2b97189c 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -1252,7 +1252,6 @@ class G1CollectedHeap : public CollectedHeap { // Section on thread-local allocation buffers (TLABs) // See CollectedHeap for semantics. - bool supports_tlab_allocation() const; size_t tlab_capacity(Thread* ignored) const; size_t tlab_used(Thread* ignored) const; size_t max_tlab_size() const; diff --git a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp index 64da505ec23aa..ed72efea86669 100644 --- a/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp +++ b/src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp @@ -202,8 +202,6 @@ class ParallelScavengeHeap : public CollectedHeap { void ensure_parsability(bool retire_tlabs); void resize_all_tlabs(); - bool supports_tlab_allocation() const { return true; } - size_t tlab_capacity(Thread* thr) const; size_t tlab_used(Thread* thr) const; size_t unsafe_max_tlab_alloc(Thread* thr) const; diff --git a/src/hotspot/share/gc/shared/collectedHeap.hpp b/src/hotspot/share/gc/shared/collectedHeap.hpp index e8d7d74c7a648..9fed67ed33a6f 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.hpp +++ b/src/hotspot/share/gc/shared/collectedHeap.hpp @@ -353,13 +353,6 @@ class CollectedHeap : public CHeapObj { // allocation from them and necessitating allocation of new TLABs. virtual void ensure_parsability(bool retire_tlabs); - // Section on thread-local allocation buffers (TLABs) - // If the heap supports thread-local allocation buffers, it should override - // the following methods: - // Returns "true" iff the heap supports thread-local allocation buffers. - // The default is "no". - virtual bool supports_tlab_allocation() const = 0; - // The amount of space available for thread-local allocation buffers. virtual size_t tlab_capacity(Thread *thr) const = 0; diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.cpp b/src/hotspot/share/gc/shared/genCollectedHeap.cpp index 606baff119832..48c7060a10f6c 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp @@ -1029,33 +1029,22 @@ bool GenCollectedHeap::block_is_obj(const HeapWord* addr) const { return _old_gen->block_is_obj(addr); } -bool GenCollectedHeap::supports_tlab_allocation() const { - assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!"); - return _young_gen->supports_tlab_allocation(); -} - size_t GenCollectedHeap::tlab_capacity(Thread* thr) const { assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!"); - if (_young_gen->supports_tlab_allocation()) { - return _young_gen->tlab_capacity(); - } - return 0; + assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!"); + return _young_gen->tlab_capacity(); } size_t GenCollectedHeap::tlab_used(Thread* thr) const { assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!"); - if (_young_gen->supports_tlab_allocation()) { - return _young_gen->tlab_used(); - } - return 0; + assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!"); + return _young_gen->tlab_used(); } size_t GenCollectedHeap::unsafe_max_tlab_alloc(Thread* thr) const { assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!"); - if (_young_gen->supports_tlab_allocation()) { - return _young_gen->unsafe_max_tlab_alloc(); - } - return 0; + assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!"); + return _young_gen->unsafe_max_tlab_alloc(); } HeapWord* GenCollectedHeap::allocate_new_tlab(size_t min_size, diff --git a/src/hotspot/share/gc/shared/genCollectedHeap.hpp b/src/hotspot/share/gc/shared/genCollectedHeap.hpp index 357816b44aeed..da88474a0fa7b 100644 --- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp +++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp @@ -266,7 +266,6 @@ class GenCollectedHeap : public CollectedHeap { bool block_is_obj(const HeapWord* addr) const; // Section on TLAB's. - virtual bool supports_tlab_allocation() const; virtual size_t tlab_capacity(Thread* thr) const; virtual size_t tlab_used(Thread* thr) const; virtual size_t unsafe_max_tlab_alloc(Thread* thr) const; diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp index 923346e0a537f..c20aa63fb2bdc 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp @@ -606,9 +606,6 @@ class ShenandoahHeap : public CollectedHeap { void notify_mutator_alloc_words(size_t words, bool waste); - // Shenandoah supports TLAB allocation - bool supports_tlab_allocation() const { return true; } - HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size); size_t tlab_capacity(Thread *thr) const; size_t unsafe_max_tlab_alloc(Thread *thread) const; diff --git a/src/hotspot/share/gc/z/zCollectedHeap.cpp b/src/hotspot/share/gc/z/zCollectedHeap.cpp index 188ed69e5dac4..59d6bf66da8fc 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.cpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp @@ -205,10 +205,6 @@ void ZCollectedHeap::do_full_collection(bool clear_all_soft_refs) { ShouldNotReachHere(); } -bool ZCollectedHeap::supports_tlab_allocation() const { - return true; -} - size_t ZCollectedHeap::tlab_capacity(Thread* ignored) const { return _heap.tlab_capacity(); } diff --git a/src/hotspot/share/gc/z/zCollectedHeap.hpp b/src/hotspot/share/gc/z/zCollectedHeap.hpp index 9d28fe4f68f9e..0b00c51d3ea67 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.hpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp @@ -83,7 +83,6 @@ class ZCollectedHeap : public CollectedHeap { virtual void collect_as_vm_thread(GCCause::Cause cause); virtual void do_full_collection(bool clear_all_soft_refs); - virtual bool supports_tlab_allocation() const; virtual size_t tlab_capacity(Thread* thr) const; virtual size_t tlab_used(Thread* thr) const; virtual size_t max_tlab_size() const; diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index a96b1f631d3e9..6d7ac04554ff7 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -806,8 +806,6 @@ jint Universe::initialize_heap() { void Universe::initialize_tlab() { ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size()); if (UseTLAB) { - assert(Universe::heap()->supports_tlab_allocation(), - "Should support thread-local allocation buffers"); ThreadLocalAllocBuffer::startup_initialization(); } } From 27d0a70b3426d20b2fbcc0720c4fa3789a225eea Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 25 Sep 2020 10:09:27 +0000 Subject: [PATCH 14/79] 8253633: Remove unimplemented TieredThresholdPolicy::set_carry_if_neccessary Reviewed-by: thartmann --- src/hotspot/share/compiler/tieredThresholdPolicy.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hotspot/share/compiler/tieredThresholdPolicy.hpp b/src/hotspot/share/compiler/tieredThresholdPolicy.hpp index 2c909bf4d7bcc..3074ba9da4637 100644 --- a/src/hotspot/share/compiler/tieredThresholdPolicy.hpp +++ b/src/hotspot/share/compiler/tieredThresholdPolicy.hpp @@ -166,8 +166,6 @@ class TieredThresholdPolicy : public CompilationPolicy { jlong _start_time; int _c1_count, _c2_count; - // Check if the counter is big enough and set carry (effectively infinity). - inline void set_carry_if_necessary(InvocationCounter *counter); // Set carry flags in the counters (in Method* and MDO). inline void handle_counter_overflow(Method* method); // Verify that a level is consistent with the compilation mode From dc1ef58351313a5a269a6b75396ed4a538582c0d Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 25 Sep 2020 10:10:04 +0000 Subject: [PATCH 15/79] 8253631: Remove unimplemented CompileBroker methods after JEP-165 Reviewed-by: thartmann --- src/hotspot/share/compiler/compileBroker.hpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/hotspot/share/compiler/compileBroker.hpp b/src/hotspot/share/compiler/compileBroker.hpp index 94a1eb02e3e18..2da97cf107ea4 100644 --- a/src/hotspot/share/compiler/compileBroker.hpp +++ b/src/hotspot/share/compiler/compileBroker.hpp @@ -271,10 +271,6 @@ class CompileBroker: AllStatic { static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread); public: - - static DirectivesStack* dirstack(); - static void set_dirstack(DirectivesStack* stack); - enum { // The entry bci used for non-OSR compilations. standard_entry_bci = InvocationEntryBci @@ -289,7 +285,6 @@ class CompileBroker: AllStatic { static bool compilation_is_complete(const methodHandle& method, int osr_bci, int comp_level); static bool compilation_is_in_queue(const methodHandle& method); static void print_compile_queues(outputStream* st); - static void print_directives(outputStream* st); static int queue_size(int comp_level) { CompileQueue *q = compile_queue(comp_level); return q != NULL ? q->size() : 0; From 1b79326c0556e2d70fb96dbcc6aeee4961fe65fc Mon Sep 17 00:00:00 2001 From: Gilles Duboscq Date: Fri, 25 Sep 2020 10:10:36 +0000 Subject: [PATCH 16/79] 8242451: ensure semantics of non-capturing lambdas are preserved independent of execution mode Reviewed-by: mchung --- .../invoke/InnerClassLambdaMetafactory.java | 85 ++++++++++++----- .../invoke/lambda/LambdaEagerInitTest.java | 91 +++++++++++++++++++ .../lambda/lambdaExpression/LambdaTest6.java | 4 +- .../lambda/methodReference/BridgeMethod.java | 42 ++------- 4 files changed, 165 insertions(+), 57 deletions(-) create mode 100644 test/jdk/java/lang/invoke/lambda/LambdaEagerInitTest.java diff --git a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index 1ced84c5d59d5..00289cbe33388 100644 --- a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -57,6 +57,7 @@ private static final String METHOD_DESCRIPTOR_VOID = Type.getMethodDescriptor(Type.VOID_TYPE); private static final String JAVA_LANG_OBJECT = "java/lang/Object"; private static final String NAME_CTOR = ""; + private static final String LAMBDA_INSTANCE_FIELD = "LAMBDA_INSTANCE$"; //Serialization support private static final String NAME_SERIALIZED_LAMBDA = "java/lang/invoke/SerializedLambda"; @@ -206,32 +207,42 @@ private static String lambdaClassName(Class targetClass) { @Override CallSite buildCallSite() throws LambdaConversionException { final Class innerClass = spinInnerClass(); - if (invokedType.parameterCount() == 0 && !disableEagerInitialization) { + if (invokedType.parameterCount() == 0) { // In the case of a non-capturing lambda, we optimize linkage by pre-computing a single instance, // unless we've suppressed eager initialization - final Constructor[] ctrs = AccessController.doPrivileged( - new PrivilegedAction<>() { - @Override - public Constructor[] run() { - Constructor[] ctrs = innerClass.getDeclaredConstructors(); - if (ctrs.length == 1) { - // The lambda implementing inner class constructor is private, set - // it accessible (by us) before creating the constant sole instance - ctrs[0].setAccessible(true); - } - return ctrs; + if (disableEagerInitialization) { + try { + return new ConstantCallSite(caller.findStaticGetter(innerClass, LAMBDA_INSTANCE_FIELD, + invokedType.returnType())); + } catch (ReflectiveOperationException e) { + throw new LambdaConversionException( + "Exception finding " + LAMBDA_INSTANCE_FIELD + " static field", e); + } + } else { + final Constructor[] ctrs = AccessController.doPrivileged( + new PrivilegedAction<>() { + @Override + public Constructor[] run() { + Constructor[] ctrs = innerClass.getDeclaredConstructors(); + if (ctrs.length == 1) { + // The lambda implementing inner class constructor is private, set + // it accessible (by us) before creating the constant sole instance + ctrs[0].setAccessible(true); + } + return ctrs; + } + }); + if (ctrs.length != 1) { + throw new LambdaConversionException("Expected one lambda constructor for " + + innerClass.getCanonicalName() + ", got " + ctrs.length); } - }); - if (ctrs.length != 1) { - throw new LambdaConversionException("Expected one lambda constructor for " - + innerClass.getCanonicalName() + ", got " + ctrs.length); - } - try { - Object inst = ctrs[0].newInstance(); - return new ConstantCallSite(MethodHandles.constant(samBase, inst)); - } catch (ReflectiveOperationException e) { - throw new LambdaConversionException("Exception instantiating lambda object", e); + try { + Object inst = ctrs[0].newInstance(); + return new ConstantCallSite(MethodHandles.constant(samBase, inst)); + } catch (ReflectiveOperationException e) { + throw new LambdaConversionException("Exception instantiating lambda object", e); + } } } else { try { @@ -331,6 +342,10 @@ private Class generateInnerClass() throws LambdaConversionException { generateConstructor(); + if (invokedType.parameterCount() == 0 && disableEagerInitialization) { + generateClassInitializer(); + } + // Forward the SAM method MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, samMethodName, samMethodType.toMethodDescriptorString(), null, null); @@ -398,6 +413,32 @@ public Void run() { } } + /** + * Generate a static field and a static initializer that sets this field to an instance of the lambda + */ + private void generateClassInitializer() { + String lambdaTypeDescriptor = invokedType.returnType().descriptorString(); + + // Generate the static final field that holds the lambda singleton + FieldVisitor fv = cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, + LAMBDA_INSTANCE_FIELD, lambdaTypeDescriptor, null, null); + fv.visitEnd(); + + // Instantiate the lambda and store it to the static final field + MethodVisitor clinit = cw.visitMethod(ACC_STATIC, "", "()V", null, null); + clinit.visitCode(); + + clinit.visitTypeInsn(NEW, lambdaClassName); + clinit.visitInsn(Opcodes.DUP); + assert invokedType.parameterCount() == 0; + clinit.visitMethodInsn(INVOKESPECIAL, lambdaClassName, NAME_CTOR, constructorType.toMethodDescriptorString(), false); + clinit.visitFieldInsn(PUTSTATIC, lambdaClassName, LAMBDA_INSTANCE_FIELD, lambdaTypeDescriptor); + + clinit.visitInsn(RETURN); + clinit.visitMaxs(-1, -1); + clinit.visitEnd(); + } + /** * Generate the constructor for the class */ diff --git a/test/jdk/java/lang/invoke/lambda/LambdaEagerInitTest.java b/test/jdk/java/lang/invoke/lambda/LambdaEagerInitTest.java new file mode 100644 index 0000000000000..4fbdeb691c51e --- /dev/null +++ b/test/jdk/java/lang/invoke/lambda/LambdaEagerInitTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020, 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 8242451 + * @library /test/lib + * @summary Test that the LAMBDA_INSTANCE$ field is present depending + * on disableEagerInitialization + * @run main LambdaEagerInitTest + * @run main/othervm -Djdk.internal.lambda.disableEagerInitialization=true LambdaEagerInitTest + */ + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +import static jdk.test.lib.Asserts.*; + +public class LambdaEagerInitTest { + + interface H {Object m(String s);} + + private static Set allowedStaticFields(boolean nonCapturing) { + Set s = new HashSet<>(); + if (Boolean.getBoolean("jdk.internal.lambda.disableEagerInitialization")) { + if (nonCapturing) s.add("LAMBDA_INSTANCE$"); + } + return s; + } + + private void nonCapturingLambda() { + H la = s -> s; + assertEquals("hi", la.m("hi")); + Class c1 = la.getClass(); + verifyLambdaClass(la.getClass(), true); + } + + private void capturingLambda() { + H la = s -> concat(s, "foo"); + assertEquals("hi foo", la.m("hi")); + verifyLambdaClass(la.getClass(), false); + } + + private void verifyLambdaClass(Class c, boolean nonCapturing) { + Set staticFields = new HashSet<>(); + Set instanceFields = new HashSet<>(); + for (Field f : c.getDeclaredFields()) { + if (Modifier.isStatic(f.getModifiers())) { + staticFields.add(f.getName()); + } else { + instanceFields.add(f.getName()); + } + } + assertEquals(instanceFields.size(), nonCapturing ? 0 : 1, "Unexpected instance fields"); + assertEquals(staticFields, allowedStaticFields(nonCapturing), "Unexpected static fields"); + } + + private String concat(String... ss) { + return Arrays.stream(ss).collect(Collectors.joining(" ")); + } + + public static void main(String[] args) { + LambdaEagerInitTest test = new LambdaEagerInitTest(); + test.nonCapturingLambda(); + test.capturingLambda(); + } +} diff --git a/test/langtools/tools/javac/lambda/lambdaExpression/LambdaTest6.java b/test/langtools/tools/javac/lambda/lambdaExpression/LambdaTest6.java index 40b232b4f4231..c9fe5db6917cb 100644 --- a/test/langtools/tools/javac/lambda/lambdaExpression/LambdaTest6.java +++ b/test/langtools/tools/javac/lambda/lambdaExpression/LambdaTest6.java @@ -26,11 +26,9 @@ * @bug 8003280 * @summary Add lambda tests * Test bridge methods for certain SAM conversions - * Tests that jdk.internal.lambda.disableEagerInitialization=true creates a - * get$Lambda method for non-capturing lambdas + * Test the set of generated methods * @compile LambdaTest6.java * @run main LambdaTest6 - * @run main/othervm -Djdk.internal.lambda.disableEagerInitialization=true LambdaTest6 */ import java.lang.reflect.Method; diff --git a/test/langtools/tools/javac/lambda/methodReference/BridgeMethod.java b/test/langtools/tools/javac/lambda/methodReference/BridgeMethod.java index ca32d3c7d2180..fb5c29ca4ca4c 100644 --- a/test/langtools/tools/javac/lambda/methodReference/BridgeMethod.java +++ b/test/langtools/tools/javac/lambda/methodReference/BridgeMethod.java @@ -26,15 +26,11 @@ * @bug 8003280 * @summary Add lambda tests * Test bridge methods in certain SAM conversion - * Tests that jdk.internal.lambda.disableEagerInitialization=true creates a - * get$Lambda method for non-capturing lambdas * @compile BridgeMethod.java * @run main BridgeMethod - * @run main/othervm -Djdk.internal.lambda.disableEagerInitialization=true BridgeMethod */ import java.lang.reflect.Method; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -72,35 +68,19 @@ private static Set setOfStringObject() { return s; } - private static Set allowedMethods() { - Set s = new HashSet<>(); - s.add("m"); - return s; - } - - private static boolean matchingMethodNames(Method[] methods) { - Set methodNames = new HashSet<>(); - for (Method m : methods) { - methodNames.add(m.getName()); - } - return methodNames.equals(allowedMethods()); - } - public static void main(String[] args) { L la = BridgeMethod::bar; //static reference la.m("hi"); Class c1 = la.getClass(); Method[] methods = c1.getDeclaredMethods(); - assertTrue(matchingMethodNames(methods)); Set types = setOfStringObject(); System.out.println("methods in SAM conversion of L:"); for(Method m : methods) { - if (m.getName().equals("m")) { - System.out.println(m.toGenericString()); - Class[] parameterTypes = m.getParameterTypes(); - assertTrue(parameterTypes.length == 1); - assertTrue(types.remove(parameterTypes[0].getName())); - } + assertTrue(m.getName().equals("m")); + System.out.println(m.toGenericString()); + Class[] parameterTypes = m.getParameterTypes(); + assertTrue(parameterTypes.length == 1); + assertTrue(types.remove(parameterTypes[0].getName())); } assertTrue(types.isEmpty() || (types.size() == 1 && types.contains("java.lang.String"))); @@ -108,16 +88,14 @@ public static void main(String[] args) { //km.m("hi"); //will be uncommented when CR7028808 fixed Class c2 = km.getClass(); methods = c2.getDeclaredMethods(); - assertTrue(matchingMethodNames(methods)); types = setOfStringObject(); System.out.println("methods in SAM conversion of KM:"); for(Method m : methods) { - if (m.getName().equals("m")) { - System.out.println(m.toGenericString()); - Class[] parameterTypes = m.getParameterTypes(); - assertTrue(parameterTypes.length == 1); - assertTrue(types.remove(parameterTypes[0].getName())); - } + assertTrue(m.getName().equals("m")); + System.out.println(m.toGenericString()); + Class[] parameterTypes = m.getParameterTypes(); + assertTrue(parameterTypes.length == 1); + assertTrue(types.remove(parameterTypes[0].getName())); } assertTrue(types.isEmpty()); From f62eefc02b1358a2a36f2091761f32b73d33bd57 Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Fri, 25 Sep 2020 10:14:04 +0000 Subject: [PATCH 17/79] 8253469: ARM32 Zero: replace usages of __sync_synchronize() with OrderAccess::fence Reviewed-by: dholmes --- src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp | 8 +++++--- src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp b/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp index 890385e8f175a..1c6f2155ef8cb 100644 --- a/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp +++ b/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp @@ -26,6 +26,7 @@ #ifndef OS_CPU_BSD_ZERO_ATOMIC_BSD_ZERO_HPP #define OS_CPU_BSD_ZERO_ATOMIC_BSD_ZERO_HPP +#include "orderAccess_bsd_zero.hpp" #include "runtime/os.hpp" // Implementation of class atomic @@ -218,8 +219,9 @@ inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest, // All atomic operations are expected to be full memory barriers // (see atomic.hpp). However, __sync_lock_test_and_set is not // a full memory barrier, but an acquire barrier. Hence, this added - // barrier. - __sync_synchronize(); + // barrier. Some platforms (notably ARM) have peculiarities with + // their barrier implementations, delegate it to OrderAccess. + OrderAccess::fence(); return result; #endif // M68K #endif // ARM @@ -232,7 +234,7 @@ inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, atomic_memory_order order) const { STATIC_ASSERT(8 == sizeof(T)); T result = __sync_lock_test_and_set (dest, exchange_value); - __sync_synchronize(); + OrderAccess::fence(); return result; } diff --git a/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp b/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp index dbd2fb0c587fc..fb6e350cf0555 100644 --- a/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp +++ b/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp @@ -26,6 +26,7 @@ #ifndef OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP #define OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP +#include "orderAccess_linux_zero.hpp" #include "runtime/os.hpp" // Implementation of class atomic @@ -74,8 +75,9 @@ inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest, // All atomic operations are expected to be full memory barriers // (see atomic.hpp). However, __sync_lock_test_and_set is not // a full memory barrier, but an acquire barrier. Hence, this added - // barrier. - __sync_synchronize(); + // barrier. Some platforms (notably ARM) have peculiarities with + // their barrier implementations, delegate it to OrderAccess. + OrderAccess::fence(); return result; } @@ -86,7 +88,7 @@ inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest, atomic_memory_order order) const { STATIC_ASSERT(8 == sizeof(T)); T result = __sync_lock_test_and_set (dest, exchange_value); - __sync_synchronize(); + OrderAccess::fence(); return result; } From 1f5a033421bbcf803169c5c5f93314fd22b5a4a5 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 25 Sep 2020 10:29:26 +0000 Subject: [PATCH 18/79] 8253555: Make ByteSize and WordSize typed scoped enums Reviewed-by: kbarrett, tschatzl --- src/hotspot/cpu/aarch64/assembler_aarch64.hpp | 4 +- src/hotspot/cpu/arm/assembler_arm.hpp | 13 +-- src/hotspot/cpu/arm/assembler_arm_32.hpp | 8 +- src/hotspot/cpu/ppc/assembler_ppc.hpp | 4 +- src/hotspot/cpu/ppc/assembler_ppc.inline.hpp | 4 +- src/hotspot/cpu/s390/assembler_s390.hpp | 11 +- src/hotspot/cpu/x86/assembler_x86.hpp | 58 +++------- src/hotspot/share/utilities/sizes.hpp | 108 ++---------------- test/hotspot/gtest/utilities/test_sizes.cpp | 41 +++++++ 9 files changed, 74 insertions(+), 177 deletions(-) create mode 100644 test/hotspot/gtest/utilities/test_sizes.cpp diff --git a/src/hotspot/cpu/aarch64/assembler_aarch64.hpp b/src/hotspot/cpu/aarch64/assembler_aarch64.hpp index 19a3ced143520..717be156e5c08 100644 --- a/src/hotspot/cpu/aarch64/assembler_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/assembler_aarch64.hpp @@ -401,10 +401,8 @@ class Address { : _base(r), _index(noreg), _offset(o), _mode(base_plus_offset), _target(0) { } Address(Register r, unsigned long long o) : _base(r), _index(noreg), _offset(o), _mode(base_plus_offset), _target(0) { } -#ifdef ASSERT Address(Register r, ByteSize disp) - : _base(r), _index(noreg), _offset(in_bytes(disp)), _mode(base_plus_offset), _target(0) { } -#endif + : Address(r, in_bytes(disp)) { } Address(Register r, Register r1, extend ext = lsl()) : _base(r), _index(r1), _offset(0), _mode(base_plus_offset_reg), _ext(ext), _target(0) { } diff --git a/src/hotspot/cpu/arm/assembler_arm.hpp b/src/hotspot/cpu/arm/assembler_arm.hpp index 8beaa284a79ce..1de4b0da7740c 100644 --- a/src/hotspot/cpu/arm/assembler_arm.hpp +++ b/src/hotspot/cpu/arm/assembler_arm.hpp @@ -89,17 +89,8 @@ class Address { _offset_op = add_offset; } -#ifdef ASSERT - Address(Register rn, ByteSize offset, AsmOffset mode = basic_offset) { - _base = rn; - _index = noreg; - _disp = in_bytes(offset); - _mode = mode; - _shift_imm = 0; - _shift = lsl; - _offset_op = add_offset; - } -#endif + Address(Register rn, ByteSize offset, AsmOffset mode = basic_offset) : + Address(rn, in_bytes(offset), mode) {} Address(Register rn, Register rm, AsmShift shift = lsl, int shift_imm = 0, AsmOffset mode = basic_offset, diff --git a/src/hotspot/cpu/arm/assembler_arm_32.hpp b/src/hotspot/cpu/arm/assembler_arm_32.hpp index 44997ddcbce4b..dd04ad1ab3a3c 100644 --- a/src/hotspot/cpu/arm/assembler_arm_32.hpp +++ b/src/hotspot/cpu/arm/assembler_arm_32.hpp @@ -55,12 +55,8 @@ class AsmOperand { encode(imm_8); } -#ifdef ASSERT - AsmOperand(ByteSize bytesize_8) { - const int imm_8 = in_bytes(bytesize_8); - encode(imm_8); - } -#endif // ASSERT + AsmOperand(ByteSize bytesize_8) : + AsmOperand(in_bytes(bytesize_8)) {} AsmOperand(Register rm, AsmShift shift, int shift_imm) { encode(rm,shift,shift_imm); diff --git a/src/hotspot/cpu/ppc/assembler_ppc.hpp b/src/hotspot/cpu/ppc/assembler_ppc.hpp index 37a46a26b5a09..05ab385fb4f55 100644 --- a/src/hotspot/cpu/ppc/assembler_ppc.hpp +++ b/src/hotspot/cpu/ppc/assembler_ppc.hpp @@ -1639,7 +1639,7 @@ class Assembler : public AbstractAssembler { // For convenience. Load pointer into d from b+s1. inline void ld_ptr(Register d, int b, Register s1); - DEBUG_ONLY(inline void ld_ptr(Register d, ByteSize b, Register s1);) + inline void ld_ptr(Register d, ByteSize b, Register s1); // PPC 1, section 3.3.3 Fixed-Point Store Instructions inline void stwx( Register d, Register s1, Register s2); @@ -1663,7 +1663,7 @@ class Assembler : public AbstractAssembler { inline void stdbrx( Register d, Register s1, Register s2); inline void st_ptr(Register d, int si16, Register s1); - DEBUG_ONLY(inline void st_ptr(Register d, ByteSize b, Register s1);) + inline void st_ptr(Register d, ByteSize b, Register s1); // PPC 1, section 3.3.13 Move To/From System Register Instructions inline void mtlr( Register s1); diff --git a/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp b/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp index 4f50b570f68b3..a351674b5ba92 100644 --- a/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp +++ b/src/hotspot/cpu/ppc/assembler_ppc.inline.hpp @@ -342,7 +342,7 @@ inline void Assembler::ldu( Register d, int si16, Register s1) { assert(d != inline void Assembler::ldbrx( Register d, Register s1, Register s2) { emit_int32(LDBRX_OPCODE | rt(d) | ra0mem(s1) | rb(s2));} inline void Assembler::ld_ptr(Register d, int b, Register s1) { ld(d, b, s1); } -DEBUG_ONLY(inline void Assembler::ld_ptr(Register d, ByteSize b, Register s1) { ld(d, in_bytes(b), s1); }) +inline void Assembler::ld_ptr(Register d, ByteSize b, Register s1) { ld(d, in_bytes(b), s1); } // PPC 1, section 3.3.3 Fixed-Point Store Instructions inline void Assembler::stwx( Register d, Register s1, Register s2) { emit_int32(STWX_OPCODE | rs(d) | ra0mem(s1) | rb(s2));} @@ -366,7 +366,7 @@ inline void Assembler::stdux(Register s, Register a, Register b) { emit_int32( inline void Assembler::stdbrx( Register d, Register s1, Register s2) { emit_int32(STDBRX_OPCODE | rs(d) | ra0mem(s1) | rb(s2));} inline void Assembler::st_ptr(Register d, int b, Register s1) { std(d, b, s1); } -DEBUG_ONLY(inline void Assembler::st_ptr(Register d, ByteSize b, Register s1) { std(d, in_bytes(b), s1); }) +inline void Assembler::st_ptr(Register d, ByteSize b, Register s1) { std(d, in_bytes(b), s1); } // PPC 1, section 3.3.13 Move To/From System Register Instructions inline void Assembler::mtlr( Register s1) { emit_int32(MTLR_OPCODE | rs(s1)); } diff --git a/src/hotspot/cpu/s390/assembler_s390.hpp b/src/hotspot/cpu/s390/assembler_s390.hpp index cd1e7e2c5f28f..96e494d52e7df 100644 --- a/src/hotspot/cpu/s390/assembler_s390.hpp +++ b/src/hotspot/cpu/s390/assembler_s390.hpp @@ -206,18 +206,11 @@ class Address { if (roc.is_constant()) _disp += roc.as_constant(); else _index = roc.as_register(); } -#ifdef ASSERT - // ByteSize is only a class when ASSERT is defined, otherwise it's an int. Address(Register base, ByteSize disp) : - _base(base), - _index(noreg), - _disp(in_bytes(disp)) {} + Address(base, in_bytes(disp)) {} Address(Register base, Register index, ByteSize disp) : - _base(base), - _index(index), - _disp(in_bytes(disp)) {} -#endif + Address(base, index, in_bytes(disp)) {} // Aborts if disp is a register and base and index are set already. Address plus_disp(RegisterOrConstant disp) const { diff --git a/src/hotspot/cpu/x86/assembler_x86.hpp b/src/hotspot/cpu/x86/assembler_x86.hpp index bbcfb7ec64e64..283285dc347e4 100644 --- a/src/hotspot/cpu/x86/assembler_x86.hpp +++ b/src/hotspot/cpu/x86/assembler_x86.hpp @@ -256,6 +256,19 @@ class Address { "inconsistent address"); } + // The following overloads are used in connection with the + // ByteSize type (see sizes.hpp). They simplify the use of + // ByteSize'd arguments in assembly code. + + Address(Register base, ByteSize disp) + : Address(base, in_bytes(disp)) {} + + Address(Register base, Register index, ScaleFactor scale, ByteSize disp) + : Address(base, index, scale, in_bytes(disp)) {} + + Address(Register base, RegisterOrConstant index, ScaleFactor scale, ByteSize disp) + : Address(base, index, scale, in_bytes(disp)) {} + Address plus_disp(int disp) const { Address a = (*this); a._disp += disp; @@ -276,51 +289,6 @@ class Address { return _base == a._base && _disp == a._disp && _index == a._index && _scale == a._scale; } - // The following two overloads are used in connection with the - // ByteSize type (see sizes.hpp). They simplify the use of - // ByteSize'd arguments in assembly code. Note that their equivalent - // for the optimized build are the member functions with int disp - // argument since ByteSize is mapped to an int type in that case. - // - // Note: DO NOT introduce similar overloaded functions for WordSize - // arguments as in the optimized mode, both ByteSize and WordSize - // are mapped to the same type and thus the compiler cannot make a - // distinction anymore (=> compiler errors). - -#ifdef ASSERT - Address(Register base, ByteSize disp) - : _base(base), - _index(noreg), - _xmmindex(xnoreg), - _scale(no_scale), - _disp(in_bytes(disp)), - _isxmmindex(false){ - } - - Address(Register base, Register index, ScaleFactor scale, ByteSize disp) - : _base(base), - _index(index), - _xmmindex(xnoreg), - _scale(scale), - _disp(in_bytes(disp)), - _isxmmindex(false){ - assert(!index->is_valid() == (scale == Address::no_scale), - "inconsistent address"); - } - Address(Register base, RegisterOrConstant index, ScaleFactor scale, ByteSize disp) - : _base (base), - _index(index.register_or_noreg()), - _xmmindex(xnoreg), - _scale(scale), - _disp (in_bytes(disp) + (index.constant_or_zero() * scale_size(scale))), - _isxmmindex(false) { - if (!index.is_register()) scale = Address::no_scale; - assert(!_index->is_valid() == (scale == Address::no_scale), - "inconsistent address"); - } - -#endif // ASSERT - // accessors bool uses(Register reg) const { return _base == reg || _index == reg; } Register base() const { return _base; } diff --git a/src/hotspot/share/utilities/sizes.hpp b/src/hotspot/share/utilities/sizes.hpp index 0944c8280b285..97e28cd6082a8 100644 --- a/src/hotspot/share/utilities/sizes.hpp +++ b/src/hotspot/share/utilities/sizes.hpp @@ -32,22 +32,6 @@ // WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words // depending on platform). // -// The classes are defined with friend functions operating on them instead of member -// functions so that they (the classes) can be re-#define'd to int types in optimized -// mode. This allows full type checking and maximum safety in debug mode, and full -// optimizations (constant folding) and zero overhead (time and space wise) in the -// optimized build (some compilers do not optimize one-element value classes but -// instead create an object in memory - thus the overhead may be significant). -// -// Note: 1) DO NOT add new overloaded friend functions that do not have a unique function -// function name but require signature types for resolution. This will not work -// in optimized mode as both, ByteSize and WordSize are mapped to the same type -// and thus the distinction would not be possible anymore (=> compiler errors). -// -// 2) DO NOT add non-static member functions as they cannot be mapped so something -// compilable in the optimized build. Static member functions could be added -// but require a corresponding class definition in the optimized build. -// // These classes should help doing a transition from (currently) word-size based offsets // to byte-size based offsets in the VM (this will be important if we desire to pack // objects more densely in the VM for 64bit machines). Such a transition should proceed @@ -56,93 +40,19 @@ // a) first transition the whole VM into a form where all sizes are strongly typed // b) change all WordSize's to ByteSize's where desired and fix the compilation errors +enum class WordSize : int {}; -#ifdef ASSERT - -class ByteSize { - private: - int _size; - - // Note: This constructor must be private to avoid implicit conversions! - ByteSize(int size) { _size = size; } - - public: - // constructors - inline friend ByteSize in_ByteSize(int size); - - // accessors - inline friend int in_bytes(ByteSize x); - - // operators - friend ByteSize operator + (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) + in_bytes(y)); } - friend ByteSize operator - (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) - in_bytes(y)); } - friend ByteSize operator * (ByteSize x, int y) { return ByteSize(in_bytes(x) * y ); } - - // comparison - friend bool operator == (ByteSize x, ByteSize y) { return in_bytes(x) == in_bytes(y); } - friend bool operator != (ByteSize x, ByteSize y) { return in_bytes(x) != in_bytes(y); } - friend bool operator < (ByteSize x, ByteSize y) { return in_bytes(x) < in_bytes(y); } - friend bool operator <= (ByteSize x, ByteSize y) { return in_bytes(x) <= in_bytes(y); } - friend bool operator > (ByteSize x, ByteSize y) { return in_bytes(x) > in_bytes(y); } - friend bool operator >= (ByteSize x, ByteSize y) { return in_bytes(x) >= in_bytes(y); } -}; - -inline ByteSize in_ByteSize(int size) { return ByteSize(size); } -inline int in_bytes(ByteSize x) { return x._size; } - - -class WordSize { - private: - int _size; - - // Note: This constructor must be private to avoid implicit conversions! - WordSize(int size) { _size = size; } - - public: - // constructors - inline friend WordSize in_WordSize(int size); - - // accessors - inline friend int in_words(WordSize x); - - // operators - friend WordSize operator + (WordSize x, WordSize y) { return WordSize(in_words(x) + in_words(y)); } - friend WordSize operator - (WordSize x, WordSize y) { return WordSize(in_words(x) - in_words(y)); } - friend WordSize operator * (WordSize x, int y) { return WordSize(in_words(x) * y ); } - - // comparison - friend bool operator == (WordSize x, WordSize y) { return in_words(x) == in_words(y); } - friend bool operator != (WordSize x, WordSize y) { return in_words(x) != in_words(y); } - friend bool operator < (WordSize x, WordSize y) { return in_words(x) < in_words(y); } - friend bool operator <= (WordSize x, WordSize y) { return in_words(x) <= in_words(y); } - friend bool operator > (WordSize x, WordSize y) { return in_words(x) > in_words(y); } - friend bool operator >= (WordSize x, WordSize y) { return in_words(x) >= in_words(y); } -}; - -inline WordSize in_WordSize(int size) { return WordSize(size); } -inline int in_words(WordSize x) { return x._size; } - - -#else // ASSERT - -// The following definitions must match the corresponding friend declarations -// in the Byte/WordSize classes if they are typedef'ed to be int. This will -// be the case in optimized mode to ensure zero overhead for these types. -// -// Note: If a compiler does not inline these function calls away, one may -// want to use #define's to make sure full optimization (constant -// folding in particular) is possible. - -typedef int ByteSize; -inline ByteSize in_ByteSize(int size) { return size; } -inline int in_bytes (ByteSize x) { return x; } +constexpr WordSize in_WordSize(int size) { return static_cast(size); } +constexpr int in_words(WordSize x) { return static_cast(x); } -typedef int WordSize; -inline WordSize in_WordSize(int size) { return size; } -inline int in_words (WordSize x) { return x; } +enum class ByteSize : int {}; -#endif // ASSERT +constexpr ByteSize in_ByteSize(int size) { return static_cast(size); } +constexpr int in_bytes(ByteSize x) { return static_cast(x); } +constexpr ByteSize operator + (ByteSize x, ByteSize y) { return in_ByteSize(in_bytes(x) + in_bytes(y)); } +constexpr ByteSize operator - (ByteSize x, ByteSize y) { return in_ByteSize(in_bytes(x) - in_bytes(y)); } +constexpr ByteSize operator * (ByteSize x, int y) { return in_ByteSize(in_bytes(x) * y ); } // Use the following #define to get C++ field member offsets diff --git a/test/hotspot/gtest/utilities/test_sizes.cpp b/test/hotspot/gtest/utilities/test_sizes.cpp new file mode 100644 index 0000000000000..9458124ee2b76 --- /dev/null +++ b/test/hotspot/gtest/utilities/test_sizes.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020, 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. + */ + +#include "precompiled.hpp" +#include "utilities/sizes.hpp" +#include "unittest.hpp" + +TEST(ByteSize, constructors) { + EXPECT_EQ(in_bytes(in_ByteSize(10)), 10); +} + +TEST(ByteSize, operators) { + ByteSize s = in_ByteSize(7); + ASSERT_EQ(in_bytes(s + in_ByteSize(3)), 10); + ASSERT_EQ(in_bytes(s - in_ByteSize(3)), 4); + ASSERT_EQ(in_bytes(s * 3), 21); +} + +TEST(WordSize, constructors) { + EXPECT_EQ(in_words(in_WordSize(10)), 10); +} From a75edc29c6ce41116cc99530aa1710efb62c6d5a Mon Sep 17 00:00:00 2001 From: Aleksei Efimov Date: Fri, 25 Sep 2020 12:46:08 +0000 Subject: [PATCH 19/79] 8251188: Update LDAP tests not to use wildcard addresses Reviewed-by: dfuchs --- test/jdk/ProblemList.txt | 2 - .../sun/jndi/ldap/BalancedParentheses.java | 23 ++- .../sun/jndi/ldap/DeadSSLLdapTimeoutTest.java | 170 ++++++++++++------ .../sun/jndi/ldap/DeadSSLSocketFactory.java | 93 ++++++++++ .../jndi/ldap/blits/AddTests/AddNewEntry.java | 25 ++- .../com/sun/jndi/ldap/lib/LDAPTestUtils.java | 16 +- 6 files changed, 258 insertions(+), 71 deletions(-) create mode 100644 test/jdk/com/sun/jndi/ldap/DeadSSLSocketFactory.java diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index cbae666f1452c..602ea3cb1506c 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -889,8 +889,6 @@ sun/tools/jhsdb/BasicLauncherTest.java 8211767 linux-pp # jdk_other -com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java 8169942 linux-i586,macosx-all,windows-x64 - javax/rmi/ssl/SSLSocketParametersTest.sh 8162906 generic-all javax/script/Test7.java 8239361 generic-all diff --git a/test/jdk/com/sun/jndi/ldap/BalancedParentheses.java b/test/jdk/com/sun/jndi/ldap/BalancedParentheses.java index 2b62888f75afa..b4ea10313d85a 100644 --- a/test/jdk/com/sun/jndi/ldap/BalancedParentheses.java +++ b/test/jdk/com/sun/jndi/ldap/BalancedParentheses.java @@ -24,18 +24,23 @@ /** * @test * @bug 6449574 + * @library /test/lib * @summary Invalid ldap filter is accepted and processed */ import java.io.*; import javax.naming.*; import javax.naming.directory.*; -import java.util.Properties; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.util.Hashtable; import java.net.Socket; import java.net.ServerSocket; +import jdk.test.lib.net.URIBuilder; + public class BalancedParentheses { // Should we run the client or server in a separate thread? // @@ -54,7 +59,13 @@ public class BalancedParentheses { // If the server prematurely exits, serverReady will be set to true // to avoid infinite hangs. void doServerSide() throws Exception { - ServerSocket serverSock = new ServerSocket(serverPort); + // Create unbound server socket + ServerSocket serverSock = new ServerSocket(); + + // And bind it to the loopback address + SocketAddress sockAddr = new InetSocketAddress( + InetAddress.getLoopbackAddress(), 0); + serverSock.bind(sockAddr); // signal client, it's ready to accecpt connection serverPort = serverSock.getLocalPort(); @@ -106,7 +117,13 @@ void doClientSide() throws Exception { Hashtable env = new Hashtable<>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); - env.put(Context.PROVIDER_URL, "ldap://localhost:" + serverPort); + // Construct the provider URL + String providerURL = URIBuilder.newBuilder() + .scheme("ldap") + .loopback() + .port(serverPort) + .build().toString(); + env.put(Context.PROVIDER_URL, providerURL); env.put("com.sun.jndi.ldap.read.timeout", "1000"); // env.put(Context.SECURITY_AUTHENTICATION, "simple"); diff --git a/test/jdk/com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java b/test/jdk/com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java index ea056f252373a..e72683391ab74 100644 --- a/test/jdk/com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java +++ b/test/jdk/com/sun/jndi/ldap/DeadSSLLdapTimeoutTest.java @@ -21,34 +21,35 @@ * questions. */ -/** +/* * @test - * @run main/othervm DeadSSLLdapTimeoutTest * @bug 8141370 * @key intermittent + * @library /test/lib + * @build DeadSSLSocketFactory + * @run main/othervm DeadSSLLdapTimeoutTest */ -import java.net.Socket; +import java.io.EOFException; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketAddress; import java.net.SocketTimeoutException; -import java.io.*; -import javax.naming.*; -import javax.naming.directory.*; -import java.util.List; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import java.util.Hashtable; -import java.util.ArrayList; import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.naming.directory.InitialDirContext; import javax.net.ssl.SSLHandshakeException; -import static java.util.concurrent.TimeUnit.MILLISECONDS; +import jdk.test.lib.net.URIBuilder; + import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -57,26 +58,26 @@ class DeadServerTimeoutSSLTest implements Callable { Hashtable env; DeadSSLServer server; boolean passed = false; - private int HANGING_TEST_TIMEOUT = 20_000; public DeadServerTimeoutSSLTest(Hashtable env) throws IOException { - this.server = new DeadSSLServer(); + SocketAddress sockAddr = new InetSocketAddress( + InetAddress.getLoopbackAddress(), 0); + this.server = new DeadSSLServer(sockAddr); this.env = env; } - public void performOp(InitialContext ctx) throws NamingException {} - - public void handleNamingException(NamingException e, long start, long end) { + public void handleNamingException(NamingException e) { if (e.getCause() instanceof SocketTimeoutException || e.getCause().getCause() instanceof SocketTimeoutException) { // SSL connect will timeout via readReply using // SocketTimeoutException - e.printStackTrace(); + System.out.println("PASS: Observed expected SocketTimeoutException"); pass(); } else if (e.getCause() instanceof SSLHandshakeException && e.getCause().getCause() instanceof EOFException) { // test seems to be failing intermittently on some // platforms. + System.out.println("PASS: Observed expected SSLHandshakeException/EOFException"); pass(); } else { fail(e); @@ -92,6 +93,7 @@ public void fail() { } public void fail(Exception e) { + System.err.println("FAIL: Unexpected exception was observed:" + e.getMessage()); throw new RuntimeException("Test failed", e); } @@ -106,34 +108,36 @@ boolean shutItDown(InitialContext ctx) { public Boolean call() { InitialContext ctx = null; - ScheduledFuture killer = null; - long start = System.nanoTime(); try { - while(!server.accepting()) - Thread.sleep(200); // allow the server to start up + server.serverStarted.await(); // Wait for the server to start-up Thread.sleep(200); // to be sure - env.put(Context.PROVIDER_URL, "ldap://localhost:" + - server.getLocalPort()); + env.put(Context.PROVIDER_URL, + URIBuilder.newBuilder() + .scheme("ldap") + .loopback() + .port(server.getLocalPort()) + .buildUnchecked().toString() + ); + long start = System.nanoTime(); try { ctx = new InitialDirContext(env); - performOp(ctx); fail(); } catch (NamingException e) { long end = System.nanoTime(); System.out.println(this.getClass().toString() + " - elapsed: " + NANOSECONDS.toMillis(end - start)); - handleNamingException(e, start, end); + handleNamingException(e); } finally { - if (killer != null && !killer.isDone()) - killer.cancel(true); + // Stop the server side thread + server.testDone.countDown(); shutItDown(ctx); server.close(); } return passed; - } catch (IOException|InterruptedException e) { + } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } } @@ -141,20 +145,69 @@ public Boolean call() { class DeadSSLServer extends Thread { ServerSocket serverSock; - boolean accepting = false; - - public DeadSSLServer() throws IOException { - this.serverSock = new ServerSocket(0); + // Latch to be used by client to wait for server to start + CountDownLatch serverStarted = new CountDownLatch(1); + + // Latch to be used by server thread to wait for client to finish testing + CountDownLatch testDone = new CountDownLatch(1); + + public DeadSSLServer(SocketAddress socketAddress) throws IOException { + // create unbound server socket + var srvSock = new ServerSocket(); + // bind it to the address provided + srvSock.bind(socketAddress); + this.serverSock = srvSock; start(); } public void run() { - while(true) { - try { - accepting = true; - Socket socket = serverSock.accept(); + // Signal client to proceed with the test + serverStarted.countDown(); + while (true) { + try (var acceptedSocket = serverSock.accept()) { + System.err.println("Accepted connection:" + acceptedSocket); + int iteration = 0; + // Wait for socket to get opened by DeadSSLSocketFactory and connected to the test server + while (iteration++ < 20) { + if (DeadSSLSocketFactory.firstCreatedSocket.get() != null && + DeadSSLSocketFactory.firstCreatedSocket.get().isConnected()) { + break; + } + try { + TimeUnit.MILLISECONDS.sleep(50); + } catch (InterruptedException ie) { + } + } + Socket clientSideSocket = DeadSSLSocketFactory.firstCreatedSocket.get(); + System.err.printf("Got SSLSocketFactory connection after %d iterations: %s%n", + iteration, clientSideSocket); + + if (clientSideSocket == null || !clientSideSocket.isConnected()) { + // If after 1000 ms client side connection is not opened - probably other local process + // tried to connect to the test server socket. Close current connection and retry accept. + continue; + } else { + // Check if accepted socket is connected to the LDAP client + if (acceptedSocket.getLocalPort() == clientSideSocket.getPort() && + acceptedSocket.getPort() == clientSideSocket.getLocalPort() && + acceptedSocket.getInetAddress().equals(clientSideSocket.getLocalAddress())) { + System.err.println("Accepted connection is originated from LDAP client:" + acceptedSocket); + try { + // Give LDAP client time to fully establish the connection. + // When client is done - the accepted socket will be closed + testDone.await(); + } catch (InterruptedException e) { + } + break; + } else { + // If accepted socket is not from the LDAP client - the accepted connection will be closed and new + // one will be accepted + System.err.println("SSLSocketFactory connection has been established, but originated not from" + + " the test's LDAP client:" + acceptedSocket); + } + } } catch (Exception e) { - break; + System.err.println("Server socket. Failure to accept connection:" + e.getMessage()); } } } @@ -163,28 +216,26 @@ public int getLocalPort() { return serverSock.getLocalPort(); } - public boolean accepting() { - return accepting; - } - public void close() throws IOException { serverSock.close(); } } public class DeadSSLLdapTimeoutTest { + // com.sun.jndi.ldap.connect.timeout value to set + static final String CONNECT_TIMEOUT_MS = "10"; + + // com.sun.jndi.ldap.read.timeout value to set + static final String READ_TIMEOUT_MS = "3000"; static Hashtable createEnv() { Hashtable env = new Hashtable<>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, - "com.sun.jndi.ldap.LdapCtxFactory"); + "com.sun.jndi.ldap.LdapCtxFactory"); return env; } public static void main(String[] args) throws Exception { - - InitialContext ctx = null; - // // Running this test serially as it seems to tickle a problem // on older kernels @@ -193,19 +244,24 @@ public static void main(String[] args) throws Exception { // and ssl enabled // this should exit with a SocketTimeoutException as the root cause // it should also use the connect timeout instead of the read timeout - System.out.println("Running connect timeout test with 10ms connect timeout, 3000ms read timeout & SSL"); + System.out.printf("Running connect timeout test with %sms connect timeout," + + " %sms read timeout & SSL%n", + CONNECT_TIMEOUT_MS, READ_TIMEOUT_MS); + Hashtable sslenv = createEnv(); - sslenv.put("com.sun.jndi.ldap.connect.timeout", "10"); - sslenv.put("com.sun.jndi.ldap.read.timeout", "3000"); + // Setup connect timeout environment property + sslenv.put("com.sun.jndi.ldap.connect.timeout", CONNECT_TIMEOUT_MS); + // Setup read timeout environment property + sslenv.put("com.sun.jndi.ldap.read.timeout", READ_TIMEOUT_MS); + // Setup DeadSSLSocketFactory to track the client's first LDAP connection + sslenv.put("java.naming.ldap.factory.socket", "DeadSSLSocketFactory"); + // Use SSL protocol sslenv.put(Context.SECURITY_PROTOCOL, "ssl"); - boolean testFailed = - (new DeadServerTimeoutSSLTest(sslenv).call()) ? false : true; + boolean testFailed = !new DeadServerTimeoutSSLTest(sslenv).call(); if (testFailed) { throw new AssertionError("some tests failed"); } - } - } diff --git a/test/jdk/com/sun/jndi/ldap/DeadSSLSocketFactory.java b/test/jdk/com/sun/jndi/ldap/DeadSSLSocketFactory.java new file mode 100644 index 0000000000000..2966abe95541c --- /dev/null +++ b/test/jdk/com/sun/jndi/ldap/DeadSSLSocketFactory.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2020, 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 javax.net.SocketFactory; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +/* + * A custom socket factory used to override the default socket factory and track the LDAP client connection. + * Factory can create only one SSLSocket. See the DeadServerTimeoutSSLTest test. + */ +public class DeadSSLSocketFactory extends SocketFactory { + // Client socket that is used by LDAP connection + public static AtomicReference firstCreatedSocket = new AtomicReference<>(); + + // Boolean to track if connection socket has been opened + public static AtomicBoolean isConnectionOpened = new AtomicBoolean(false); + + // Default SSLSocketFactory that will be used for SSL socket creation + final SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault(); + + // Create unconnected socket + public Socket createSocket() throws IOException { + if (!isConnectionOpened.getAndSet(true)) { + System.err.println("DeadSSLSocketFactory: Creating unconnected socket"); + firstCreatedSocket.set((SSLSocket) factory.createSocket()); + return firstCreatedSocket.get(); + } else { + throw new RuntimeException("DeadSSLSocketFactory only allows creation of one SSL socket"); + } + } + + public DeadSSLSocketFactory() { + System.err.println("DeadSSLSocketFactory: Constructor call"); + } + + public static SocketFactory getDefault() { + System.err.println("DeadSSLSocketFactory: acquiring DeadSSLSocketFactory as default socket factory"); + return new DeadSSLSocketFactory(); + } + + @Override + public Socket createSocket(String host, int port) throws IOException { + // Not used by DeadSSLLdapTimeoutTest + return factory.createSocket(host, port); + } + + @Override + public Socket createSocket(String host, int port, InetAddress localHost, + int localPort) throws IOException { + // Not used by DeadSSLLdapTimeoutTest + return factory.createSocket(host, port, localHost, localPort); + } + + @Override + public Socket createSocket(InetAddress host, int port) throws IOException { + // Not used by DeadSSLLdapTimeoutTest + return factory.createSocket(host, port); + } + + @Override + public Socket createSocket(InetAddress address, int port, + InetAddress localAddress, int localPort) throws IOException { + // Not used by DeadSSLLdapTimeoutTest + return factory.createSocket(address, port, localAddress, localPort); + } +} + diff --git a/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java b/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java index 925286774535d..3b9f7c1b9a5ba 100644 --- a/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java +++ b/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java @@ -27,7 +27,7 @@ * @summary Verify capability to add a new entry to the directory using the * ADD operation. * @modules java.naming/com.sun.jndi.ldap - * @library ../../lib/ /javax/naming/module/src/test/test/ + * @library /test/lib ../../lib/ /javax/naming/module/src/test/test/ * @build LDAPServer LDAPTestUtils * @run main/othervm AddNewEntry */ @@ -41,19 +41,36 @@ import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.ServerSocket; +import java.net.SocketAddress; import java.util.Hashtable; +import jdk.test.lib.net.URIBuilder; public class AddNewEntry { public static void main(String[] args) throws Exception { - ServerSocket serverSocket = new ServerSocket(0); + // Create unbound server socket + ServerSocket serverSocket = new ServerSocket(); + + // Bind it to the loopback address + SocketAddress sockAddr = new InetSocketAddress( + InetAddress.getLoopbackAddress(), 0); + serverSocket.bind(sockAddr); + + // Construct the provider URL for LDAPTestUtils + String providerURL = URIBuilder.newBuilder() + .scheme("ldap") + .loopback() + .port(serverSocket.getLocalPort()) + .buildUnchecked().toString(); Hashtable env; // initialize test - env = LDAPTestUtils - .initEnv(serverSocket, AddNewEntry.class.getName(), args, true); + env = LDAPTestUtils.initEnv(serverSocket, providerURL, + AddNewEntry.class.getName(), args, true); /* Build attribute set */ String[] ids = { "objectClass", "sn", "cn", "telephoneNumber", "mail", diff --git a/test/jdk/com/sun/jndi/ldap/lib/LDAPTestUtils.java b/test/jdk/com/sun/jndi/ldap/lib/LDAPTestUtils.java index dc3ec74e06c5f..c44cc4aed98b2 100644 --- a/test/jdk/com/sun/jndi/ldap/lib/LDAPTestUtils.java +++ b/test/jdk/com/sun/jndi/ldap/lib/LDAPTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,12 +50,17 @@ public class LDAPTestUtils { * Process command line arguments and return properties in a Hashtable. */ public static Hashtable initEnv(String testname, - String[] args) { + String[] args) { return initEnv(null, testname, args, false); } public static Hashtable initEnv(ServerSocket socket, - String testname, String[] args, boolean authInfo) { + String testname, String[] args, boolean authInfo) { + return initEnv(socket, null, testname, args, authInfo); + } + + public static Hashtable initEnv(ServerSocket socket, String providerUrl, + String testname, String[] args, boolean authInfo) { Hashtable env = new Hashtable<>(); String root = "o=IMC,c=US"; @@ -103,8 +108,9 @@ public static Hashtable initEnv(ServerSocket socket, if (socket != null) { env.put(TEST_LDAP_SERVER_THREAD, startLDAPServer(socket, getCaptureFile(testname))); - env.put("java.naming.provider.url", - "ldap://localhost:" + socket.getLocalPort()); + String url = providerUrl != null ? providerUrl : + "ldap://localhost:" + socket.getLocalPort(); + env.put("java.naming.provider.url", url); } else { // for tests which run against remote server or no server // required From 0187567704d79ecf394d4cb656d0ba4c886351f1 Mon Sep 17 00:00:00 2001 From: Harold Seigel Date: Fri, 25 Sep 2020 17:16:38 +0000 Subject: [PATCH 20/79] =?UTF-8?q?8250984:=20Memory=20Docker=20tests=20fail?= =?UTF-8?q?=20on=20some=20Linux=20kernels=20w/o=20cgroupv1=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: bobv, sgehwolf --- .../CgroupV1MemorySubSystemController.java | 10 ++- .../platform/cgroupv1/CgroupV1Subsystem.java | 20 ++++++ test/hotspot/jtreg/ProblemList.txt | 1 - .../jtreg/containers/cgroup/PlainRead.java | 2 +- .../docker/TestMemoryAwareness.java | 20 ++++-- test/jdk/ProblemList.txt | 2 - .../platform/docker/MetricsMemoryTester.java | 64 +++++++++++-------- .../cgroup/MetricsTesterCgroupV1.java | 44 +++++++------ 8 files changed, 104 insertions(+), 59 deletions(-) diff --git a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1MemorySubSystemController.java b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1MemorySubSystemController.java index 6153d64efaee6..415ae930a935d 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1MemorySubSystemController.java +++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1MemorySubSystemController.java @@ -28,6 +28,7 @@ public class CgroupV1MemorySubSystemController extends CgroupV1SubsystemController { private boolean hierarchical; + private boolean swapenabled; public CgroupV1MemorySubSystemController(String root, String mountPoint) { super(root, mountPoint); @@ -41,4 +42,11 @@ void setHierarchical(boolean hierarchical) { this.hierarchical = hierarchical; } -} \ No newline at end of file + boolean isSwapEnabled() { + return swapenabled; + } + + void setSwapEnabled(boolean swapenabled) { + this.swapenabled = swapenabled; + } +} diff --git a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java index fd1867d5cf2bd..e1455e2799dbe 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java +++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv1/CgroupV1Subsystem.java @@ -199,6 +199,8 @@ private static void setSubSystemControllerPath(CgroupV1Subsystem subsystem, Stri CgroupV1MemorySubSystemController memorySubSystem = (CgroupV1MemorySubSystemController)controller; boolean isHierarchial = getHierarchical(memorySubSystem); memorySubSystem.setHierarchical(isHierarchial); + boolean isSwapEnabled = getSwapEnabled(memorySubSystem); + memorySubSystem.setSwapEnabled(isSwapEnabled); } subsystem.setActiveSubSystems(); } @@ -208,6 +210,12 @@ private static void setSubSystemControllerPath(CgroupV1Subsystem subsystem, Stri } + private static boolean getSwapEnabled(CgroupV1MemorySubSystemController controller) { + long retval = getLongValue(controller, "memory.memsw.limit_in_bytes"); + return retval > 0; + } + + private static boolean getHierarchical(CgroupV1MemorySubSystemController controller) { long hierarchical = getLongValue(controller, "memory.use_hierarchy"); return hierarchical > 0; @@ -438,10 +446,16 @@ public long getTcpMemoryUsage() { } public long getMemoryAndSwapFailCount() { + if (!memory.isSwapEnabled()) { + return getMemoryFailCount(); + } return getLongValue(memory, "memory.memsw.failcnt"); } public long getMemoryAndSwapLimit() { + if (!memory.isSwapEnabled()) { + return getMemoryLimit(); + } long retval = getLongValue(memory, "memory.memsw.limit_in_bytes"); if (retval > CgroupV1SubsystemController.UNLIMITED_MIN) { if (memory.isHierarchical()) { @@ -457,10 +471,16 @@ public long getMemoryAndSwapLimit() { } public long getMemoryAndSwapMaxUsage() { + if (!memory.isSwapEnabled()) { + return getMemoryMaxUsage(); + } return getLongValue(memory, "memory.memsw.max_usage_in_bytes"); } public long getMemoryAndSwapUsage() { + if (!memory.isSwapEnabled()) { + return getMemoryUsage(); + } return getLongValue(memory, "memory.memsw.usage_in_bytes"); } diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 870440565915d..d8efdafc8d8e8 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -86,7 +86,6 @@ runtime/cds/DeterministicDump.java 8253495 generic-all runtime/cds/serviceability/ReplaceCriticalClassesForSubgraphs.java 8253081 generic-all runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64 runtime/ReservedStack/ReservedStackTest.java 8231031 generic-all -containers/docker/TestMemoryAwareness.java 8250984 linux-5.4.0-1019-oracle ############################################################################# diff --git a/test/hotspot/jtreg/containers/cgroup/PlainRead.java b/test/hotspot/jtreg/containers/cgroup/PlainRead.java index e0c4a7e613aff..74cf1cbff04b7 100644 --- a/test/hotspot/jtreg/containers/cgroup/PlainRead.java +++ b/test/hotspot/jtreg/containers/cgroup/PlainRead.java @@ -45,7 +45,7 @@ static public void noMatch(OutputAnalyzer oa, String what, String value) { oa.shouldNotMatch("^.*" + what + " *" + value + ".*$"); } - static final String good_value = "(\\d+|-1|Unlimited)"; + static final String good_value = "(\\d+|-1|-2|Unlimited)"; static final String bad_value = "(failed)"; static final String[] variables = {"Memory Limit is:", "CPU Shares is:", "CPU Quota is:", "CPU Period is:", "active_processor_count:"}; diff --git a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java index cde1dde96a662..e261eebd66192 100644 --- a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java +++ b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java @@ -153,18 +153,24 @@ private static void testOperatingSystemMXBeanAwareness(String memoryAllocation, out.shouldHaveExitValue(0) .shouldContain("Checking OperatingSystemMXBean") .shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory) - .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+") .shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + expectedMemory) .shouldMatch("OperatingSystemMXBean\\.getFreeMemorySize: [1-9][0-9]+") - .shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+"); - // in case of warnings like : "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap." - // the getTotalSwapSpaceSize returns the system values as the container setup isn't supported in that case. + .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+"); + + // in case of warnings like : "Your kernel does not support swap limit capabilities + // or the cgroup is not mounted. Memory limited without swap." + // the getTotalSwapSpaceSize and getFreeSwapSpaceSize return the system + // values as the container setup isn't supported in that case. try { out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap); } catch(RuntimeException ex) { - out.shouldMatch("OperatingSystemMXBean.getTotalSwapSpaceSize: [1-9][0-9]+"); - out.shouldContain("Metrics.getMemoryLimit() == " + expectedMemory); - out.shouldContain("Metrics.getMemoryAndSwapLimit() == -1"); + out.shouldMatch("OperatingSystemMXBean.getTotalSwapSpaceSize: [0-9]+"); + } + + try { + out.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+"); + } catch(RuntimeException ex) { + out.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: 0"); } } diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 602ea3cb1506c..1dea98953da53 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -905,8 +905,6 @@ jdk/jfr/event/os/TestThreadContextSwitches.java 8247776 windows- # jdk_internal -jdk/internal/platform/docker/TestDockerMemoryMetrics.java 8250984 linux-5.4.0-1019-oracle - ############################################################################ # jdk_jpackage diff --git a/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java b/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java index 57f5b2a705660..f170458893c1d 100644 --- a/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java +++ b/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java @@ -66,34 +66,42 @@ private static void testMemoryLimit(String value) { } private static void testMemoryFailCount() { - long count = Metrics.systemMetrics().getMemoryFailCount(); - - // Allocate 512M of data - byte[][] bytes = new byte[64][]; - boolean atLeastOneAllocationWorked = false; - for (int i = 0; i < 64; i++) { - try { - bytes[i] = new byte[8 * 1024 * 1024]; - atLeastOneAllocationWorked = true; - // Break out as soon as we see an increase in failcount - // to avoid getting killed by the OOM killer. - if (Metrics.systemMetrics().getMemoryFailCount() > count) { + long memAndSwapLimit = Metrics.systemMetrics().getMemoryAndSwapLimit(); + long memLimit = Metrics.systemMetrics().getMemoryLimit(); + + // We need swap to execute this test or will SEGV + if (memAndSwapLimit <= memLimit) { + System.out.println("No swap memory limits, test case skipped"); + } else { + long count = Metrics.systemMetrics().getMemoryFailCount(); + + // Allocate 512M of data + byte[][] bytes = new byte[64][]; + boolean atLeastOneAllocationWorked = false; + for (int i = 0; i < 64; i++) { + try { + bytes[i] = new byte[8 * 1024 * 1024]; + atLeastOneAllocationWorked = true; + // Break out as soon as we see an increase in failcount + // to avoid getting killed by the OOM killer. + if (Metrics.systemMetrics().getMemoryFailCount() > count) { + break; + } + } catch (Error e) { // OOM error break; } - } catch (Error e) { // OOM error - break; } - } - if (!atLeastOneAllocationWorked) { - System.out.println("Allocation failed immediately. Ignoring test!"); - return; - } - // Be sure bytes allocations don't get optimized out - System.out.println("DEBUG: Bytes allocation length 1: " + bytes[0].length); - if (Metrics.systemMetrics().getMemoryFailCount() <= count) { - throw new RuntimeException("Memory fail count : new : [" - + Metrics.systemMetrics().getMemoryFailCount() + "]" - + ", old : [" + count + "]"); + if (!atLeastOneAllocationWorked) { + System.out.println("Allocation failed immediately. Ignoring test!"); + return; + } + // Be sure bytes allocations don't get optimized out + System.out.println("DEBUG: Bytes allocation length 1: " + bytes[0].length); + if (Metrics.systemMetrics().getMemoryFailCount() <= count) { + throw new RuntimeException("Memory fail count : new : [" + + Metrics.systemMetrics().getMemoryFailCount() + "]" + + ", old : [" + count + "]"); + } } System.out.println("TEST PASSED!!!"); } @@ -131,10 +139,12 @@ private static void testKernelMemoryLimit(String value) { private static void testMemoryAndSwapLimit(String memory, String memAndSwap) { long expectedMem = getMemoryValue(memory); long expectedMemAndSwap = getMemoryValue(memAndSwap); + long actualMemAndSwap = Metrics.systemMetrics().getMemoryAndSwapLimit(); if (expectedMem != Metrics.systemMetrics().getMemoryLimit() - || expectedMemAndSwap != Metrics.systemMetrics().getMemoryAndSwapLimit()) { - System.err.println("Memory and swap limit not equal, expected : [" + || (expectedMemAndSwap != actualMemAndSwap + && expectedMem != actualMemAndSwap)) { + throw new RuntimeException("Memory and swap limit not equal, expected : [" + expectedMem + ", " + expectedMemAndSwap + "]" + ", got : [" + Metrics.systemMetrics().getMemoryLimit() + ", " + Metrics.systemMetrics().getMemoryAndSwapLimit() + "]"); diff --git a/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java b/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java index 0c16b07449f16..6239a6de76958 100644 --- a/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java +++ b/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java @@ -293,29 +293,33 @@ public void testMemorySubsystem() { } // Memory and Swap - oldVal = metrics.getMemoryAndSwapFailCount(); - newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.failcnt"); - if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { - fail(Controller.MEMORY, "memory.memsw.failcnt", oldVal, newVal); - } - oldVal = metrics.getMemoryAndSwapLimit(); - newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes"); - newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; - if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { - fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal); - } + // Skip swap tests if no swap is configured. + if (metrics.getMemoryAndSwapLimit() > metrics.getMemoryLimit()) { + oldVal = metrics.getMemoryAndSwapFailCount(); + newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.failcnt"); + if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { + fail(Controller.MEMORY, "memory.memsw.failcnt", oldVal, newVal); + } - oldVal = metrics.getMemoryAndSwapMaxUsage(); - newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.max_usage_in_bytes"); - if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { - fail(Controller.MEMORY, "memory.memsw.max_usage_in_bytes", oldVal, newVal); - } + oldVal = metrics.getMemoryAndSwapLimit(); + newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes"); + newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal; + if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { + fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal); + } - oldVal = metrics.getMemoryAndSwapUsage(); - newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.usage_in_bytes"); - if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { - fail(Controller.MEMORY, "memory.memsw.usage_in_bytes", oldVal, newVal); + oldVal = metrics.getMemoryAndSwapMaxUsage(); + newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.max_usage_in_bytes"); + if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { + fail(Controller.MEMORY, "memory.memsw.max_usage_in_bytes", oldVal, newVal); + } + + oldVal = metrics.getMemoryAndSwapUsage(); + newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.usage_in_bytes"); + if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { + fail(Controller.MEMORY, "memory.memsw.usage_in_bytes", oldVal, newVal); + } } oldVal = metrics.getMemorySoftLimit(); From 9150b902d5c9d678b940f015c6fab8eb7d51c262 Mon Sep 17 00:00:00 2001 From: "Daniel D. Daugherty" Date: Fri, 25 Sep 2020 19:38:15 +0000 Subject: [PATCH 21/79] 8253659: ProblemList sun/security/ec/TestEC.java on linux-aarch64 Reviewed-by: iklam --- test/jdk/ProblemList.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 1dea98953da53..56e8d3f291d27 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -42,7 +42,7 @@ # List items are testnames followed by labels, all MUST BE commented # as to why they are here and use a label: # generic-all Problems on all platforms -# generic-ARCH Where ARCH is one of: x64, i586, ppc64, ppc64le, s390x etc. +# generic-ARCH Where ARCH is one of: x64, i586, ppc64, ppc64le, s390x, aarch64 etc. # OSNAME-all Where OSNAME is one of: linux, windows, macosx, aix # OSNAME-ARCH Specific on to one OSNAME and ARCH, e.g. macosx-x64 # OSNAME-REV Specific on to one OSNAME and REV, e.g. macosx-10.7.4 @@ -704,6 +704,7 @@ javax/security/auth/kerberos/KerberosTixDateTest.java 8039280 generic- sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 generic-all sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all +sun/security/ec/TestEC.java 8253637 linux-aarch64 ############################################################################ From 0e855fe5fac8a9ade3da4b1eeda4111966f39f16 Mon Sep 17 00:00:00 2001 From: Hai-May Chao Date: Fri, 25 Sep 2020 19:47:15 +0000 Subject: [PATCH 22/79] 8252377: Incorrect encoding for EC AlgorithmIdentifier Reviewed-by: weijun --- .../sun/security/x509/AlgorithmId.java | 27 ++++- .../x509/AlgorithmId/OmitAlgIdParam.java | 99 +++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test/jdk/sun/security/x509/AlgorithmId/OmitAlgIdParam.java diff --git a/src/java.base/share/classes/sun/security/x509/AlgorithmId.java b/src/java.base/share/classes/sun/security/x509/AlgorithmId.java index b9b96b31c918c..d9e46d9890741 100644 --- a/src/java.base/share/classes/sun/security/x509/AlgorithmId.java +++ b/src/java.base/share/classes/sun/security/x509/AlgorithmId.java @@ -207,9 +207,20 @@ public void derEncode (OutputStream out) throws IOException { bytes.putNull(); }*/ if (algid.equals(RSASSA_PSS_oid) || algid.equals(ed448_oid) - || algid.equals(ed25519_oid)) { + || algid.equals(ed25519_oid) + || algid.equals(x448_oid) + || algid.equals(x25519_oid) + || algid.equals(SHA224withECDSA_oid) + || algid.equals(SHA256withECDSA_oid) + || algid.equals(SHA384withECDSA_oid) + || algid.equals(SHA512withECDSA_oid)) { // RFC 4055 3.3: when an RSASSA-PSS key does not require // parameter validation, field is absent. + // RFC 8410 3: for id-X25519, id-X448, id-Ed25519, and + // id-Ed448, the parameters must be absent. + // RFC 5758 3.2: the encoding must omit the parameters field + // for ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384 + // and ecdsa-with-SHA512. } else { bytes.putNull(); } @@ -644,6 +655,20 @@ private static ConcurrentHashMap collectOIDAliases() { public static final ObjectIdentifier ed448_oid = ObjectIdentifier.of(KnownOIDs.Ed448); + public static final ObjectIdentifier x25519_oid = + ObjectIdentifier.of(KnownOIDs.X25519); + public static final ObjectIdentifier x448_oid = + ObjectIdentifier.of(KnownOIDs.X448); + + public static final ObjectIdentifier SHA224withECDSA_oid = + ObjectIdentifier.of(KnownOIDs.SHA224withECDSA); + public static final ObjectIdentifier SHA256withECDSA_oid = + ObjectIdentifier.of(KnownOIDs.SHA256withECDSA); + public static final ObjectIdentifier SHA384withECDSA_oid = + ObjectIdentifier.of(KnownOIDs.SHA384withECDSA); + public static final ObjectIdentifier SHA512withECDSA_oid = + ObjectIdentifier.of(KnownOIDs.SHA512withECDSA); + /** * Creates a signature algorithm name from a digest algorithm * name and a encryption algorithm name. diff --git a/test/jdk/sun/security/x509/AlgorithmId/OmitAlgIdParam.java b/test/jdk/sun/security/x509/AlgorithmId/OmitAlgIdParam.java new file mode 100644 index 0000000000000..bdbfe96201cb4 --- /dev/null +++ b/test/jdk/sun/security/x509/AlgorithmId/OmitAlgIdParam.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2020, 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 8252377 + * @library /test/lib + * @modules java.base/sun.security.util + * java.base/sun.security.x509 + * @summary The AlgorithmIdentifier for ECDSA should omit the parameters field + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.SecurityTools; +import jdk.test.lib.process.OutputAnalyzer; +import static jdk.test.lib.security.DerUtils.*; + +import java.io.File; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import sun.security.util.*; + +public class OmitAlgIdParam { + + public static void main(String[] args) throws Exception { + keytool("-genkeypair -keyalg ec -dname CN=EC1 -alias ecsha224 " + + "-sigalg SHA224withECDSA -keystore ks -storepass changeit"); + + keytool("-genkeypair -keyalg ec -dname CN=EC2 -alias ecsha256 " + + "-sigalg SHA256withECDSA -keystore ks -storepass changeit"); + + keytool("-genkeypair -keyalg ec -dname CN=EC3 -alias ecsha384 " + + "-sigalg SHA384withECDSA -keystore ks -storepass changeit"); + + keytool("-genkeypair -keyalg ec -dname CN=EC4 -alias ecsha512 " + + "-sigalg SHA512withECDSA -keystore ks -storepass changeit"); + + KeyStore kstore = KeyStore.getInstance( + new File("ks"), "changeit".toCharArray()); + + // SHA224withECDSA + checkAlgId(kstore, "ecsha224", "SHA224withECDSA", + ObjectIdentifier.of(KnownOIDs.SHA224withECDSA)); + + // SHA256withECDSA + checkAlgId(kstore, "ecsha256", "SHA256withECDSA", + ObjectIdentifier.of(KnownOIDs.SHA256withECDSA)); + + // SHA384withECDSA + checkAlgId(kstore, "ecsha384", "SHA384withECDSA", + ObjectIdentifier.of(KnownOIDs.SHA384withECDSA)); + + // SHA512withECDSA + checkAlgId(kstore, "ecsha512", "SHA512withECDSA", + ObjectIdentifier.of(KnownOIDs.SHA512withECDSA)); + } + + private static void checkAlgId(KeyStore ks, String alias, String alg, + ObjectIdentifier oid) throws Exception { + X509Certificate cert = (X509Certificate)ks.getCertificate(alias); + System.out.println("SigAlgName = " + cert.getSigAlgName()); + + Asserts.assertEQ(cert.getPublicKey().getAlgorithm(), "EC"); + Asserts.assertEQ(cert.getSigAlgName(), alg); + + byte[] data = cert.getEncoded(); + // Parameters field in the specified AlgorithmIdentifier should be omitted + // Checking the first signature AlgorithmIdentifier in the cert + checkAlg(data, "020", oid); + shouldNotExist(data, "021"); + // Checking the second signature AlgorithmIdentifier in the cert + checkAlg(data, "10", oid); + shouldNotExist(data, "11"); + } + + static OutputAnalyzer keytool(String cmd) throws Exception { + return SecurityTools.keytool(cmd).shouldHaveExitValue(0); + } +} From b159e4ed9eb67691af436282e39660fa7073fe42 Mon Sep 17 00:00:00 2001 From: Andy Herrick Date: Fri, 25 Sep 2020 20:22:38 +0000 Subject: [PATCH 23/79] =?UTF-8?q?8253149:=20Building=20an=20installer=20fr?= =?UTF-8?q?om=20invalid=20app=20image=20fails=20on=20Window=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: asemenyuk, almatvee, kizune --- .../internal/LinuxPackageBundler.java | 7 ++++- .../resources/LinuxResources.properties | 2 ++ .../resources/LinuxResources_ja.properties | 2 ++ .../resources/LinuxResources_zh_CN.properties | 2 ++ .../jpackage/internal/AppImageFile.java | 9 ++++++ .../resources/MainResources.properties | 2 ++ .../resources/MainResources_ja.properties | 2 ++ .../resources/MainResources_zh_CN.properties | 2 ++ .../jpackage/internal/WinMsiBundler.java | 4 ++- .../jdk/jpackage/test/LinuxHelper.java | 16 ++++++---- .../jpackage/share/AppImagePackageTest.java | 30 +++++++++++++++++++ 11 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java index a10119491bc84..5d67234180aef 100644 --- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java +++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.nio.file.InvalidPathException; import java.nio.file.Path; +import java.nio.file.Files; import java.text.MessageFormat; import java.util.Collections; import java.util.HashMap; @@ -182,13 +183,17 @@ private List getListOfNeededPackages( } final List neededLibPackages; - if (withFindNeededPackages) { + if (withFindNeededPackages && Files.exists(thePackage.sourceRoot())) { LibProvidersLookup lookup = new LibProvidersLookup(); initLibProvidersLookup(params, lookup); neededLibPackages = lookup.execute(thePackage.sourceRoot()); } else { neededLibPackages = Collections.emptyList(); + if (!Files.exists(thePackage.sourceRoot())) { + Log.info(I18N.getString("warning.foreign-app-image")); + + } } // Merge all package lists together. diff --git a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources.properties b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources.properties index 9ad1b2d6a4bb7..0474234e17128 100644 --- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources.properties +++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources.properties @@ -61,6 +61,8 @@ message.ldd-not-available=ldd command not found. Package dependencies will not b message.deb-ldd-not-available.advice=Install "libc-bin" DEB package to get ldd. message.rpm-ldd-not-available.advice=Install "glibc-common" RPM package to get ldd. +warning.foreign-app-image=Warning: app-image dir not generated by jpackage. + error.unexpected-package-property=Expected value of "{0}" property is [{1}]. Actual value in output package is [{2}]. Looks like custom "{3}" file from resource directory contained hard coded value of "{0}" property error.unexpected-package-property.advice=Use [{0}] pattern string instead of hard coded value [{1}] of {2} property in custom "{3}" file error.unexpected-default-package-property.advice=Don't explicitly set value of {0} property in custom "{1}" file diff --git a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_ja.properties b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_ja.properties index 5c751db4468da..48a0f3438a930 100644 --- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_ja.properties +++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_ja.properties @@ -40,6 +40,8 @@ resource.menu-shortcut-descriptor=\u30E1\u30CB\u30E5\u30FC\u30FB\u30B7\u30E7\u30 resource.menu-icon=\u30E1\u30CB\u30E5\u30FC\u30FB\u30A2\u30A4\u30B3\u30F3 resource.rpm-spec-file=RPM\u4ED5\u69D8\u30D5\u30A1\u30A4\u30EB +warning.foreign-app-image=Warning: app-image dir not generated by jpackage. + error.tool-not-found.advice=\u5FC5\u8981\u306A\u30D1\u30C3\u30B1\u30FC\u30B8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u3066\u304F\u3060\u3055\u3044 error.tool-old-version.advice=\u5FC5\u8981\u306A\u30D1\u30C3\u30B1\u30FC\u30B8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u3066\u304F\u3060\u3055\u3044 diff --git a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_zh_CN.properties b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_zh_CN.properties index c636d584a15c9..52feabd13f42d 100644 --- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_zh_CN.properties +++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/resources/LinuxResources_zh_CN.properties @@ -40,6 +40,8 @@ resource.menu-shortcut-descriptor=\u83DC\u5355\u5FEB\u6377\u65B9\u5F0F\u63CF\u8F resource.menu-icon=\u83DC\u5355\u56FE\u6807 resource.rpm-spec-file=RPM \u89C4\u8303\u6587\u4EF6 +warning.foreign-app-image=Warning: app-image dir not generated by jpackage. + error.tool-not-found.advice=\u8BF7\u5B89\u88C5\u6240\u9700\u7684\u7A0B\u5E8F\u5305 error.tool-old-version.advice=\u8BF7\u5B89\u88C5\u6240\u9700\u7684\u7A0B\u5E8F\u5305 diff --git a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java index 94072561fa72b..d51f40fa825fc 100644 --- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java @@ -27,6 +27,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.NoSuchFileException; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -214,8 +216,15 @@ static List getLauncherNames(Path appImageDir, launchers.addAll(appImageInfo.getAddLauncherNames()); return launchers; } + } catch (NoSuchFileException nsfe) { + // non jpackage generated app-image (no app/.jpackage.xml) + Log.info(MessageFormat.format(I18N.getString( + "warning.foreign-app-image"), appImageDir)); } catch (IOException ioe) { Log.verbose(ioe); + Log.info(MessageFormat.format(I18N.getString( + "warning.invalid-app-image"), appImageDir)); + } launchers.add(APP_NAME.fetchFrom(params)); diff --git a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources.properties b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources.properties index e4e949b688062..37fa371f3e891 100644 --- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources.properties +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources.properties @@ -74,6 +74,8 @@ error.jlink.failed=jlink failed with: {0} error.blocked.option=jlink option [{0}] is not permitted in --jlink-options warning.no.jdk.modules.found=Warning: No JDK Modules found +warning.foreign-app-image=Warning: app-image dir ({0}) not generated by jpackage. +warning.invalid-app-image=Warning: cannot parse .jpackage.xml in app-image dir ({0}) MSG_BundlerFailed=Error: Bundler "{1}" ({0}) failed to produce a package MSG_BundlerConfigException=Bundler {0} skipped because of a configuration problem: {1} \n\ diff --git a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_ja.properties b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_ja.properties index fbdee54023b23..62ffe2d521ea5 100644 --- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_ja.properties +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_ja.properties @@ -74,6 +74,8 @@ error.jlink.failed=jlink\u304C\u6B21\u3067\u5931\u6557\u3057\u307E\u3057\u305F: error.blocked.option=jlink\u30AA\u30D7\u30B7\u30E7\u30F3[{0}]\u306F--jlink-options\u3067\u306F\u8A31\u53EF\u3055\u308C\u307E\u305B\u3093 warning.no.jdk.modules.found=\u8B66\u544A: JDK\u30E2\u30B8\u30E5\u30FC\u30EB\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093 +warning.foreign-app-image=Warning: app-image dir ({0}) not generated by jpackage. +warning.invalid-app-image=Warning: cannot parse .jpackage.xml in app-image dir ({0}) MSG_BundlerFailed=\u30A8\u30E9\u30FC: \u30D0\u30F3\u30C9\u30E9"{1}" ({0})\u304C\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u751F\u6210\u306B\u5931\u6557\u3057\u307E\u3057\u305F MSG_BundlerConfigException=\u69CB\u6210\u306E\u554F\u984C\u306E\u305F\u3081\u3001\u30D0\u30F3\u30C9\u30E9{0}\u304C\u30B9\u30AD\u30C3\u30D7\u3055\u308C\u307E\u3057\u305F: {1} \n\u6B21\u306E\u4FEE\u6B63\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044: {2} diff --git a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_zh_CN.properties b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_zh_CN.properties index ac17730e530f7..41e7e09fbb41b 100644 --- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_zh_CN.properties +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/resources/MainResources_zh_CN.properties @@ -74,6 +74,8 @@ error.jlink.failed=jlink \u5931\u8D25\uFF0C\u51FA\u73B0 {0} error.blocked.option=\u4E0D\u5141\u8BB8\u5728 --jlink-options \u4E2D\u4F7F\u7528 jlink \u9009\u9879 [{0}] warning.no.jdk.modules.found=\u8B66\u544A: \u672A\u627E\u5230 JDK \u6A21\u5757 +warning.foreign-app-image=Warning: app-image dir ({0}) not generated by jpackage. +warning.invalid-app-image=Warning: cannot parse .jpackage.xml in app-image dir ({0}) MSG_BundlerFailed=\u9519\u8BEF\uFF1A\u6253\u5305\u7A0B\u5E8F "{1}" ({0}) \u65E0\u6CD5\u751F\u6210\u7A0B\u5E8F\u5305 MSG_BundlerConfigException=\u7531\u4E8E\u914D\u7F6E\u95EE\u9898, \u8DF3\u8FC7\u4E86\u6253\u5305\u7A0B\u5E8F{0}: {1} \n\u4FEE\u590D\u5EFA\u8BAE: {2} diff --git a/src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java b/src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java index 91444580d059b..bc684368c6192 100644 --- a/src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java +++ b/src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java @@ -406,7 +406,9 @@ private Map prepareMainProjectFile( data.put("JpAppDescription", DESCRIPTION.fetchFrom(params)); data.put("JpAppVendor", VENDOR.fetchFrom(params)); data.put("JpAppVersion", PRODUCT_VERSION.fetchFrom(params)); - data.put("JpIcon", installerIcon.toString()); + if (Files.exists(installerIcon)) { + data.put("JpIcon", installerIcon.toString()); + } final Path configDir = CONFIG_ROOT.fetchFrom(params); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java index f7906406f2f5b..9bfa146aa2415 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java @@ -233,7 +233,9 @@ static long getInstalledPackageSizeKB(JPackageCommand cmd) { "Installed-Size")); case LINUX_RPM: - return Long.parseLong(getRpmBundleProperty(packageFile, "Size")) >> 10; + String size = getRpmBundleProperty(packageFile, "Size"); + return (Long.parseLong(size) + 1023L) >> 10; // in KB rounded up + } return 0; @@ -254,10 +256,10 @@ static String getRpmBundleProperty(Path bundle, String fieldName) { static void verifyPackageBundleEssential(JPackageCommand cmd) { String packageName = LinuxHelper.getPackageName(cmd); - TKit.assertNotEquals(0L, LinuxHelper.getInstalledPackageSizeKB( - cmd), String.format( - "Check installed size of [%s] package in KB is not zero", - packageName)); + Long packageSize = LinuxHelper.getInstalledPackageSizeKB(cmd); + TKit.trace("InstalledPackageSize: " + packageSize); + TKit.assertNotEquals(0L, packageSize, String.format( + "Check installed size of [%s] package in not zero", packageName)); final boolean checkPrerequisites; if (cmd.isRuntime()) { @@ -270,7 +272,9 @@ static void verifyPackageBundleEssential(JPackageCommand cmd) { checkPrerequisites = expectedCriticalRuntimePaths.equals( actualCriticalRuntimePaths); } else { - checkPrerequisites = true; + // AppImagePackageTest.testEmpty() will have no dependencies, + // but will have more then 0 and less than 1K content size. + checkPrerequisites = packageSize > 1; } List prerequisites = LinuxHelper.getPrerequisitePackages(cmd); diff --git a/test/jdk/tools/jpackage/share/AppImagePackageTest.java b/test/jdk/tools/jpackage/share/AppImagePackageTest.java index 979aaea0ce94c..2ee998af4472b 100644 --- a/test/jdk/tools/jpackage/share/AppImagePackageTest.java +++ b/test/jdk/tools/jpackage/share/AppImagePackageTest.java @@ -22,9 +22,14 @@ */ import java.nio.file.Path; +import java.nio.file.Files; +import java.io.IOException; +import java.util.List; import jdk.jpackage.test.TKit; import jdk.jpackage.test.JPackageCommand; import jdk.jpackage.test.PackageTest; +import jdk.jpackage.test.PackageType; +import jdk.jpackage.test.RunnablePackageTest.Action; import jdk.jpackage.test.Annotations.Test; /** @@ -61,4 +66,29 @@ public static void test() { cmd.removeArgumentWithValue("--input"); }).addBundleDesktopIntegrationVerifier(false).run(); } + + @Test + public static void testEmpty() throws IOException { + final String name = "EmptyAppImagePackageTest"; + final String imageName = name + (TKit.isOSX() ? ".app" : ""); + Path appImageDir = TKit.createTempDirectory(null).resolve(imageName); + + Files.createDirectories(appImageDir.resolve("bin")); + Path libDir = Files.createDirectories(appImageDir.resolve("lib")); + TKit.createTextFile(libDir.resolve("README"), + List.of("This is some arbitrary text for the README file\n")); + + new PackageTest() + .addInitializer(cmd -> { + cmd.addArguments("--app-image", appImageDir); + cmd.removeArgumentWithValue("--input"); + + // on mac, with --app-image and without --mac-package-identifier, + // will try to infer it from the image, so foreign image needs it. + if (TKit.isOSX()) { + cmd.addArguments("--mac-package-identifier", name); + } + }).run(new Action[] { Action.CREATE, Action.UNPACK }); + // default: {CREATE, UNPACK, VERIFY}, but we can't verify foreign image + } } From 5a57945f1afe58ac7757559587bc7f799a4ab8f2 Mon Sep 17 00:00:00 2001 From: Alexander Matveev Date: Fri, 25 Sep 2020 23:02:00 +0000 Subject: [PATCH 24/79] 8231591: [TESTBUG] Create additional two phase jpackage tests Reviewed-by: asemenyuk, herrick --- .../jpackage/internal/DesktopIntegration.java | 32 ++++++- .../jdk/jpackage/test/AdditionalLauncher.java | 2 + .../jdk/jpackage/test/PackageTest.java | 20 +++- .../jdk/jpackage/test/WindowsHelper.java | 14 +-- .../share/MultiLauncherTwoPhaseTest.java | 92 +++++++++++++++++++ 5 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 test/jdk/tools/jpackage/share/MultiLauncherTwoPhaseTest.java diff --git a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java index 41246d4c4ee0a..9396bfb93c336 100644 --- a/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java +++ b/src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java @@ -46,6 +46,7 @@ import javax.imageio.ImageIO; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import jdk.incubator.jpackage.internal.Arguments.CLIOptions; import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.DEFAULT_ICON; import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.ICON_PNG; import static jdk.incubator.jpackage.internal.OverridableResource.createResource; @@ -54,6 +55,7 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.DESCRIPTION; import static jdk.incubator.jpackage.internal.StandardBundlerParam.FILE_ASSOCIATIONS; import static jdk.incubator.jpackage.internal.StandardBundlerParam.ICON; +import static jdk.incubator.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE; /** * Helper to create files for desktop integration. @@ -133,12 +135,32 @@ private DesktopIntegration(PlatformPackage thePackage, createDataForDesktopFile(params)); nestedIntegrations = new ArrayList<>(); - for (var launcherParams : launchers) { - launcherParams = AddLauncherArguments.merge(params, launcherParams, + // Read launchers information from predefine app image + if (launchers.isEmpty() && + PREDEFINED_APP_IMAGE.fetchFrom(params) != null) { + List launcherPaths = AppImageFile.getLauncherNames( + PREDEFINED_APP_IMAGE.fetchFrom(params), params); + if (!launcherPaths.isEmpty()) { + launcherPaths.remove(0); // Remove main launcher + } + for (var launcherPath : launcherPaths) { + Map launcherParams = new HashMap<>(); + Arguments.putUnlessNull(launcherParams, CLIOptions.NAME.getId(), + launcherPath); + launcherParams = AddLauncherArguments.merge(params, launcherParams, ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(), - FILE_ASSOCIATIONS.getID()); - nestedIntegrations.add(new DesktopIntegration(thePackage, - launcherParams, params)); + FILE_ASSOCIATIONS.getID(), PREDEFINED_APP_IMAGE.getID()); + nestedIntegrations.add(new DesktopIntegration(thePackage, + launcherParams, params)); + } + } else { + for (var launcherParams : launchers) { + launcherParams = AddLauncherArguments.merge(params, launcherParams, + ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(), + FILE_ASSOCIATIONS.getID()); + nestedIntegrations.add(new DesktopIntegration(thePackage, + launcherParams, params)); + } } } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java index ee28452c50039..6aaa1375d0193 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java @@ -32,6 +32,7 @@ import java.util.Optional; import java.util.function.BiConsumer; import java.util.stream.Stream; +import jdk.incubator.jpackage.internal.ApplicationLayout; import jdk.jpackage.test.Functional.ThrowingBiConsumer; public final class AdditionalLauncher { @@ -110,6 +111,7 @@ public void applyTo(JPackageCommand cmd) { } public void applyTo(PackageTest test) { + test.addLauncherName(name); test.addInitializer(this::initialize); test.addInstallVerifier(this::verify); } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java index 5f09859062bae..0acb196c2bac7 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java @@ -317,6 +317,11 @@ public PackageTest configureHelloApp(String javaAppDesc) { return this; } + public PackageTest addLauncherName(String name) { + launcherNames.add(name); + return this; + } + public final static class Group extends RunnablePackageTest { public Group(PackageTest... tests) { handlers = Stream.of(tests) @@ -556,7 +561,12 @@ private void verifyPackageInstalled(JPackageCommand cmd) { if (PackageType.WINDOWS.contains(cmd.packageType()) && !cmd.isPackageUnpacked( "Not verifying desktop integration")) { - new WindowsHelper.DesktopIntegrationVerifier(cmd); + // Check main launcher + new WindowsHelper.DesktopIntegrationVerifier(cmd, null); + // Check additional launchers + launcherNames.forEach(name -> { + new WindowsHelper.DesktopIntegrationVerifier(cmd, name); + }); } } cmd.assertAppLayout(); @@ -571,7 +581,12 @@ private void verifyPackageUninstalled(JPackageCommand cmd) { TKit.assertPathExists(cmd.appLauncherPath(), false); if (PackageType.WINDOWS.contains(cmd.packageType())) { - new WindowsHelper.DesktopIntegrationVerifier(cmd); + // Check main launcher + new WindowsHelper.DesktopIntegrationVerifier(cmd, null); + // Check additional launchers + launcherNames.forEach(name -> { + new WindowsHelper.DesktopIntegrationVerifier(cmd, name); + }); } } @@ -618,6 +633,7 @@ private static Map createDefaultPackageHandlers() private Map handlers; private Set namedInitializers; private Map packageHandlers; + private final List launcherNames = new ArrayList(); private final static File BUNDLE_OUTPUT_DIR; diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java index 329627307ea78..debba096364ed 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java @@ -134,16 +134,17 @@ private static boolean isUserLocalInstall(JPackageCommand cmd) { static class DesktopIntegrationVerifier { - DesktopIntegrationVerifier(JPackageCommand cmd) { + DesktopIntegrationVerifier(JPackageCommand cmd, String name) { cmd.verifyIsOfType(PackageType.WINDOWS); this.cmd = cmd; + this.name = (name == null ? cmd.name() : name); verifyStartMenuShortcut(); verifyDesktopShortcut(); verifyFileAssociationsRegistry(); } private void verifyDesktopShortcut() { - boolean appInstalled = cmd.appLauncherPath().toFile().exists(); + boolean appInstalled = cmd.appLauncherPath(name).toFile().exists(); if (cmd.hasArgument("--win-shortcut")) { if (isUserLocalInstall(cmd)) { verifyUserLocalDesktopShortcut(appInstalled); @@ -159,7 +160,7 @@ private void verifyDesktopShortcut() { } private Path desktopShortcutPath() { - return Path.of(cmd.name() + ".lnk"); + return Path.of(name + ".lnk"); } private void verifyShortcut(Path path, boolean exists) { @@ -183,7 +184,7 @@ private void verifyUserLocalDesktopShortcut(boolean exists) { } private void verifyStartMenuShortcut() { - boolean appInstalled = cmd.appLauncherPath().toFile().exists(); + boolean appInstalled = cmd.appLauncherPath(name).toFile().exists(); if (cmd.hasArgument("--win-menu")) { if (isUserLocalInstall(cmd)) { verifyUserLocalStartMenuShortcut(appInstalled); @@ -200,7 +201,7 @@ private void verifyStartMenuShortcut() { private Path startMenuShortcutPath() { return Path.of(cmd.getArgumentValue("--win-menu-group", - () -> "Unknown"), cmd.name() + ".lnk"); + () -> "Unknown"), name + ".lnk"); } private void verifyStartMenuShortcut(Path shortcutsRoot, boolean exists) { @@ -228,7 +229,7 @@ private void verifyFileAssociationsRegistry() { } private void verifyFileAssociationsRegistry(Path faFile) { - boolean appInstalled = cmd.appLauncherPath().toFile().exists(); + boolean appInstalled = cmd.appLauncherPath(name).toFile().exists(); try { TKit.trace(String.format( "Get file association properties from [%s] file", @@ -279,6 +280,7 @@ private void verifyFileAssociations(boolean exists, String suffix, } private final JPackageCommand cmd; + private final String name; } private static String queryRegistryValue(String keyPath, String valueName) { diff --git a/test/jdk/tools/jpackage/share/MultiLauncherTwoPhaseTest.java b/test/jdk/tools/jpackage/share/MultiLauncherTwoPhaseTest.java new file mode 100644 index 0000000000000..423ea5b960813 --- /dev/null +++ b/test/jdk/tools/jpackage/share/MultiLauncherTwoPhaseTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020, 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.nio.file.Path; +import java.io.IOException; +import jdk.jpackage.test.AdditionalLauncher; +import jdk.jpackage.test.PackageTest; +import jdk.jpackage.test.PackageType; +import jdk.jpackage.test.TKit; +import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.JPackageCommand; + +/** + * Test multiple launchers in two phases. First test creates app image and then + * creates installer from this image. Output of the test should be + * MultiLauncherTwoPhaseTest*.* installer. The output installer should be basic + * installer with 3 launcher MultiLauncherTwoPhaseTest, bar and foo. On Windows + * we should have start menu integration under MultiLauncherTwoPhaseTest and + * desktop shortcuts for all 3 launchers. Linux should also create shortcuts for + * all launchers. + */ + +/* + * @test + * @summary Multiple launchers in two phases + * @library ../helpers + * @library /test/lib + * @key jpackagePlatformPackage + * @build jdk.jpackage.test.* + * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal + * @compile MultiLauncherTwoPhaseTest.java + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main + * --jpt-run=MultiLauncherTwoPhaseTest + */ + +public class MultiLauncherTwoPhaseTest { + + @Test + public static void test() throws IOException { + Path appimageOutput = TKit.createTempDirectory("appimage"); + + JPackageCommand appImageCmd = JPackageCommand.helloAppImage() + .setArgumentValue("--dest", appimageOutput); + + AdditionalLauncher launcher1 = new AdditionalLauncher("bar"); + launcher1.setDefaultArguments().applyTo(appImageCmd); + + AdditionalLauncher launcher2 = new AdditionalLauncher("foo"); + launcher2.applyTo(appImageCmd); + + PackageTest packageTest = new PackageTest() + .addLauncherName("bar") // Add launchers name for verification + .addLauncherName("foo") + .addRunOnceInitializer(() -> appImageCmd.execute()) + .addBundleDesktopIntegrationVerifier(true) + .addInitializer(cmd -> { + cmd.addArguments("--app-image", appImageCmd.outputBundle()); + cmd.removeArgumentWithValue("--input"); + }) + .forTypes(PackageType.WINDOWS) + .addInitializer(cmd -> { + cmd.addArguments("--win-shortcut", "--win-menu", + "--win-menu-group", "MultiLauncherTwoPhaseTest"); + }) + .forTypes(PackageType.LINUX) + .addInitializer(cmd -> { + cmd.addArguments("--linux-shortcut"); + }); + + packageTest.run(); + } +} From 4167540074fa5670e982d29325a3741e3132e8e1 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Fri, 25 Sep 2020 23:33:42 +0000 Subject: [PATCH 25/79] 8253647: Remove dead code in os::create_thread() on Linux/BSD Reviewed-by: stuefe, dholmes --- src/hotspot/os/bsd/os_bsd.cpp | 7 ------- src/hotspot/os/linux/os_linux.cpp | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index 1a8f0a4558ea6..edf714bb97023 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -782,13 +782,6 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, } - // Aborted due to thread limit being reached - if (state == ZOMBIE) { - thread->set_osthread(NULL); - delete osthread; - return false; - } - // The thread is returned suspended (in state INITIALIZED), // and is started higher up in the call chain assert(state == INITIALIZED, "race condition"); diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 5c610cdf7e9ed..d067a65c3a2c8 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -978,13 +978,6 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, } } - // Aborted due to thread limit being reached - if (state == ZOMBIE) { - thread->set_osthread(NULL); - delete osthread; - return false; - } - // The thread is returned suspended (in state INITIALIZED), // and is started higher up in the call chain assert(state == INITIALIZED, "race condition"); From b66fa8f444cea3d2d166e19fc4da46c2695e7d41 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Sat, 26 Sep 2020 04:12:54 +0000 Subject: [PATCH 26/79] 8253572: [windows] CDS archive may fail to open with long file names 8249943: [TESTBUG] runtime/cds/serviceability/transformRelatedClasses/TransformInterfaceAndImplementor.java Reviewed-by: ccheung, iklam --- src/hotspot/os/windows/os_windows.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 99ed8f22db012..d0d1ee2b5c470 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -4827,15 +4827,25 @@ static int stdinAvailable(int fd, long *pbytes) { char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, char *addr, size_t bytes, bool read_only, bool allow_exec) { + + errno_t err; + wchar_t* wide_path = wide_abs_unc_path(file_name, err); + + if (wide_path == NULL) { + return NULL; + } + HANDLE hFile; char* base; - hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, + hFile = CreateFileW(wide_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { - log_info(os)("CreateFile() failed: GetLastError->%ld.", GetLastError()); + log_info(os)("CreateFileW() failed: GetLastError->%ld.", GetLastError()); + os::free(wide_path); return NULL; } + os::free(wide_path); if (allow_exec) { // CreateFileMapping/MapViewOfFileEx can't map executable memory From ea7c47c1bb51d079aff44b88f94b3fe5c76fbce5 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Sat, 26 Sep 2020 04:15:30 +0000 Subject: [PATCH 27/79] 7179006: [macosx] Print-to-file doesn't work: printing to the default printer instead. Reviewed-by: serb --- .../classes/sun/lwawt/macosx/CPrinterJob.java | 17 +++ .../native/libawt_lwawt/awt/CPrinterJob.m | 30 +++- .../java/awt/print/Dialog/PrintDlgApp.java | 134 ++++++++++-------- .../awt/print/PrinterJob/PrintToFileTest.java | 77 ++++++++++ 4 files changed, 189 insertions(+), 69 deletions(-) create mode 100644 test/jdk/java/awt/print/PrinterJob/PrintToFileTest.java diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 06516e8adb44a..17ab015b11e3d 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -30,6 +30,7 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.print.*; +import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; @@ -37,6 +38,7 @@ import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.standard.Copies; +import javax.print.attribute.standard.Destination; import javax.print.attribute.standard.Media; import javax.print.attribute.standard.MediaPrintableArea; import javax.print.attribute.standard.MediaSize; @@ -251,6 +253,21 @@ private void setPrintToFile(boolean printToFile) { isPrintToFile = printToFile; } + private void setDestinationFile(String dest) { + if (attributes != null && dest != null) { + try { + URI destURI = new URI(dest); + attributes.add(new Destination(destURI)); + destinationAttr = "" + destURI.getSchemeSpecificPart(); + } catch (Exception e) { + } + } + } + + private String getDestinationFile() { + return destinationAttr; + } + @Override public void print(PrintRequestAttributeSet attributes) throws PrinterException { // NOTE: Some of this code is copied from RasterPrinterJob. diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m index 5247d12f6528f..e995da67dcbd5 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -316,21 +316,25 @@ static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject d static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V"); static JNF_MEMBER_CACHE(jm_setPageRangeAttribute, sjc_CPrinterJob, "setPageRangeAttribute", "(IIZ)V"); static JNF_MEMBER_CACHE(jm_setPrintToFile, sjc_CPrinterJob, "setPrintToFile", "(Z)V"); - - if (src.jobDisposition == NSPrintSaveJob) { - JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, true); - } else { - JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, false); - } + static JNF_MEMBER_CACHE(jm_setDestinationFile, sjc_CPrinterJob, "setDestinationFile", "(Ljava/lang/String;)V"); // get the selected printer's name, and set the appropriate PrintService on the Java side NSString *name = [[src printer] name]; jstring printerName = JNFNSToJavaString(env, name); JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName); - NSMutableDictionary* printingDictionary = [src dictionary]; + if (src.jobDisposition == NSPrintSaveJob) { + JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, true); + NSURL *url = [printingDictionary objectForKey:NSPrintJobSavingURL]; + NSString *nsStr = [url absoluteString]; + jstring str = JNFNSToJavaString(env, nsStr); + JNFCallVoidMethod(env, dstPrinterJob, jm_setDestinationFile, str); + } else { + JNFCallVoidMethod(env, dstPrinterJob, jm_setPrintToFile, false); + } + NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies]; if ([nsCopies respondsToSelector:@selector(integerValue)]) { @@ -384,6 +388,8 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); + static JNF_MEMBER_CACHE(jm_getDestinationFile, sjc_CPrinterJob, + "getDestinationFile", "()Ljava/lang/String;"); NSMutableDictionary* printingDictionary = [dst dictionary]; @@ -423,6 +429,16 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj if (page != NULL) { javaPageFormatToNSPrintInfo(env, NULL, page, dst); } + + jstring dest = JNFCallObjectMethod(env, srcPrinterJob, jm_getDestinationFile); + if (dest != NULL) { + [dst setJobDisposition:NSPrintSaveJob]; + NSString *nsDestStr = JNFJavaToNSString(env, dest); + NSURL *nsURL = [NSURL fileURLWithPath:nsDestStr isDirectory:NO]; + [printingDictionary setObject:nsURL forKey:NSPrintJobSavingURL]; + } else { + [dst setJobDisposition:NSPrintSpoolJob]; + } } /* diff --git a/test/jdk/java/awt/print/Dialog/PrintDlgApp.java b/test/jdk/java/awt/print/Dialog/PrintDlgApp.java index 7e98b327eb4c2..3a84eb532f632 100644 --- a/test/jdk/java/awt/print/Dialog/PrintDlgApp.java +++ b/test/jdk/java/awt/print/Dialog/PrintDlgApp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2020, 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,76 +23,86 @@ /* @test - @bug 4865976 7158366 - @summary Pass if it program exits. + @key printer + @bug 4865976 7158366 7179006 + @summary Pass if program exits. @run main/manual PrintDlgApp */ -import java.awt.*; -import java.awt.print.*; -import javax.print.attribute.*; + +import java.io.File; +import java.net.URI; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterJob; +import java.awt.print.PrinterException; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Copies; import javax.print.attribute.standard.Destination; -import java.util.Locale; -import javax.print.*; +public class PrintDlgApp implements Printable { -class PrintDlgApp implements Printable { - /** - * Constructor - */ - public PrintDlgApp() { - super(); - } - /** - * Starts the application. - */ - public static void main(java.lang.String[] args) { - PrintDlgApp pd = new PrintDlgApp(); - PrinterJob pj = PrinterJob.getPrinterJob(); - System.out.println(pj); - PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); - pSet.add(new Copies(1)); - //PageFormat pf = pj.pageDialog(pSet); - PageFormat pf = new PageFormat(); - System.out.println("Setting Printable...pf = "+pf); - if (pf == null) { - return; - } - pj.setPrintable(pd,pf); + public PrintDlgApp() {} - //try { pj.setPrintService(services[0]); } catch(Exception e) { e.printStackTrace(); } - pSet.add(new Destination(new java.io.File("./out.prn").toURI())); - System.out.println("open PrintDialog.."); - for (int i=0; i<2; i++) { - if (pj.printDialog(pSet)) { - try { - System.out.println("About to print the data ..."); - pj.print(pSet); - System.out.println("Printed"); - } - catch (PrinterException pe) { - pe.printStackTrace(); - } - } - } + public static void main(String[] args) { + PrinterJob pj = PrinterJob.getPrinterJob(); + if (pj.getPrintService() == null) { + System.out.println("No printers installed. Skipping test"); + return; + } - } + PrintDlgApp pd = new PrintDlgApp(); + PageFormat pf = new PageFormat(); + pj.setPrintable(pd, pf); + + PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); + pSet.add(new Copies(1)); + + Destination dest = null; + for (int i=0; i<2; i++) { + File file = new File("./out"+i+".prn"); + dest = new Destination(file.toURI()); + pSet.add(dest); + System.out.println("open PrintDialog."); + if (pj.printDialog(pSet)) { + // In case tester changes the destination : + dest = (Destination)pSet.get(Destination.class); + System.out.println("DEST="+dest); + if (dest != null) { + URI uri = dest.getURI(); + file = new File(uri.getSchemeSpecificPart()); + System.out.println("will be checking for file " + file); + } + try { + System.out.println("About to print the data ..."); + pj.print(pSet); + System.out.println("Printed."); + } + catch (PrinterException pe) { + pe.printStackTrace(); + } + } + if (dest != null && !file.exists()) { + throw new RuntimeException("No file created"); + } + } + } - //printable interface - public int print(Graphics g, PageFormat pf, int pi) throws -PrinterException { + public int print(Graphics g, PageFormat pf, int pi) throws PrinterException { - if (pi > 0) { - System.out.println("pi is greater than 0"); - return Printable.NO_SUCH_PAGE; - } - // Simply draw two rectangles - Graphics2D g2 = (Graphics2D)g; - g2.setColor(Color.black); - g2.translate(pf.getImageableX(), pf.getImageableY()); - g2.drawRect(1,1,200,300); - g2.drawRect(1,1,25,25); - System.out.println("print method called "+pi); - return Printable.PAGE_EXISTS; + if (pi > 0) { + return Printable.NO_SUCH_PAGE; } + // Simply draw two rectangles + Graphics2D g2 = (Graphics2D)g; + g2.setColor(Color.black); + g2.translate(pf.getImageableX(), pf.getImageableY()); + g2.drawRect(1,1,200,300); + g2.drawRect(1,1,25,25); + System.out.println("print method called "+pi); + return Printable.PAGE_EXISTS; + } } diff --git a/test/jdk/java/awt/print/PrinterJob/PrintToFileTest.java b/test/jdk/java/awt/print/PrinterJob/PrintToFileTest.java new file mode 100644 index 0000000000000..c3e0e8a0821b9 --- /dev/null +++ b/test/jdk/java/awt/print/PrinterJob/PrintToFileTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020, 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 + * @key printer + * @bug 7179006 + * @summary Confirm printing to file works. +*/ + +import java.io.File; +import java.net.URI; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterJob; +import java.awt.print.PrinterException; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.Destination; + +public class PrintToFileTest implements Printable { + + public PrintToFileTest() {} + + public static void main(String[] args) throws Exception { + PrinterJob pj = PrinterJob.getPrinterJob(); + if (pj.getPrintService() == null) { + System.out.println("No printers installed. Skipping test."); + return; + } + pj.setPrintable(new PrintToFileTest(), new PageFormat()); + PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); + File file = new File("./out.prn"); + pSet.add(new Destination(file.toURI())); + pj.print(pSet); + if (!file.exists()) { + throw new RuntimeException("No file created"); + } + } + + public int print(Graphics g, PageFormat pf, int pi) throws + PrinterException { + + if (pi > 0) { + return Printable.NO_SUCH_PAGE; + } + Graphics2D g2 = (Graphics2D)g; + g2.setColor(Color.black); + g2.translate(pf.getImageableX(), pf.getImageableY()); + g2.drawRect(1,1,200,300); + g2.drawRect(1,1,25,25); + return Printable.PAGE_EXISTS; + } +} From 79904c1fa385b41ad2ea12a183d859c6422d7fa5 Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Sat, 26 Sep 2020 07:01:22 +0000 Subject: [PATCH 28/79] 8252730: jlink does not create reproducible builds on different servers Reviewed-by: mchung, alanb --- .../jlink/internal/ImageFileCreator.java | 14 +-- .../tools/jlink/JLinkReproducible2Test.java | 15 ++- .../tools/jlink/JLinkReproducible3Test.java | 101 ++++++++++++++++++ 3 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 test/jdk/tools/jlink/JLinkReproducible3Test.java diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java index 93625f71b8209..8ec9c3df61b32 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ImageFileCreator.java @@ -262,14 +262,14 @@ public String getString(int id) { return writer.getString(id); } }); - - for (Archive archive : archives) { - String mn = archive.moduleName(); - entriesForModule.get(mn).stream() - .map(e -> new ArchiveEntryResourcePoolEntry(mn, - e.getResourcePoolEntryName(), e)) + archives.stream() + .map(Archive::moduleName) + .sorted() + .flatMap(mn -> + entriesForModule.get(mn).stream() + .map(e -> new ArchiveEntryResourcePoolEntry(mn, + e.getResourcePoolEntryName(), e))) .forEach(resources::add); - } return resources; } diff --git a/test/jdk/tools/jlink/JLinkReproducible2Test.java b/test/jdk/tools/jlink/JLinkReproducible2Test.java index c11025c30fee4..4723bd0eb8f0c 100644 --- a/test/jdk/tools/jlink/JLinkReproducible2Test.java +++ b/test/jdk/tools/jlink/JLinkReproducible2Test.java @@ -32,6 +32,9 @@ * @bug 8241602 * @modules jdk.jlink * java.se + * jdk.management + * jdk.unsupported + * jdk.charsets * @run main JLinkReproducible2Test */ public class JLinkReproducible2Test { @@ -48,7 +51,17 @@ public static void main(String[] args) throws Exception { JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.se", "--output", image2.toString()); if (Files.mismatch(image1.resolve("lib").resolve("modules"), image2.resolve("lib").resolve("modules")) != -1L) { - new RuntimeException("jlink producing inconsistent result"); + throw new RuntimeException("jlink producing inconsistent result"); + } + + Path image3 = Paths.get("./image3"); + Path image4 = Paths.get("./image4"); + + JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image3.toString()); + JLINK_TOOL.run(System.out, System.err, "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image4.toString()); + + if (Files.mismatch(image3.resolve("lib").resolve("modules"), image4.resolve("lib").resolve("modules")) != -1L) { + throw new RuntimeException("jlink producing inconsistent result with multiple named modules"); } } } diff --git a/test/jdk/tools/jlink/JLinkReproducible3Test.java b/test/jdk/tools/jlink/JLinkReproducible3Test.java new file mode 100644 index 0000000000000..6d37cff4ee4d9 --- /dev/null +++ b/test/jdk/tools/jlink/JLinkReproducible3Test.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020, 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 jdk.test.lib.process.ProcessTools; + +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.*; + +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Optional; + +/* + * @test + * @summary Make sure that jimages are consistent when created by jlink. Copies test jdk and runs against original. + * @bug 8252730 + * @modules jdk.jlink + * jdk.management + * jdk.unsupported + * jdk.charsets + * @library /test/lib + * @run main JLinkReproducible3Test + */ +public class JLinkReproducible3Test { + + public static void main(String[] args) throws Exception { + Path image1 = Paths.get("./image1"); + Path image2 = Paths.get("./image2"); + + Path copyJdk1Dir = Path.of("./copy-jdk1-tmpdir"); + Files.createDirectory(copyJdk1Dir); + + Path copyJdk2Dir = Path.of("./copy-jdk2-tmpdir"); + Files.createDirectory(copyJdk2Dir); + + Path jdkTestDir = Path.of( + Optional.of( + System.getProperty("test.jdk")) + .orElseThrow(() -> new RuntimeException("Couldn't load JDK Test Dir")) + ); + + copyJDK(jdkTestDir, copyJdk1Dir); + copyJDK(jdkTestDir, copyJdk2Dir); + + Path copiedJlink1 = Optional.of( + Paths.get(copyJdk1Dir.toString(), "bin", "jlink")) + .orElseThrow(() -> new RuntimeException("Unable to load copied jlink") + ); + + Path copiedJlink2 = Optional.of( + Paths.get(copyJdk2Dir.toString(), "bin", "jlink")) + .orElseThrow(() -> new RuntimeException("Unable to load copied jlink") + ); + + runCopiedJlink(copiedJlink1.toString(), "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image1.toString()); + runCopiedJlink(copiedJlink2.toString(), "--add-modules", "java.base,jdk.management,jdk.unsupported,jdk.charsets", "--output", image2.toString()); + + long mismatch = Files.mismatch(image1.resolve("lib").resolve("modules"), image2.resolve("lib").resolve("modules")); + if (mismatch != -1L) { + throw new RuntimeException("jlink producing inconsistent result in modules. Mismatch in modules file occurred at byte position " + mismatch); + } + } + + private static void runCopiedJlink(String... args) throws Exception { + var process = new ProcessBuilder(args); + var res = ProcessTools.executeProcess(process); + res.shouldHaveExitValue(0); + } + + private static void copyJDK(Path src, Path dst) throws Exception { + Files.walk(src).skip(1).forEach(file -> { + try { + Files.copy(file, dst.resolve(src.relativize(file)), StandardCopyOption.COPY_ATTRIBUTES); + } catch (IOException ioe) { + throw new UncheckedIOException(ioe); + } + }); + } +} + From 7817963ce91384380fe65005a6c438b08b022bad Mon Sep 17 00:00:00 2001 From: Patric Hedlin Date: Sat, 26 Sep 2020 18:24:11 +0000 Subject: [PATCH 29/79] 8247691: [aarch64] Incorrect handling of VM exceptions in C1 deopt stub/traps Reviewed-by: eosterlund, aph --- .../cpu/aarch64/c1_Runtime1_aarch64.cpp | 91 +++++-------------- src/hotspot/share/c1/c1_Runtime1.cpp | 21 ++--- src/hotspot/share/runtime/deoptimization.cpp | 1 + 3 files changed, 34 insertions(+), 79 deletions(-) diff --git a/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp index a356cc2cbd728..2f1845affe966 100644 --- a/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp @@ -553,84 +553,39 @@ OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) { __ bind(L); } #endif - __ reset_last_Java_frame(true); - __ maybe_isb(); - - // check for pending exceptions - { Label L; - __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); - __ cbz(rscratch1, L); - // exception pending => remove activation and forward to exception handler - - { Label L1; - __ cbnz(r0, L1); // have we deoptimized? - __ far_jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id))); - __ bind(L1); - } - - // the deopt blob expects exceptions in the special fields of - // JavaThread, so copy and clear pending exception. - - // load and clear pending exception - __ ldr(r0, Address(rthread, Thread::pending_exception_offset())); - __ str(zr, Address(rthread, Thread::pending_exception_offset())); - - // check that there is really a valid exception - __ verify_not_null_oop(r0); - // load throwing pc: this is the return address of the stub - __ mov(r3, lr); + __ reset_last_Java_frame(true); #ifdef ASSERT - // check that fields in JavaThread for exception oop and issuing pc are empty - Label oop_empty; - __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); - __ cbz(rscratch1, oop_empty); - __ stop("exception oop must be empty"); - __ bind(oop_empty); - - Label pc_empty; - __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset())); - __ cbz(rscratch1, pc_empty); - __ stop("exception pc must be empty"); - __ bind(pc_empty); -#endif - - // store exception oop and throwing pc to JavaThread - __ str(r0, Address(rthread, JavaThread::exception_oop_offset())); - __ str(r3, Address(rthread, JavaThread::exception_pc_offset())); - - restore_live_registers(sasm); - - __ leave(); - - // Forward the exception directly to deopt blob. We can blow no - // registers and must leave throwing pc on the stack. A patch may - // have values live in registers so the entry point with the - // exception in tls. - __ far_jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls())); - - __ bind(L); - } - - - // Runtime will return true if the nmethod has been deoptimized during - // the patching process. In that case we must do a deopt reexecute instead. + // check that fields in JavaThread for exception oop and issuing pc are empty + Label oop_empty; + __ ldr(rscratch1, Address(rthread, Thread::pending_exception_offset())); + __ cbz(rscratch1, oop_empty); + __ stop("exception oop must be empty"); + __ bind(oop_empty); - Label cont; + Label pc_empty; + __ ldr(rscratch1, Address(rthread, JavaThread::exception_pc_offset())); + __ cbz(rscratch1, pc_empty); + __ stop("exception pc must be empty"); + __ bind(pc_empty); +#endif - __ cbz(r0, cont); // have we deoptimized? + // Runtime will return true if the nmethod has been deoptimized, this is the + // expected scenario and anything else is an error. Note that we maintain a + // check on the result purely as a defensive measure. + Label no_deopt; + __ cbz(r0, no_deopt); // Have we deoptimized? - // Will reexecute. Proper return address is already on the stack we just restore - // registers, pop all of our frame but the return address and jump to the deopt blob + // Perform a re-execute. The proper return address is already on the stack, + // we just need to restore registers, pop all of our frame but the return + // address and jump to the deopt blob. restore_live_registers(sasm); __ leave(); __ far_jump(RuntimeAddress(deopt_blob->unpack_with_reexecution())); - __ bind(cont); - restore_live_registers(sasm); - __ leave(); - __ ret(lr); + __ bind(no_deopt); + __ stop("deopt not performed"); return oop_maps; } diff --git a/src/hotspot/share/c1/c1_Runtime1.cpp b/src/hotspot/share/c1/c1_Runtime1.cpp index 6cfc256ab6e9b..a1977636dfa1a 100644 --- a/src/hotspot/share/c1/c1_Runtime1.cpp +++ b/src/hotspot/share/c1/c1_Runtime1.cpp @@ -1255,32 +1255,32 @@ JRT_END #else // DEOPTIMIZE_WHEN_PATCHING -JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id )) - RegisterMap reg_map(thread, false); +void Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id) { + NOT_PRODUCT(_patch_code_slowcase_cnt++); - NOT_PRODUCT(_patch_code_slowcase_cnt++;) if (TracePatching) { tty->print_cr("Deoptimizing because patch is needed"); } + RegisterMap reg_map(thread, false); + frame runtime_frame = thread->last_frame(); frame caller_frame = runtime_frame.sender(®_map); + assert(caller_frame.is_compiled_frame(), "Wrong frame type"); - // It's possible the nmethod was invalidated in the last - // safepoint, but if it's still alive then make it not_entrant. + // Make sure the nmethod is invalidated, i.e. made not entrant. nmethod* nm = CodeCache::find_nmethod(caller_frame.pc()); if (nm != NULL) { nm->make_not_entrant(); } Deoptimization::deoptimize_frame(thread, caller_frame.id()); - // Return to the now deoptimized frame. -JRT_END + postcond(caller_is_deopted()); +} #endif // DEOPTIMIZE_WHEN_PATCHING -// // Entry point for compiled code. We want to patch a nmethod. // We don't do a normal VM transition here because we want to // know after the patching is complete and any safepoint(s) are taken @@ -1345,7 +1345,7 @@ int Runtime1::move_appendix_patching(JavaThread* thread) { return caller_is_deopted(); } -// + // Entry point for compiled code. We want to patch a nmethod. // We don't do a normal VM transition here because we want to // know after the patching is complete and any safepoint(s) are taken @@ -1354,7 +1354,6 @@ int Runtime1::move_appendix_patching(JavaThread* thread) { // completes we can check for deoptimization. This simplifies the // assembly code in the cpu directories. // - int Runtime1::access_field_patching(JavaThread* thread) { // // NOTE: we are still in Java @@ -1372,7 +1371,7 @@ int Runtime1::access_field_patching(JavaThread* thread) { // Return true if calling code is deoptimized return caller_is_deopted(); -JRT_END +} JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id)) diff --git a/src/hotspot/share/runtime/deoptimization.cpp b/src/hotspot/share/runtime/deoptimization.cpp index 8c850cda39c01..59eb4583f40e2 100644 --- a/src/hotspot/share/runtime/deoptimization.cpp +++ b/src/hotspot/share/runtime/deoptimization.cpp @@ -1623,6 +1623,7 @@ void Deoptimization::deoptimize_frame_internal(JavaThread* thread, intptr_t* id, while (fr.id() != id) { fr = fr.sender(®_map); } + assert(fr.is_compiled_frame(), "Wrong frame type"); deoptimize(thread, fr, reason); } From f014854ac71a82b307667ba017f01b13eed54330 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 28 Sep 2020 01:54:45 +0000 Subject: [PATCH 30/79] 8253624: gtest fails when run from make with read-only source directory Reviewed-by: erikj --- make/RunTests.gmk | 1 + 1 file changed, 1 insertion(+) diff --git a/make/RunTests.gmk b/make/RunTests.gmk index b978f9cf5af70..97fd016b36109 100644 --- a/make/RunTests.gmk +++ b/make/RunTests.gmk @@ -609,6 +609,7 @@ define SetupRunGtestTestBody $$(call LogWarn, Running test '$$($1_TEST)') $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR)) $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, ( \ + $$(CD) $$($1_TEST_SUPPORT_DIR) && \ $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \ -jdk $(JDK_UNDER_TEST) $$($1_GTEST_FILTER) \ --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \ From 625a9352bfdc017f426c3bd2a5c24b0f7598ccce Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Mon, 28 Sep 2020 06:30:09 +0000 Subject: [PATCH 31/79] 8253638: Cleanup os::reserve_memory and remove MAP_FIXED Reviewed-by: stuefe, iklam --- src/hotspot/os/aix/os_aix.cpp | 22 +++------- src/hotspot/os/bsd/os_bsd.cpp | 26 ++++-------- src/hotspot/os/linux/os_linux.cpp | 41 ++++++------------- src/hotspot/os/posix/os_posix.cpp | 2 +- src/hotspot/os/windows/os_windows.cpp | 25 ++++++----- src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp | 2 +- src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp | 2 +- src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp | 2 +- .../os_cpu/linux_zero/os_linux_zero.cpp | 2 +- .../share/gc/z/zMarkStackAllocator.cpp | 2 +- .../share/memory/allocation.inline.hpp | 4 +- src/hotspot/share/memory/virtualspace.cpp | 4 +- src/hotspot/share/prims/whitebox.cpp | 2 +- src/hotspot/share/runtime/os.cpp | 35 ++++++++-------- src/hotspot/share/runtime/os.hpp | 23 +++++++---- .../share/runtime/safepointMechanism.cpp | 2 +- .../runtime/test_committed_virtualmemory.cpp | 4 +- 17 files changed, 86 insertions(+), 114 deletions(-) diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index 43e7f29242123..f0a89fbe294af 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -1728,7 +1728,7 @@ static void local_sem_init() { } else { // Memory semaphores must live in shared mem. guarantee0(p_sig_msem == NULL); - p_sig_msem = (msemaphore*)os::reserve_memory(sizeof(msemaphore), NULL); + p_sig_msem = (msemaphore*)os::reserve_memory(sizeof(msemaphore)); guarantee(p_sig_msem, "Cannot allocate memory for memory semaphore"); guarantee(::msem_init(p_sig_msem, 0) == p_sig_msem, "msem_init failed"); } @@ -2347,19 +2347,7 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info } // Reserves and attaches a shared memory segment. -// Will assert if a wish address is given and could not be obtained. -char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) { - - // All other Unices do a mmap(MAP_FIXED) if the addr is given, - // thereby clobbering old mappings at that place. That is probably - // not intended, never used and almost certainly an error were it - // ever be used this way (to try attaching at a specified address - // without clobbering old mappings an alternate API exists, - // os::attempt_reserve_memory_at()). - // Instead of mimicking the dangerous coding of the other platforms, here I - // just ignore the request address (release) or assert(debug). - assert0(requested_addr == NULL); - +char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) { // Always round to os::vm_page_size(), which may be larger than 4K. bytes = align_up(bytes, os::vm_page_size()); const size_t alignment_hint0 = @@ -2368,12 +2356,12 @@ char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment // In 4K mode always use mmap. // In 64K mode allocate small sizes with mmap, large ones with 64K shmatted. if (os::vm_page_size() == 4*K) { - return reserve_mmaped_memory(bytes, requested_addr, alignment_hint); + return reserve_mmaped_memory(bytes, NULL /* requested_addr */, alignment_hint); } else { if (bytes >= Use64KPagesThreshold) { - return reserve_shmated_memory(bytes, requested_addr, alignment_hint); + return reserve_shmated_memory(bytes, NULL /* requested_addr */, alignment_hint); } else { - return reserve_mmaped_memory(bytes, requested_addr, alignment_hint); + return reserve_mmaped_memory(bytes, NULL /* requested_addr */, alignment_hint); } } } diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index edf714bb97023..7fbf762f778a6 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -2011,27 +2011,17 @@ bool os::remove_stack_guard_pages(char* addr, size_t size) { return os::uncommit_memory(addr, size); } -// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory -// at 'requested_addr'. If there are existing memory mappings at the same -// location, however, they will be overwritten. If 'fixed' is false, // 'requested_addr' is only treated as a hint, the return value may or // may not start from the requested address. Unlike Bsd mmap(), this // function returns NULL to indicate failure. -static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) { - char * addr; - int flags; - - flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; - if (fixed) { - assert((uintptr_t)requested_addr % os::Bsd::page_size() == 0, "unaligned address"); - flags |= MAP_FIXED; - } +static char* anon_mmap(char* requested_addr, size_t bytes) { + // MAP_FIXED is intentionally left out, to leave existing mappings intact. + const int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; // Map reserved/uncommitted pages PROT_NONE so we fail early if we // touch an uncommitted page. Otherwise, the read/write might // succeed if we have enough swap space to back the physical page. - addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, - flags, -1, 0); + char* addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, flags, -1, 0); return addr == MAP_FAILED ? NULL : addr; } @@ -2040,9 +2030,9 @@ static int anon_munmap(char * addr, size_t size) { return ::munmap(addr, size) == 0; } -char* os::pd_reserve_memory(size_t bytes, char* requested_addr, - size_t alignment_hint) { - return anon_mmap(requested_addr, bytes, (requested_addr != NULL)); +char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) { + // Ignores alignment hint + return anon_mmap(NULL /* addr */, bytes); } bool os::pd_release_memory(char* addr, size_t size) { @@ -2152,7 +2142,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { // Bsd mmap allows caller to pass an address as hint; give it a try first, // if kernel honors the hint then we can return immediately. - char * addr = anon_mmap(requested_addr, bytes, false); + char * addr = anon_mmap(requested_addr, bytes); if (addr == requested_addr) { return requested_addr; } diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index d067a65c3a2c8..03691e39237ea 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -3638,27 +3638,17 @@ bool os::remove_stack_guard_pages(char* addr, size_t size) { return os::uncommit_memory(addr, size); } -// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory -// at 'requested_addr'. If there are existing memory mappings at the same -// location, however, they will be overwritten. If 'fixed' is false, // 'requested_addr' is only treated as a hint, the return value may or // may not start from the requested address. Unlike Linux mmap(), this // function returns NULL to indicate failure. -static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) { - char * addr; - int flags; - - flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; - if (fixed) { - assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address"); - flags |= MAP_FIXED; - } +static char* anon_mmap(char* requested_addr, size_t bytes) { + // MAP_FIXED is intentionally left out, to leave existing mappings intact. + const int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; // Map reserved/uncommitted pages PROT_NONE so we fail early if we // touch an uncommitted page. Otherwise, the read/write might // succeed if we have enough swap space to back the physical page. - addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, - flags, -1, 0); + char* addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, flags, -1, 0); return addr == MAP_FAILED ? NULL : addr; } @@ -3671,19 +3661,14 @@ static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) { // It must be a multiple of allocation granularity. // Returns address of memory or NULL. If req_addr was not NULL, will only return // req_addr or NULL. -static char* anon_mmap_aligned(size_t bytes, size_t alignment, char* req_addr) { - +static char* anon_mmap_aligned(char* req_addr, size_t bytes, size_t alignment) { size_t extra_size = bytes; if (req_addr == NULL && alignment > 0) { extra_size += alignment; } - char* start = (char*) ::mmap(req_addr, extra_size, PROT_NONE, - MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, - -1, 0); - if (start == MAP_FAILED) { - start = NULL; - } else { + char* start = anon_mmap(req_addr, bytes); + if (start != NULL) { if (req_addr != NULL) { if (start != req_addr) { ::munmap(start, extra_size); @@ -3709,9 +3694,9 @@ static int anon_munmap(char * addr, size_t size) { return ::munmap(addr, size) == 0; } -char* os::pd_reserve_memory(size_t bytes, char* requested_addr, - size_t alignment_hint) { - return anon_mmap(requested_addr, bytes, (requested_addr != NULL)); +char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) { + // Ignores alignment hint + return anon_mmap(NULL, bytes); } bool os::pd_release_memory(char* addr, size_t size) { @@ -4069,7 +4054,7 @@ static char* shmat_with_alignment(int shmid, size_t bytes, size_t alignment) { // To ensure that we get 'alignment' aligned memory from shmat, // we pre-reserve aligned virtual memory and then attach to that. - char* pre_reserved_addr = anon_mmap_aligned(bytes, alignment, NULL); + char* pre_reserved_addr = anon_mmap_aligned(NULL /* req_addr */, bytes, alignment); if (pre_reserved_addr == NULL) { // Couldn't pre-reserve aligned memory. shm_warning("Failed to pre-reserve aligned memory for shmat."); @@ -4238,7 +4223,7 @@ char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes, assert(is_aligned(bytes, alignment), "Must be"); // First reserve - but not commit - the address range in small pages. - char* const start = anon_mmap_aligned(bytes, alignment, req_addr); + char* const start = anon_mmap_aligned(req_addr, bytes, alignment); if (start == NULL) { return NULL; @@ -4418,7 +4403,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { // Linux mmap allows caller to pass an address as hint; give it a try first, // if kernel honors the hint then we can return immediately. - char * addr = anon_mmap(requested_addr, bytes, false); + char * addr = anon_mmap(requested_addr, bytes); if (addr == requested_addr) { return requested_addr; } diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp index 39d2d2732adc1..b5a5ef0333235 100644 --- a/src/hotspot/os/posix/os_posix.cpp +++ b/src/hotspot/os/posix/os_posix.cpp @@ -326,7 +326,7 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { MemTracker::record_virtual_memory_reserve((address)extra_base, extra_size, CALLER_PC); } } else { - extra_base = os::reserve_memory(extra_size, NULL, alignment); + extra_base = os::reserve_memory(extra_size, alignment); } if (extra_base == NULL) { diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index d0d1ee2b5c470..ca93bc7df0569 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -3063,8 +3063,8 @@ void os::split_reserved_memory(char *base, size_t size, size_t split) { assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity"); release_memory(base, size); - reserve_memory(split, base); - reserve_memory(size - split, split_address); + attempt_reserve_memory_at(split, base); + attempt_reserve_memory_at(size - split, split_address); // NMT: nothing to do here. Since Windows implements the split by // releasing and re-reserving memory, the parts are already registered @@ -3086,7 +3086,7 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { char* aligned_base = NULL; do { - char* extra_base = os::reserve_memory(extra_size, NULL, alignment, file_desc); + char* extra_base = os::reserve_memory_with_fd(extra_size, alignment, file_desc); if (extra_base == NULL) { return NULL; } @@ -3099,14 +3099,21 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { os::release_memory(extra_base, extra_size); } - aligned_base = os::reserve_memory(size, aligned_base, 0, file_desc); + aligned_base = os::attempt_reserve_memory_at(size, aligned_base, file_desc); } while (aligned_base == NULL); return aligned_base; } -char* os::pd_reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { +char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) { + // Ignores alignment hint + return pd_attempt_reserve_memory_at(bytes, NULL /* addr */); +} + +// Reserve memory at an arbitrary address, only if that area is +// available (and not reserved for something else). +char* os::pd_attempt_reserve_memory_at(size_t bytes, char* addr) { assert((size_t)addr % os::vm_allocation_granularity() == 0, "reserve alignment"); assert(bytes % os::vm_page_size() == 0, "reserve page size"); @@ -3137,14 +3144,6 @@ char* os::pd_reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { return res; } -// Reserve memory at an arbitrary address, only if that area is -// available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { - // Windows os::reserve_memory() fails of the requested address range is - // not avilable. - return reserve_memory(bytes, requested_addr); -} - char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { assert(file_desc >= 0, "file_desc is not valid"); return map_memory_to_file(requested_addr, bytes, file_desc); diff --git a/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp b/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp index c2437d5635023..bb6a54ab00656 100644 --- a/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp +++ b/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp @@ -791,7 +791,7 @@ bool os::is_allocatable(size_t bytes) { return true; } - char* addr = reserve_memory(bytes, NULL); + char* addr = reserve_memory(bytes); if (addr != NULL) { release_memory(addr, bytes); diff --git a/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp b/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp index b404c840a6a9a..79300179659e4 100644 --- a/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp +++ b/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp @@ -247,7 +247,7 @@ bool os::is_allocatable(size_t bytes) { return true; } - char* addr = reserve_memory(bytes, NULL); + char* addr = reserve_memory(bytes); if (addr != NULL) { release_memory(addr, bytes); diff --git a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp index 598383ca9db1a..d4abb754498ad 100644 --- a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp +++ b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp @@ -650,7 +650,7 @@ bool os::is_allocatable(size_t bytes) { return true; } - char* addr = reserve_memory(bytes, NULL); + char* addr = reserve_memory(bytes); if (addr != NULL) { release_memory(addr, bytes); diff --git a/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp b/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp index e2de18263f0a7..8af3a3a5b4641 100644 --- a/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp +++ b/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp @@ -273,7 +273,7 @@ bool os::is_allocatable(size_t bytes) { return true; } - char* addr = reserve_memory(bytes, NULL); + char* addr = reserve_memory(bytes); if (addr != NULL) { release_memory(addr, bytes); diff --git a/src/hotspot/share/gc/z/zMarkStackAllocator.cpp b/src/hotspot/share/gc/z/zMarkStackAllocator.cpp index 8b7d264218829..b5d15a067d9b3 100644 --- a/src/hotspot/share/gc/z/zMarkStackAllocator.cpp +++ b/src/hotspot/share/gc/z/zMarkStackAllocator.cpp @@ -43,7 +43,7 @@ ZMarkStackSpace::ZMarkStackSpace() : // Reserve address space const size_t size = ZMarkStackSpaceLimit; const size_t alignment = (size_t)os::vm_allocation_granularity(); - const uintptr_t addr = (uintptr_t)os::reserve_memory(size, NULL, alignment, mtGC); + const uintptr_t addr = (uintptr_t)os::reserve_memory(size, alignment, mtGC); if (addr == 0) { log_error_pd(gc, marking)("Failed to reserve address space for mark stacks"); return; diff --git a/src/hotspot/share/memory/allocation.inline.hpp b/src/hotspot/share/memory/allocation.inline.hpp index ccec420a2868d..919e603ae3b70 100644 --- a/src/hotspot/share/memory/allocation.inline.hpp +++ b/src/hotspot/share/memory/allocation.inline.hpp @@ -57,7 +57,7 @@ E* MmapArrayAllocator::allocate_or_null(size_t length, MEMFLAGS flags) { size_t size = size_for(length); int alignment = os::vm_allocation_granularity(); - char* addr = os::reserve_memory(size, NULL, alignment, flags); + char* addr = os::reserve_memory(size, alignment, flags); if (addr == NULL) { return NULL; } @@ -75,7 +75,7 @@ E* MmapArrayAllocator::allocate(size_t length, MEMFLAGS flags) { size_t size = size_for(length); int alignment = os::vm_allocation_granularity(); - char* addr = os::reserve_memory(size, NULL, alignment, flags); + char* addr = os::reserve_memory(size, alignment, flags); if (addr == NULL) { vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "Allocator (reserve)"); } diff --git a/src/hotspot/share/memory/virtualspace.cpp b/src/hotspot/share/memory/virtualspace.cpp index cbb1a0427c78b..210659ca5d14b 100644 --- a/src/hotspot/share/memory/virtualspace.cpp +++ b/src/hotspot/share/memory/virtualspace.cpp @@ -194,7 +194,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large, base = NULL; } } else { - base = os::reserve_memory(size, NULL, alignment, _fd_for_heap); + base = os::reserve_memory_with_fd(size, alignment, _fd_for_heap); } if (base == NULL) return; @@ -382,7 +382,7 @@ void ReservedHeapSpace::try_reserve_heap(size_t size, if (requested_address != 0) { base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap); } else { - base = os::reserve_memory(size, NULL, alignment, _fd_for_heap); + base = os::reserve_memory_with_fd(size, alignment, _fd_for_heap); } } if (base == NULL) { return; } diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index e2d12cdf71f45..fe1bf09552342 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -1473,7 +1473,7 @@ WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) static char c; static volatile char* p; - p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); + p = os::reserve_memory(os::vm_allocation_granularity()); if (p == NULL) { THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); } diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 2a3621f3712da..24491e79b4385 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -1652,37 +1652,38 @@ bool os::create_stack_guard_pages(char* addr, size_t bytes) { return os::pd_create_stack_guard_pages(addr, bytes); } -char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint, int file_desc) { - char* result = NULL; +char* os::reserve_memory(size_t bytes, size_t alignment_hint, MEMFLAGS flags) { + char* result = pd_reserve_memory(bytes, alignment_hint); + if (result != NULL) { + MemTracker::record_virtual_memory_reserve(result, bytes, CALLER_PC); + if (flags != mtOther) { + MemTracker::record_virtual_memory_type(result, flags); + } + } + + return result; +} + +char* os::reserve_memory_with_fd(size_t bytes, size_t alignment_hint, int file_desc) { + char* result; if (file_desc != -1) { // Could have called pd_reserve_memory() followed by replace_existing_mapping_with_file_mapping(), // but AIX may use SHM in which case its more trouble to detach the segment and remap memory to the file. - result = os::map_memory_to_file(addr, bytes, file_desc); + result = os::map_memory_to_file(NULL /* addr */, bytes, file_desc); if (result != NULL) { - MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); + MemTracker::record_virtual_memory_reserve_and_commit(result, bytes, CALLER_PC); } } else { - result = pd_reserve_memory(bytes, addr, alignment_hint); + result = pd_reserve_memory(bytes, alignment_hint); if (result != NULL) { - MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); + MemTracker::record_virtual_memory_reserve(result, bytes, CALLER_PC); } } return result; } -char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint, - MEMFLAGS flags) { - char* result = pd_reserve_memory(bytes, addr, alignment_hint); - if (result != NULL) { - MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); - MemTracker::record_virtual_memory_type((address)result, flags); - } - - return result; -} - char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) { char* result = NULL; if (file_desc != -1) { diff --git a/src/hotspot/share/runtime/os.hpp b/src/hotspot/share/runtime/os.hpp index 21031656aa5ee..5a03dd5dda12f 100644 --- a/src/hotspot/share/runtime/os.hpp +++ b/src/hotspot/share/runtime/os.hpp @@ -113,10 +113,11 @@ class os: AllStatic { _page_sizes[1] = 0; // sentinel } - static char* pd_reserve_memory(size_t bytes, char* addr = 0, - size_t alignment_hint = 0); + static char* pd_reserve_memory(size_t bytes, size_t alignment_hint); + static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc); + static bool pd_commit_memory(char* addr, size_t bytes, bool executable); static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, bool executable); @@ -310,13 +311,21 @@ class os: AllStatic { const size_t size); static int vm_allocation_granularity(); - static char* reserve_memory(size_t bytes, char* addr = 0, - size_t alignment_hint = 0, int file_desc = -1); - static char* reserve_memory(size_t bytes, char* addr, - size_t alignment_hint, MEMFLAGS flags); + + // Reserves virtual memory. + // alignment_hint - currently only used by AIX + static char* reserve_memory(size_t bytes, size_t alignment_hint = 0, MEMFLAGS flags = mtOther); + + // Reserves virtual memory. + // if file_desc != -1, also attaches the memory to the file. + static char* reserve_memory_with_fd(size_t bytes, size_t alignment_hint, int file_desc); + + // Reserves virtual memory that starts at an address that is aligned to 'alignment'. static char* reserve_memory_aligned(size_t size, size_t alignment, int file_desc = -1); - static char* attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1); + // Attempts to reserve the virtual memory at [addr, addr + bytes). + // Does not overwrite existing mappings. + static char* attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1); // Split a reserved memory region [base, base+size) into two regions [base, base+split) and // [base+split, base+size). diff --git a/src/hotspot/share/runtime/safepointMechanism.cpp b/src/hotspot/share/runtime/safepointMechanism.cpp index d6c401a9bc072..79a15ab1bb8c0 100644 --- a/src/hotspot/share/runtime/safepointMechanism.cpp +++ b/src/hotspot/share/runtime/safepointMechanism.cpp @@ -47,7 +47,7 @@ void SafepointMechanism::default_initialize() { // Polling page const size_t page_size = os::vm_page_size(); const size_t allocation_size = 2 * page_size; - char* polling_page = os::reserve_memory(allocation_size, NULL, page_size); + char* polling_page = os::reserve_memory(allocation_size, page_size); os::commit_memory_or_exit(polling_page, allocation_size, false, "Unable to commit Safepoint polling page"); MemTracker::record_virtual_memory_type((address)polling_page, mtSafepoint); diff --git a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp index 12fa3f2b8d9b7..9d3ecfd9a3aa6 100644 --- a/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp +++ b/test/hotspot/gtest/runtime/test_committed_virtualmemory.cpp @@ -101,7 +101,7 @@ class CommittedVirtualMemoryTest { static void test_committed_region_impl(size_t num_pages, size_t touch_pages, int* page_num) { const size_t page_sz = os::vm_page_size(); const size_t size = num_pages * page_sz; - char* base = os::reserve_memory(size, NULL, page_sz, mtThreadStack); + char* base = os::reserve_memory(size, page_sz, mtThreadStack); bool result = os::commit_memory(base, size, false); size_t index; ASSERT_NE(base, (char*)NULL); @@ -169,7 +169,7 @@ class CommittedVirtualMemoryTest { const size_t page_sz = os::vm_page_size(); const size_t num_pages = 4; const size_t size = num_pages * page_sz; - char* base = os::reserve_memory(size, NULL, page_sz, mtTest); + char* base = os::reserve_memory(size, page_sz, mtTest); ASSERT_NE(base, (char*)NULL); result = os::commit_memory(base, size, false); From fed3636f12b442ee80375025301f137c950625c4 Mon Sep 17 00:00:00 2001 From: Roberto Castaneda Lozano Date: Mon, 28 Sep 2020 06:44:58 +0000 Subject: [PATCH 32/79] 8252219: C2: Randomize IGVN worklist for stress testing Add 'StressIGVN' option to let C2 randomize IGVN worklist order. When enabled, the worklist is shuffled before each main run of the IGVN loop. Also add 'StressSeed=N' option to specify the seed. If the seed is not specified, a random one is generated. In either case, the seed is logged if 'LogCompilation' is enabled. The new options are declared as production+diagnostic for consistency with the existing 'StressLCM' and 'StressGCM' options. Reviewed-by: kvn, chagedorn, thartmann --- src/hotspot/share/opto/c2_globals.hpp | 8 +++ src/hotspot/share/opto/compile.cpp | 24 ++++++- src/hotspot/share/opto/compile.hpp | 4 +- src/hotspot/share/opto/phaseX.cpp | 11 +++ src/hotspot/share/opto/phaseX.hpp | 3 + src/hotspot/share/runtime/os.cpp | 4 +- src/hotspot/share/runtime/os.hpp | 1 + .../arguments/TestStressIGVNOptions.java | 44 ++++++++++++ .../debug/TestGenerateStressSeed.java | 64 +++++++++++++++++ .../jtreg/compiler/debug/TestStressIGVN.java | 71 +++++++++++++++++++ 10 files changed, 229 insertions(+), 5 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java create mode 100644 test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java create mode 100644 test/hotspot/jtreg/compiler/debug/TestStressIGVN.java diff --git a/src/hotspot/share/opto/c2_globals.hpp b/src/hotspot/share/opto/c2_globals.hpp index 668c04f379a46..1d3b6fd910b63 100644 --- a/src/hotspot/share/opto/c2_globals.hpp +++ b/src/hotspot/share/opto/c2_globals.hpp @@ -49,6 +49,14 @@ product(bool, StressGCM, false, DIAGNOSTIC, \ "Randomize instruction scheduling in GCM") \ \ + product(bool, StressIGVN, false, DIAGNOSTIC, \ + "Randomize worklist traversal in IGVN") \ + \ + product(uint, StressSeed, 0, DIAGNOSTIC, \ + "Seed for IGVN stress testing (if unset, a random one is " \ + "generated") \ + range(0, max_juint) \ + \ develop(bool, StressMethodHandleLinkerInlining, false, \ "Stress inlining through method handle linkers") \ \ diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index ec98635a248e6..b91441dc38b67 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -70,6 +70,7 @@ #include "opto/type.hpp" #include "opto/vectornode.hpp" #include "runtime/arguments.hpp" +#include "runtime/globals_extension.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/signature.hpp" #include "runtime/stubRoutines.hpp" @@ -523,6 +524,7 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci, #endif _has_method_handle_invokes(false), _clinit_barrier_on_entry(false), + _stress_seed(0), _comp_arena(mtCompiler), _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())), _env(ci_env), @@ -727,6 +729,18 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci, if (failing()) return; NOT_PRODUCT( verify_graph_edges(); ) + // If IGVN is randomized for stress testing, seed random number + // generation and log the seed for repeatability. + if (StressIGVN) { + _stress_seed = FLAG_IS_DEFAULT(StressSeed) ? + static_cast(Ticks::now().nanoseconds()) : StressSeed; + if (_log != NULL) { + _log->elem("stress_test seed='%u'", _stress_seed); + } else if (FLAG_IS_DEFAULT(StressSeed)) { + tty->print_cr("Warning: set +LogCompilation to log the seed."); + } + } + // Now optimize Optimize(); if (failing()) return; @@ -809,6 +823,7 @@ Compile::Compile( ciEnv* ci_env, #endif _has_method_handle_invokes(false), _clinit_barrier_on_entry(false), + _stress_seed(0), _comp_arena(mtCompiler), _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())), _env(ci_env), @@ -4436,8 +4451,13 @@ void Compile::remove_speculative_types(PhaseIterGVN &igvn) { } } -// Auxiliary method to support randomized stressing/fuzzing. -// +// Auxiliary methods to support randomized stressing/fuzzing. + +int Compile::random() { + _stress_seed = os::next_random(_stress_seed); + return static_cast(_stress_seed); +} + // This method can be called the arbitrary number of times, with current count // as the argument. The logic allows selecting a single candidate from the // running list of candidates as follows: diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 16b0a5261f3d9..afc6279c30c5b 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -300,6 +300,7 @@ class Compile : public Phase { RTMState _rtm_state; // State of Restricted Transactional Memory usage int _loop_opts_cnt; // loop opts round bool _clinit_barrier_on_entry; // True if clinit barrier is needed on nmethod entry + uint _stress_seed; // Seed for stress testing // Compilation environment. Arena _comp_arena; // Arena with lifetime equivalent to Compile @@ -1136,7 +1137,8 @@ class Compile : public Phase { // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check) static Node* constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl); - // Auxiliary method for randomized fuzzing/stressing + // Auxiliary methods for randomized fuzzing/stressing + int random(); static bool randomized_select(int count); // supporting clone_map diff --git a/src/hotspot/share/opto/phaseX.cpp b/src/hotspot/share/opto/phaseX.cpp index 58f820d0c725a..08855d2136750 100644 --- a/src/hotspot/share/opto/phaseX.cpp +++ b/src/hotspot/share/opto/phaseX.cpp @@ -975,6 +975,14 @@ PhaseIterGVN::PhaseIterGVN( PhaseGVN *gvn ) : PhaseGVN(gvn), } } +void PhaseIterGVN::shuffle_worklist() { + if (_worklist.size() < 2) return; + for (uint i = _worklist.size() - 1; i >= 1; i--) { + uint j = C->random() % (i + 1); + swap(_worklist.adr()[i], _worklist.adr()[j]); + } +} + #ifndef PRODUCT void PhaseIterGVN::verify_step(Node* n) { if (VerifyIterativeGVN) { @@ -1127,6 +1135,9 @@ void PhaseIterGVN::trace_PhaseIterGVN_verbose(Node* n, int num_processed) { void PhaseIterGVN::optimize() { DEBUG_ONLY(uint num_processed = 0;) NOT_PRODUCT(init_verifyPhaseIterGVN();) + if (StressIGVN) { + shuffle_worklist(); + } uint loop_count = 0; // Pull from worklist and transform the node. If the node has changed, diff --git a/src/hotspot/share/opto/phaseX.hpp b/src/hotspot/share/opto/phaseX.hpp index ec6ef2f78d56c..c297bb76978e7 100644 --- a/src/hotspot/share/opto/phaseX.hpp +++ b/src/hotspot/share/opto/phaseX.hpp @@ -458,6 +458,9 @@ class PhaseIterGVN : public PhaseGVN { protected: + // Shuffle worklist, for stress testing + void shuffle_worklist(); + virtual const Type* saturate(const Type* new_type, const Type* old_type, const Type* limit_type) const; // Usually returns new_type. Returns old_type if new_type is only a slight diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index 24491e79b4385..f584386b1d670 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -815,7 +815,7 @@ void os::init_random(unsigned int initval) { } -static int random_helper(unsigned int rand_seed) { +int os::next_random(unsigned int rand_seed) { /* standard, well-known linear congruential random generator with * next_rand = (16807*seed) mod (2**31-1) * see @@ -853,7 +853,7 @@ int os::random() { // Make updating the random seed thread safe. while (true) { unsigned int seed = _rand_seed; - unsigned int rand = random_helper(seed); + unsigned int rand = next_random(seed); if (Atomic::cmpxchg(&_rand_seed, seed, rand) == seed) { return static_cast(rand); } diff --git a/src/hotspot/share/runtime/os.hpp b/src/hotspot/share/runtime/os.hpp index 5a03dd5dda12f..0fc38a5c24ab0 100644 --- a/src/hotspot/share/runtime/os.hpp +++ b/src/hotspot/share/runtime/os.hpp @@ -765,6 +765,7 @@ class os: AllStatic { // random number generation static int random(); // return 32bit pseudorandom number + static int next_random(unsigned int rand_seed); // pure version of random() static void init_random(unsigned int initval); // initialize random sequence // Structured OS Exception support diff --git a/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java b/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java new file mode 100644 index 0000000000000..4077fb3dbb929 --- /dev/null +++ b/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020, 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 8252219 + * @requires vm.compiler2.enabled + * @summary Tests that different combinations of the options -XX:+StressIGVN and + * -XX:StressSeed=N are accepted. + * @run main/othervm -XX:+StressIGVN + * compiler.arguments.TestStressIGVNOptions + * @run main/othervm -XX:+StressIGVN -XX:StressSeed=42 + * compiler.arguments.TestStressIGVNOptions + */ + +package compiler.arguments; + +public class TestStressIGVNOptions { + + static public void main(String[] args) { + System.out.println("Passed"); + } +} + diff --git a/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java b/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java new file mode 100644 index 0000000000000..e256c46f9f8eb --- /dev/null +++ b/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2020, 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. + */ + +package compiler.debug; + +import java.nio.file.Paths; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.Asserts; + +/* + * @test + * @bug 8252219 + * @requires vm.compiler2.enabled + * @summary Tests that using -XX:+StressIGVN without -XX:StressSeed=N generates + * and logs a random seed. + * @library /test/lib / + * @run driver compiler.debug.TestGenerateStressSeed + */ + +public class TestGenerateStressSeed { + + static void sum(int n) { + int acc = 0; + for (int i = 0; i < n; i++) acc += i; + System.out.println(acc); + } + + public static void main(String[] args) throws Exception { + if (args.length == 0) { + String className = TestGenerateStressSeed.class.getName(); + String log = "test.log"; + String[] procArgs = { + "-Xcomp", "-XX:-TieredCompilation", + "-XX:CompileOnly=" + className + "::sum", "-XX:+StressIGVN", + "-XX:+LogCompilation", "-XX:LogFile=" + log, className, "10"}; + ProcessTools.createJavaProcessBuilder(procArgs).start().waitFor(); + new OutputAnalyzer(Paths.get(log)) + .shouldContain("stress_test seed"); + } else if (args.length > 0) { + sum(Integer.parseInt(args[0])); + } + } +} diff --git a/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java b/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java new file mode 100644 index 0000000000000..0b64a9cffe809 --- /dev/null +++ b/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020, 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. + */ + +package compiler.debug; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.Asserts; + +/* + * @test + * @bug 8252219 + * @requires vm.compiler2.enabled + * @summary Tests that compilations with the same seed yield the same IGVN + * trace, and compilations with different seeds yield different IGVN + * traces. + * @library /test/lib / + * @run driver compiler.debug.TestStressIGVN + */ + +public class TestStressIGVN { + + static String igvnTrace(int stressSeed) throws Exception { + String className = TestStressIGVN.class.getName(); + String[] procArgs = { + "-Xcomp", "-XX:-TieredCompilation", + "-XX:CompileOnly=" + className + "::sum", "-XX:+TraceIterativeGVN", + "-XX:+StressIGVN", "-XX:StressSeed=" + stressSeed, + className, "10"}; + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs); + OutputAnalyzer out = new OutputAnalyzer(pb.start()); + return out.getStdout(); + } + + static void sum(int n) { + int acc = 0; + for (int i = 0; i < n; i++) acc += i; + System.out.println(acc); + } + + public static void main(String[] args) throws Exception { + if (args.length == 0) { + Asserts.assertEQ(igvnTrace(10), igvnTrace(10), + "got different IGVN traces for the same seed"); + Asserts.assertNE(igvnTrace(10), igvnTrace(20), + "got the same IGVN trace for different seeds"); + } else if (args.length > 0) { + sum(Integer.parseInt(args[0])); + } + } +} From ca1ed16292492d256d076122d124be8978fce4c3 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Mon, 28 Sep 2020 07:12:48 +0000 Subject: [PATCH 33/79] 8253639: Change os::attempt_reserve_memory_at parameter order Reviewed-by: tschatzl, iklam --- src/hotspot/os/aix/os_aix.cpp | 4 ++-- src/hotspot/os/bsd/os_bsd.cpp | 6 +++--- src/hotspot/os/linux/os_linux.cpp | 6 +++--- src/hotspot/os/windows/os_windows.cpp | 12 ++++++------ src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp | 4 ++-- src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp | 4 ++-- src/hotspot/share/memory/virtualspace.cpp | 4 ++-- src/hotspot/share/prims/whitebox.cpp | 2 +- src/hotspot/share/runtime/os.cpp | 6 +++--- src/hotspot/share/runtime/os.hpp | 6 +++--- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index f0a89fbe294af..07a92fe1cee64 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -2532,7 +2532,7 @@ bool os::can_execute_large_page_memory() { return false; } -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, int file_desc) { assert(file_desc >= 0, "file_desc is not valid"); char* result = NULL; @@ -2550,7 +2550,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int f // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes) { char* addr = NULL; // Always round to os::vm_page_size(), which may be larger than 4K. diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index 7fbf762f778a6..64418a399ab4a 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -2115,9 +2115,9 @@ bool os::can_execute_large_page_memory() { return false; } -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, int file_desc) { assert(file_desc >= 0, "file_desc is not valid"); - char* result = pd_attempt_reserve_memory_at(bytes, requested_addr); + char* result = pd_attempt_reserve_memory_at(requested_addr, bytes); if (result != NULL) { if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == NULL) { vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); @@ -2129,7 +2129,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int f // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes) { // Assert only that the size is a multiple of the page size, since // that's all that mmap requires, and since that's all we really know // about at this low abstraction level. If we need higher alignment, diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 03691e39237ea..d16d90eed1201 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -4376,9 +4376,9 @@ bool os::can_execute_large_page_memory() { return UseTransparentHugePages || UseHugeTLBFS; } -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, int file_desc) { assert(file_desc >= 0, "file_desc is not valid"); - char* result = pd_attempt_reserve_memory_at(bytes, requested_addr); + char* result = pd_attempt_reserve_memory_at(requested_addr, bytes); if (result != NULL) { if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == NULL) { vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); @@ -4390,7 +4390,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int f // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes) { // Assert only that the size is a multiple of the page size, since // that's all that mmap requires, and since that's all we really know // about at this low abstraction level. If we need higher alignment, diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index ca93bc7df0569..0002bec4592c7 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -3063,8 +3063,8 @@ void os::split_reserved_memory(char *base, size_t size, size_t split) { assert(is_aligned(split_address, os::vm_allocation_granularity()), "Sanity"); release_memory(base, size); - attempt_reserve_memory_at(split, base); - attempt_reserve_memory_at(size - split, split_address); + attempt_reserve_memory_at(base, split); + attempt_reserve_memory_at(split_address, size - split); // NMT: nothing to do here. Since Windows implements the split by // releasing and re-reserving memory, the parts are already registered @@ -3099,7 +3099,7 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { os::release_memory(extra_base, extra_size); } - aligned_base = os::attempt_reserve_memory_at(size, aligned_base, file_desc); + aligned_base = os::attempt_reserve_memory_at(aligned_base, size, file_desc); } while (aligned_base == NULL); @@ -3108,12 +3108,12 @@ char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) { char* os::pd_reserve_memory(size_t bytes, size_t alignment_hint) { // Ignores alignment hint - return pd_attempt_reserve_memory_at(bytes, NULL /* addr */); + return pd_attempt_reserve_memory_at(NULL /* addr */, bytes); } // Reserve memory at an arbitrary address, only if that area is // available (and not reserved for something else). -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* addr) { +char* os::pd_attempt_reserve_memory_at(char* addr, size_t bytes) { assert((size_t)addr % os::vm_allocation_granularity() == 0, "reserve alignment"); assert(bytes % os::vm_page_size() == 0, "reserve page size"); @@ -3144,7 +3144,7 @@ char* os::pd_attempt_reserve_memory_at(size_t bytes, char* addr) { return res; } -char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr, int file_desc) { +char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, int file_desc) { assert(file_desc >= 0, "file_desc is not valid"); return map_memory_to_file(requested_addr, bytes, file_desc); } diff --git a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp index d4abb754498ad..fdef71aa32ae7 100644 --- a/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp +++ b/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp @@ -859,7 +859,7 @@ void os::workaround_expand_exec_shield_cs_limit() { */ char* hint = (char*)(Linux::initial_thread_stack_bottom() - (JavaThread::stack_guard_zone_size() + page_size)); - char* codebuf = os::attempt_reserve_memory_at(page_size, hint); + char* codebuf = os::attempt_reserve_memory_at(hint, page_size); if (codebuf == NULL) { // JDK-8197429: There may be a stack gap of one megabyte between @@ -867,7 +867,7 @@ void os::workaround_expand_exec_shield_cs_limit() { // Linux kernel workaround for CVE-2017-1000364. If we failed to // map our codebuf, try again at an address one megabyte lower. hint -= 1 * M; - codebuf = os::attempt_reserve_memory_at(page_size, hint); + codebuf = os::attempt_reserve_memory_at(hint, page_size); } if ((codebuf == NULL) || (!os::commit_memory(codebuf, page_size, true))) { diff --git a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp index 725bf93b03065..d0cc97424d7fa 100644 --- a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp +++ b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp @@ -220,7 +220,7 @@ static bool map_nvdimm_space(ReservedSpace rs) { return false; } // commit this memory in nv-dimm - char* ret = os::attempt_reserve_memory_at(rs.size(), rs.base(), _backing_fd); + char* ret = os::attempt_reserve_memory_at(rs.base(), rs.size(), _backing_fd); if (ret != rs.base()) { if (ret != NULL) { @@ -267,7 +267,7 @@ bool G1RegionToHeteroSpaceMapper::initialize() { assert(rs_dram.size() == rs_nvdimm.size() && rs_nvdimm.size() == MaxHeapSize, "They all should be same"); // Reserve dram memory - char* base = os::attempt_reserve_memory_at(rs_dram.size(), rs_dram.base()); + char* base = os::attempt_reserve_memory_at(rs_dram.base(), rs_dram.size()); if (base != rs_dram.base()) { if (base != NULL) { os::release_memory(base, rs_dram.size()); diff --git a/src/hotspot/share/memory/virtualspace.cpp b/src/hotspot/share/memory/virtualspace.cpp index 210659ca5d14b..a7a35db8abb4a 100644 --- a/src/hotspot/share/memory/virtualspace.cpp +++ b/src/hotspot/share/memory/virtualspace.cpp @@ -188,7 +188,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large, // important. If available space is not detected, return NULL. if (requested_address != 0) { - base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap); + base = os::attempt_reserve_memory_at(requested_address, size, _fd_for_heap); if (failed_to_reserve_as_requested(base, requested_address, size, false, _fd_for_heap != -1)) { // OS ignored requested address. Try different address. base = NULL; @@ -380,7 +380,7 @@ void ReservedHeapSpace::try_reserve_heap(size_t size, // important. If available space is not detected, return NULL. if (requested_address != 0) { - base = os::attempt_reserve_memory_at(size, requested_address, _fd_for_heap); + base = os::attempt_reserve_memory_at(requested_address, size, _fd_for_heap); } else { base = os::reserve_memory_with_fd(size, alignment, _fd_for_heap); } diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index fe1bf09552342..3bc077a1727b4 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -762,7 +762,7 @@ WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) WB_END WB_ENTRY(jlong, WB_NMTAttemptReserveMemoryAt(JNIEnv* env, jobject o, jlong addr, jlong size)) - addr = (jlong)(uintptr_t)os::attempt_reserve_memory_at((size_t)size, (char*)(uintptr_t)addr); + addr = (jlong)(uintptr_t)os::attempt_reserve_memory_at((char*)(uintptr_t)addr, (size_t)size); MemTracker::record_virtual_memory_type((address)addr, mtTest); return addr; diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index f584386b1d670..3bf24f00dc120 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -1684,15 +1684,15 @@ char* os::reserve_memory_with_fd(size_t bytes, size_t alignment_hint, int file_d return result; } -char* os::attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc) { +char* os::attempt_reserve_memory_at(char* addr, size_t bytes, int file_desc) { char* result = NULL; if (file_desc != -1) { - result = pd_attempt_reserve_memory_at(bytes, addr, file_desc); + result = pd_attempt_reserve_memory_at(addr, bytes, file_desc); if (result != NULL) { MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); } } else { - result = pd_attempt_reserve_memory_at(bytes, addr); + result = pd_attempt_reserve_memory_at(addr, bytes); if (result != NULL) { MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); } diff --git a/src/hotspot/share/runtime/os.hpp b/src/hotspot/share/runtime/os.hpp index 0fc38a5c24ab0..20785540a0bb9 100644 --- a/src/hotspot/share/runtime/os.hpp +++ b/src/hotspot/share/runtime/os.hpp @@ -115,8 +115,8 @@ class os: AllStatic { static char* pd_reserve_memory(size_t bytes, size_t alignment_hint); - static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); - static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc); + static char* pd_attempt_reserve_memory_at(char* addr, size_t bytes); + static char* pd_attempt_reserve_memory_at(char* addr, size_t bytes, int file_desc); static bool pd_commit_memory(char* addr, size_t bytes, bool executable); static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, @@ -325,7 +325,7 @@ class os: AllStatic { // Attempts to reserve the virtual memory at [addr, addr + bytes). // Does not overwrite existing mappings. - static char* attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1); + static char* attempt_reserve_memory_at(char* addr, size_t bytes, int file_desc = -1); // Split a reserved memory region [base, base+size) into two regions [base, base+split) and // [base+split, base+size). From 276fcee79572de64134625e0d184fc3c99713595 Mon Sep 17 00:00:00 2001 From: Wang Zhuo Date: Mon, 28 Sep 2020 07:34:01 +0000 Subject: [PATCH 34/79] 8252835: Revert fix for JDK-8246051 Reviewed-by: psandoz, dholmes, mikael --- src/hotspot/share/prims/unsafe.cpp | 2 - .../unsafe/TestUnsafeUnalignedSwap.java | 81 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 test/hotspot/jtreg/compiler/unsafe/TestUnsafeUnalignedSwap.java diff --git a/src/hotspot/share/prims/unsafe.cpp b/src/hotspot/share/prims/unsafe.cpp index 068078c58c34a..fd56d5931794e 100644 --- a/src/hotspot/share/prims/unsafe.cpp +++ b/src/hotspot/share/prims/unsafe.cpp @@ -951,7 +951,6 @@ UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetReference(JNIEnv *env, jobject unsafe UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) { oop p = JNIHandles::resolve(obj); - GuardUnsafeAccess guard(thread); if (p == NULL) { volatile jint* addr = (volatile jint*)index_oop_from_field_offset_long(p, offset); return RawAccess<>::atomic_cmpxchg(addr, e, x) == e; @@ -963,7 +962,6 @@ UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetInt(JNIEnv *env, jobject unsafe, jobj UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) { oop p = JNIHandles::resolve(obj); - GuardUnsafeAccess guard(thread); if (p == NULL) { volatile jlong* addr = (volatile jlong*)index_oop_from_field_offset_long(p, offset); return RawAccess<>::atomic_cmpxchg(addr, e, x) == e; diff --git a/test/hotspot/jtreg/compiler/unsafe/TestUnsafeUnalignedSwap.java b/test/hotspot/jtreg/compiler/unsafe/TestUnsafeUnalignedSwap.java deleted file mode 100644 index fa68477ccdb22..0000000000000 --- a/test/hotspot/jtreg/compiler/unsafe/TestUnsafeUnalignedSwap.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2020 Alibaba Group Holding Limited. 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 - * @library / /test/lib - * @bug 8246051 - * @summary A test for SIGBUS in aarch64 by unalgined unsafe access - * @requires os.arch=="aarch64" - * @run main/othervm/timeout=200 -XX:-Inline TestUnsafeUnalignedSwap - */ - -import sun.misc.Unsafe; -import java.lang.reflect.Field; -import java.util.*; -import jdk.test.lib.Asserts; - -public class TestUnsafeUnalignedSwap { - private final static Unsafe U; - private static long sum = 4; - static volatile long[] arrayLong = new long[1001]; - static volatile int[] arrayInt = new int[1001]; - static { - try { - Field f = Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - U = (Unsafe) f.get(null); - } catch (ReflectiveOperationException e) { - throw new InternalError(e); - } - } - // Bug 8246051 : Unsafe.compareAndSwapLong should not crash - public static void testCompareAndSwapLong() { - try { - if (U.compareAndSwapLong(arrayLong, Unsafe.ARRAY_LONG_BASE_OFFSET + 1, 3243, 2334)) { - sum++; - } else { - sum--; - } - } catch (InternalError e) { - System.out.println(e.getMessage()); - } - } - public static void testCompareAndSwapInt() { - try { - if (U.compareAndSwapInt(arrayInt, Unsafe.ARRAY_INT_BASE_OFFSET + 1, 3243, 2334)) { - sum++; - } else { - sum--; - } - } catch (InternalError e) { - System.out.println(e.getMessage()); - } - } - public static void test() { - testCompareAndSwapLong(); - testCompareAndSwapInt(); - } - public static void main(String[] args) { - test(); - } -} From e9c178276ffdb7d8152e75bb54e478ac1228f71d Mon Sep 17 00:00:00 2001 From: Thomas Schatzl Date: Mon, 28 Sep 2020 08:28:57 +0000 Subject: [PATCH 35/79] 8252752: Clear card table for old regions during scan in G1 Reviewed-by: kbarrett, iwalulya, ayang --- src/hotspot/share/gc/g1/g1CardTable.hpp | 5 +- .../share/gc/g1/g1CardTable.inline.hpp | 4 +- src/hotspot/share/gc/g1/g1CollectedHeap.cpp | 30 +++++-- src/hotspot/share/gc/g1/g1CollectedHeap.hpp | 18 +++- src/hotspot/share/gc/g1/g1RemSet.cpp | 88 +++++++++++++------ src/hotspot/share/gc/g1/g1RemSet.hpp | 4 +- 6 files changed, 109 insertions(+), 40 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1CardTable.hpp b/src/hotspot/share/gc/g1/g1CardTable.hpp index aa3b7946618c3..3540bb9411a81 100644 --- a/src/hotspot/share/gc/g1/g1CardTable.hpp +++ b/src/hotspot/share/gc/g1/g1CardTable.hpp @@ -84,6 +84,7 @@ class G1CardTable : public CardTable { } static CardValue g1_young_card_val() { return g1_young_gen; } + static CardValue g1_scanned_card_val() { return g1_card_already_scanned; } void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN; void g1_mark_as_young(const MemRegion& mr); @@ -103,8 +104,8 @@ class G1CardTable : public CardTable { // be inaccurate as it does not perform the dirtying atomically. inline size_t mark_region_dirty(size_t start_card_index, size_t num_cards); - // Mark the given range of cards as Scanned. All of these cards must be Dirty. - inline void mark_as_scanned(size_t start_card_index, size_t num_cards); + // Change the given range of dirty cards to "which". All of these cards must be Dirty. + inline void change_dirty_cards_to(size_t start_card_index, size_t num_cards, CardValue which); inline uint region_idx_for(CardValue* p); diff --git a/src/hotspot/share/gc/g1/g1CardTable.inline.hpp b/src/hotspot/share/gc/g1/g1CardTable.inline.hpp index 9e95cfc3630cd..ae9637a0d1456 100644 --- a/src/hotspot/share/gc/g1/g1CardTable.inline.hpp +++ b/src/hotspot/share/gc/g1/g1CardTable.inline.hpp @@ -77,14 +77,14 @@ inline size_t G1CardTable::mark_region_dirty(size_t start_card_index, size_t num return result; } -inline void G1CardTable::mark_as_scanned(size_t start_card_index, size_t num_cards) { +inline void G1CardTable::change_dirty_cards_to(size_t start_card_index, size_t num_cards, CardValue which) { CardValue* start = &_byte_map[start_card_index]; CardValue* const end = start + num_cards; while (start < end) { CardValue value = *start; assert(value == dirty_card_val(), "Must have been dirty %d start " PTR_FORMAT " " PTR_FORMAT, value, p2i(start), p2i(end)); - *start++ = g1_card_already_scanned; + *start++ = which; } } diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 14c534527886f..d55d10a25ebf5 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -3045,10 +3045,11 @@ void G1CollectedHeap::do_collection_pause_at_safepoint_helper(double target_paus collection_set()->optional_region_length()); pre_evacuate_collection_set(evacuation_info, &per_thread_states); + bool may_do_optional_evacuation = _collection_set.optional_region_length() != 0; // Actually do the work... - evacuate_initial_collection_set(&per_thread_states); + evacuate_initial_collection_set(&per_thread_states, may_do_optional_evacuation); - if (_collection_set.optional_region_length() != 0) { + if (may_do_optional_evacuation) { evacuate_optional_collection_set(&per_thread_states); } post_evacuate_collection_set(evacuation_info, &rdcqs, &per_thread_states); @@ -3814,10 +3815,11 @@ class G1EvacuateRegionsBaseTask : public AbstractGangTask { class G1EvacuateRegionsTask : public G1EvacuateRegionsBaseTask { G1RootProcessor* _root_processor; + bool _has_optional_evacuation_work; void scan_roots(G1ParScanThreadState* pss, uint worker_id) { _root_processor->evacuate_roots(pss, worker_id); - _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::ObjCopy); + _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::ObjCopy, _has_optional_evacuation_work); _g1h->rem_set()->scan_collection_set_regions(pss, worker_id, G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::CodeRoots, G1GCPhaseTimes::ObjCopy); } @@ -3838,13 +3840,16 @@ class G1EvacuateRegionsTask : public G1EvacuateRegionsBaseTask { G1ParScanThreadStateSet* per_thread_states, G1ScannerTasksQueueSet* task_queues, G1RootProcessor* root_processor, - uint num_workers) : + uint num_workers, + bool has_optional_evacuation_work) : G1EvacuateRegionsBaseTask("G1 Evacuate Regions", per_thread_states, task_queues, num_workers), - _root_processor(root_processor) + _root_processor(root_processor), + _has_optional_evacuation_work(has_optional_evacuation_work) { } }; -void G1CollectedHeap::evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states) { +void G1CollectedHeap::evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states, + bool has_optional_evacuation_work) { G1GCPhaseTimes* p = phase_times(); { @@ -3859,7 +3864,12 @@ void G1CollectedHeap::evacuate_initial_collection_set(G1ParScanThreadStateSet* p Ticks start_processing = Ticks::now(); { G1RootProcessor root_processor(this, num_workers); - G1EvacuateRegionsTask g1_par_task(this, per_thread_states, _task_queues, &root_processor, num_workers); + G1EvacuateRegionsTask g1_par_task(this, + per_thread_states, + _task_queues, + &root_processor, + num_workers, + has_optional_evacuation_work); task_time = run_task_timed(&g1_par_task); // Closing the inner scope will execute the destructor for the G1RootProcessor object. // To extract its code root fixup time we measure total time of this scope and @@ -3869,12 +3879,14 @@ void G1CollectedHeap::evacuate_initial_collection_set(G1ParScanThreadStateSet* p p->record_initial_evac_time(task_time.seconds() * 1000.0); p->record_or_add_code_root_fixup_time((total_processing - task_time).seconds() * 1000.0); + + rem_set()->complete_evac_phase(has_optional_evacuation_work); } class G1EvacuateOptionalRegionsTask : public G1EvacuateRegionsBaseTask { void scan_roots(G1ParScanThreadState* pss, uint worker_id) { - _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::OptObjCopy); + _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::OptObjCopy, true /* remember_already_scanned_cards */); _g1h->rem_set()->scan_collection_set_regions(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::OptCodeRoots, G1GCPhaseTimes::OptObjCopy); } @@ -3934,6 +3946,8 @@ void G1CollectedHeap::evacuate_optional_collection_set(G1ParScanThreadStateSet* evacuate_next_optional_regions(per_thread_states); phase_times()->record_or_add_optional_evac_time((Ticks::now() - start).seconds() * 1000.0); } + + rem_set()->complete_evac_phase(true /* has_more_than_one_evacuation_phase */); } _collection_set.abandon_optional_collection_set(per_thread_states); diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp index 94b1b2b97189c..4c98d5f38d9e1 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp @@ -785,7 +785,23 @@ class G1CollectedHeap : public CollectedHeap { void calculate_collection_set(G1EvacuationInfo& evacuation_info, double target_pause_time_ms); // Actually do the work of evacuating the parts of the collection set. - void evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states); + // The has_optional_evacuation_work flag for the initial collection set + // evacuation indicates whether one or more optional evacuation steps may + // follow. + // If not set, G1 can avoid clearing the card tables of regions that we scan + // for roots from the heap: when scanning the card table for dirty cards after + // all remembered sets have been dumped onto it, for optional evacuation we + // mark these cards as "Scanned" to know that we do not need to re-scan them + // in the additional optional evacuation passes. This means that in the "Clear + // Card Table" phase we need to clear those marks. However, if there is no + // optional evacuation, g1 can immediately clean the dirty cards it encounters + // as nobody else will be looking at them again, saving the clear card table + // work later. + // This case is very common (young only collections and most mixed gcs), so + // depending on the ratio between scanned and evacuated regions (which g1 always + // needs to clear), this is a big win. + void evacuate_initial_collection_set(G1ParScanThreadStateSet* per_thread_states, + bool has_optional_evacuation_work); void evacuate_optional_collection_set(G1ParScanThreadStateSet* per_thread_states); private: // Evacuate the next set of optional regions. diff --git a/src/hotspot/share/gc/g1/g1RemSet.cpp b/src/hotspot/share/gc/g1/g1RemSet.cpp index da72d81825463..98809fc08b461 100644 --- a/src/hotspot/share/gc/g1/g1RemSet.cpp +++ b/src/hotspot/share/gc/g1/g1RemSet.cpp @@ -131,8 +131,17 @@ class G1RemSetScanState : public CHeapObj { } private: - // The complete set of regions which card table needs to be cleared at the end of GC because - // we scribbled all over them. + // The complete set of regions which card table needs to be cleared at the end + // of GC because we scribbled over these card tables. + // + // Regions may be added for two reasons: + // - they were part of the collection set: they may contain g1_young_card_val + // or regular card marks that we never scan so we must always clear their card + // table + // - or in case g1 does an optional evacuation pass, g1 marks the cards in there + // as g1_scanned_card_val. If G1 only did an initial evacuation pass, the + // scanning already cleared these cards. In that case they are not in this set + // at the end of the collection. G1DirtyRegions* _all_dirty_regions; // The set of regions which card table needs to be scanned for new dirty cards // in the current evacuation pass. @@ -321,9 +330,8 @@ class G1RemSetScanState : public CHeapObj { } void prepare_for_merge_heap_roots() { - _all_dirty_regions->merge(_next_dirty_regions); + assert(_next_dirty_regions->size() == 0, "next dirty regions must be empty"); - _next_dirty_regions->reset(); for (size_t i = 0; i < _max_reserved_regions; i++) { _card_table_scan_state[i] = 0; } @@ -331,6 +339,13 @@ class G1RemSetScanState : public CHeapObj { ::memset(_region_scan_chunks, false, _num_total_scan_chunks * sizeof(*_region_scan_chunks)); } + void complete_evac_phase(bool merge_dirty_regions) { + if (merge_dirty_regions) { + _all_dirty_regions->merge(_next_dirty_regions); + } + _next_dirty_regions->reset(); + } + // Returns whether the given region contains cards we need to scan. The remembered // set and other sources may contain cards that // - are in uncommitted regions @@ -374,8 +389,6 @@ class G1RemSetScanState : public CHeapObj { } void cleanup(WorkGang* workers) { - _all_dirty_regions->merge(_next_dirty_regions); - clear_card_table(workers); delete _all_dirty_regions; @@ -448,7 +461,7 @@ class G1RemSetScanState : public CHeapObj { #ifdef ASSERT HeapRegion* hr = G1CollectedHeap::heap()->region_at(region); assert(hr->in_collection_set(), - "Only add young regions to all dirty regions directly but %u is %s", + "Only add collection set regions to all dirty regions directly but %u is %s", hr->hrm_index(), hr->get_short_type_str()); #endif _all_dirty_regions->add_dirty_region(region); @@ -641,6 +654,7 @@ class G1ScanHRForRegionClosure : public HeapRegionClosure { // The address to which this thread already scanned (walked the heap) up to during // card scanning (exclusive). HeapWord* _scanned_to; + G1CardTable::CardValue _scanned_card_value; HeapWord* scan_memregion(uint region_idx_for_card, MemRegion mr) { HeapRegion* const card_region = _g1h->region_at(region_idx_for_card); @@ -677,7 +691,7 @@ class G1ScanHRForRegionClosure : public HeapRegionClosure { } ALWAYSINLINE void do_card_block(uint const region_idx, size_t const first_card, size_t const num_cards) { - _ct->mark_as_scanned(first_card, num_cards); + _ct->change_dirty_cards_to(first_card, num_cards, _scanned_card_value); do_claimed_block(region_idx, first_card, num_cards); _blocks_scanned++; } @@ -727,7 +741,8 @@ class G1ScanHRForRegionClosure : public HeapRegionClosure { G1ScanHRForRegionClosure(G1RemSetScanState* scan_state, G1ParScanThreadState* pss, uint worker_id, - G1GCPhaseTimes::GCParPhases phase) : + G1GCPhaseTimes::GCParPhases phase, + bool remember_already_scanned_cards) : _g1h(G1CollectedHeap::heap()), _ct(_g1h->card_table()), _bot(_g1h->bot()), @@ -740,7 +755,9 @@ class G1ScanHRForRegionClosure : public HeapRegionClosure { _chunks_claimed(0), _rem_set_root_scan_time(), _rem_set_trim_partially_time(), - _scanned_to(NULL) { + _scanned_to(NULL), + _scanned_card_value(remember_already_scanned_cards ? G1CardTable::g1_scanned_card_val() + : G1CardTable::clean_card_val()) { } bool do_heap_region(HeapRegion* r) { @@ -765,10 +782,11 @@ class G1ScanHRForRegionClosure : public HeapRegionClosure { }; void G1RemSet::scan_heap_roots(G1ParScanThreadState* pss, - uint worker_id, - G1GCPhaseTimes::GCParPhases scan_phase, - G1GCPhaseTimes::GCParPhases objcopy_phase) { - G1ScanHRForRegionClosure cl(_scan_state, pss, worker_id, scan_phase); + uint worker_id, + G1GCPhaseTimes::GCParPhases scan_phase, + G1GCPhaseTimes::GCParPhases objcopy_phase, + bool remember_already_scanned_cards) { + G1ScanHRForRegionClosure cl(_scan_state, pss, worker_id, scan_phase, remember_already_scanned_cards); _scan_state->iterate_dirty_regions_from(&cl, worker_id); G1GCPhaseTimes* p = _g1p->phase_times(); @@ -891,18 +909,11 @@ void G1RemSet::scan_collection_set_regions(G1ParScanThreadState* pss, void G1RemSet::prepare_region_for_scan(HeapRegion* region) { uint hrm_index = region->hrm_index(); - if (region->in_collection_set()) { - // Young regions had their card table marked as young at their allocation; - // we need to make sure that these marks are cleared at the end of GC, *but* - // they should not be scanned for cards. - // So directly add them to the "all_dirty_regions". - // Same for regions in the (initial) collection set: they may contain cards from - // the log buffers, make sure they are cleaned. - _scan_state->add_all_dirty_region(hrm_index); - } else if (region->is_old_or_humongous_or_archive()) { + if (region->is_old_or_humongous_or_archive()) { _scan_state->set_scan_top(hrm_index, region->top()); } else { - assert(region->is_free(), "Should only be free region at this point %s", region->get_type_str()); + assert(region->in_collection_set() || region->is_free(), + "Should only be free or in the collection set at this point %s", region->get_type_str()); } } @@ -984,13 +995,34 @@ class G1MergeHeapRootsTask : public AbstractGangTask { } } - virtual bool do_heap_region(HeapRegion* r) { + // Helper to put the remembered set cards for these regions onto the card + // table. + // + // Called directly for humongous starts regions because we should not add + // humongous eager reclaim candidates to the "all" list of regions to + // clear the card table by default as we do not know yet whether this region + // will be reclaimed (and reused). + // If the humongous region contains dirty cards, g1 will scan them + // because dumping the remembered set entries onto the card table will add + // the humongous region to the "dirty" region list to scan. Then scanning + // either clears the card during scan (if there is only an initial evacuation + // pass) or the "dirty" list will be merged with the "all" list later otherwise. + // (And there is no problem either way if the region does not contain dirty + // cards). + void dump_rem_set_for_region(HeapRegion* r) { assert(r->in_collection_set() || r->is_starts_humongous(), "must be"); HeapRegionRemSet* rem_set = r->rem_set(); if (!rem_set->is_empty()) { rem_set->iterate_prts(*this); } + } + + virtual bool do_heap_region(HeapRegion* r) { + assert(r->in_collection_set(), "must be"); + + _scan_state->add_all_dirty_region(r->hrm_index()); + dump_rem_set_for_region(r); return false; } @@ -1022,7 +1054,7 @@ class G1MergeHeapRootsTask : public AbstractGangTask { guarantee(r->rem_set()->occupancy_less_or_equal_than(G1RSetSparseRegionEntries), "Found a not-small remembered set here. This is inconsistent with previous assumptions."); - _cl.do_heap_region(r); + _cl.dump_rem_set_for_region(r); // We should only clear the card based remembered set here as we will not // implicitly rebuild anything else during eager reclaim. Note that at the moment @@ -1239,6 +1271,10 @@ void G1RemSet::merge_heap_roots(bool initial_evacuation) { } } +void G1RemSet::complete_evac_phase(bool has_more_than_one_evacuation_phase) { + _scan_state->complete_evac_phase(has_more_than_one_evacuation_phase); +} + void G1RemSet::exclude_region_from_scan(uint region_idx) { _scan_state->clear_scan_top(region_idx); } diff --git a/src/hotspot/share/gc/g1/g1RemSet.hpp b/src/hotspot/share/gc/g1/g1RemSet.hpp index 534257ddacc18..c44ea34c739ad 100644 --- a/src/hotspot/share/gc/g1/g1RemSet.hpp +++ b/src/hotspot/share/gc/g1/g1RemSet.hpp @@ -84,13 +84,15 @@ class G1RemSet: public CHeapObj { void scan_heap_roots(G1ParScanThreadState* pss, uint worker_id, G1GCPhaseTimes::GCParPhases scan_phase, - G1GCPhaseTimes::GCParPhases objcopy_phase); + G1GCPhaseTimes::GCParPhases objcopy_phase, + bool remember_already_scanned_cards); // Merge cards from various sources (remembered sets, hot card cache, log buffers) // and calculate the cards that need to be scanned later (via scan_heap_roots()). // If initial_evacuation is set, this is called during the initial evacuation. void merge_heap_roots(bool initial_evacuation); + void complete_evac_phase(bool has_more_than_one_evacuation_phase); // Prepare for and cleanup after scanning the heap roots. Must be called // once before and after in sequential code. void prepare_for_scan_heap_roots(); From c2692f88756d6760fa0e2c4b8e64cdeaa03d32f2 Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Mon, 28 Sep 2020 09:06:31 +0000 Subject: [PATCH 36/79] =?UTF-8?q?8225329:=20-XX:+PrintBiasedLockingStatist?= =?UTF-8?q?ics=20causes=20crash=20during=20initia=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: stuefe, dholmes --- src/hotspot/cpu/x86/macroAssembler_x86.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/cpu/x86/macroAssembler_x86.cpp b/src/hotspot/cpu/x86/macroAssembler_x86.cpp index e975a6eb8427d..b1521cb6fe292 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86.cpp @@ -1156,7 +1156,7 @@ void MacroAssembler::biased_locking_enter(Register lock_reg, // the prototype header is no longer biased and we have to revoke // the bias on this object. testptr(header_reg, markWord::biased_lock_mask_in_place); - jccb(Assembler::notZero, try_revoke_bias); + jcc(Assembler::notZero, try_revoke_bias); // Biasing is still enabled for this data type. See whether the // epoch of the current bias is still valid, meaning that the epoch From 8e87d46f41e663f5d0506554054417e3049175e7 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 28 Sep 2020 09:12:26 +0000 Subject: [PATCH 37/79] 8252857: AArch64: Shenandoah C1 CAS is not sequentially consistent Reviewed-by: rkennke, shade --- .../c1/shenandoahBarrierSetC1_aarch64.cpp | 13 ++++- .../shenandoahBarrierSetAssembler_aarch64.cpp | 50 ++++--------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/hotspot/cpu/aarch64/gc/shenandoah/c1/shenandoahBarrierSetC1_aarch64.cpp b/src/hotspot/cpu/aarch64/gc/shenandoah/c1/shenandoahBarrierSetC1_aarch64.cpp index 44d73a46f439c..b3530509b032a 100644 --- a/src/hotspot/cpu/aarch64/gc/shenandoah/c1/shenandoahBarrierSetC1_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/gc/shenandoah/c1/shenandoahBarrierSetC1_aarch64.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved. + * Copyright (c) 2018, 2020, Red Hat, Inc. 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,7 +48,16 @@ void LIR_OpShenandoahCompareAndSwap::emit_code(LIR_Assembler* masm) { newval = tmp2; } - ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm->masm(), addr, cmpval, newval, /*acquire*/ false, /*release*/ true, /*is_cae*/ false, result); + ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm->masm(), addr, cmpval, newval, /*acquire*/ true, /*release*/ true, /*is_cae*/ false, result); + + if (is_c1_or_interpreter_only()) { + // The membar here is necessary to prevent reordering between the + // release store in the CAS above and a subsequent volatile load. + // However for tiered compilation C1 inserts a full barrier before + // volatile loads which means we don't need an additional barrier + // here (see LIRGenerator::volatile_field_load()). + __ membar(__ AnyAny); + } } #undef __ diff --git a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp index dd54bf8d6ed01..c2d53df4f67dc 100644 --- a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp @@ -459,39 +459,10 @@ void ShenandoahBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler // from-space, or it refers to the to-space version of an object that // is being evacuated out of from-space. // -// By default, this operation implements sequential consistency and the -// value held in the result register following execution of the -// generated code sequence is 0 to indicate failure of CAS, non-zero -// to indicate success. Arguments support variations on this theme: -// -// acquire: Allow relaxation of the memory ordering on CAS from -// sequential consistency. This can be useful when -// sequential consistency is not required, such as when -// another sequentially consistent operation is already -// present in the execution stream. If acquire, successful -// execution has the side effect of assuring that memory -// values updated by other threads and "released" will be -// visible to any read operations perfomed by this thread -// which follow this operation in program order. This is a -// special optimization that should not be enabled by default. -// release: Allow relaxation of the memory ordering on CAS from -// sequential consistency. This can be useful when -// sequential consistency is not required, such as when -// another sequentially consistent operation is already -// present in the execution stream. If release, successful -// completion of this operation has the side effect of -// assuring that all writes to memory performed by this -// thread that precede this operation in program order are -// visible to all other threads that subsequently "acquire" -// before reading the respective memory values. This is a -// special optimization that should not be enabled by default. -// is_cae: This turns CAS (compare and swap) into CAE (compare and -// exchange). This HotSpot convention is that CAE makes -// available to the caller the "failure witness", which is -// the value that was stored in memory which did not match -// the expected value. If is_cae, the result is the value -// most recently fetched from addr rather than a boolean -// success indicator. +// By default the value held in the result register following execution +// of the generated code sequence is 0 to indicate failure of CAS, +// non-zero to indicate success. If is_cae, the result is the value most +// recently fetched from addr rather than a boolean success indicator. // // Clobbers rscratch1, rscratch2 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, @@ -526,11 +497,10 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, __ bind (step4); // Step 4. CAS has failed because the value most recently fetched - // from addr (which is now held in tmp1) is no longer the from-space - // pointer held in tmp2. If a different thread replaced the - // in-memory value with its equivalent to-space pointer, then CAS - // may still be able to succeed. The value held in the expected - // register has not changed. + // from addr is no longer the from-space pointer held in tmp2. If a + // different thread replaced the in-memory value with its equivalent + // to-space pointer, then CAS may still be able to succeed. The + // value held in the expected register has not changed. // // It is extremely rare we reach this point. For this reason, the // implementation opts for smaller rather than potentially faster @@ -603,8 +573,8 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, // Note that macro implementation of __cmpxchg cannot use same register // tmp2 for result and expected since it overwrites result before it // compares result with expected. - __ cmpxchg(addr, tmp2, new_val, size, acquire, release, false, tmp1); - // EQ flag set iff success. tmp2 holds value fetched. + __ cmpxchg(addr, tmp2, new_val, size, acquire, release, false, noreg); + // EQ flag set iff success. tmp2 holds value fetched, tmp1 (rscratch1) clobbered. // If fetched value did not equal the new expected, this could // still be a false negative because some other thread may have From 840aa2b79e6cbf26d1bee5297b12d2a5988ffd7b Mon Sep 17 00:00:00 2001 From: Robin Westberg Date: Mon, 28 Sep 2020 09:31:51 +0000 Subject: [PATCH 38/79] 8253424: Add support for running pre-submit testing using GitHub Actions Reviewed-by: ehelin, erikj --- .github/workflows/submit.yml | 861 +++++++++++++++++++++++++++++++++++ make/conf/test-dependencies | 43 ++ 2 files changed, 904 insertions(+) create mode 100644 .github/workflows/submit.yml create mode 100644 make/conf/test-dependencies diff --git a/.github/workflows/submit.yml b/.github/workflows/submit.yml new file mode 100644 index 0000000000000..f29a401a12916 --- /dev/null +++ b/.github/workflows/submit.yml @@ -0,0 +1,861 @@ +name: Pre-submit tests + +on: + push: + branches-ignore: + - master + workflow_dispatch: + inputs: + platforms: + description: "Platform(s) to execute on" + required: true + default: "Linux x64, Windows x64, macOS x64" + +jobs: + prerequisites: + name: Prerequisites + runs-on: "ubuntu-latest" + outputs: + should_run: ${{ steps.check_submit.outputs.should_run }} + platform_linux_x64: ${{ steps.check_platforms.outputs.platform_linux_x64 }} + platform_windows_x64: ${{ steps.check_platforms.outputs.platform_windows_x64 }} + platform_macos_x64: ${{ steps.check_platforms.outputs.platform_macos_x64 }} + dependencies: ${{ steps.check_deps.outputs.dependencies }} + + steps: + - name: Check if submit tests should actually run depending on secrets and manual triggering + id: check_submit + run: echo "::set-output name=should_run::${{ github.event.inputs.platforms != '' || (!secrets.JDK_SUBMIT_FILTER || startsWith(github.ref, 'refs/heads/submit/')) }}" + + - name: Check which platforms should be included + id: check_platforms + run: | + echo "::set-output name=platform_linux_x64::${{ contains(github.event.inputs.platforms, 'linux x64') || (github.event.inputs.platforms == '' && (secrets.JDK_SUBMIT_PLATFORMS == '' || contains(secrets.JDK_SUBMIT_PLATFORMS, 'linux x64'))) }}" + echo "::set-output name=platform_windows_x64::${{ contains(github.event.inputs.platforms, 'windows x64') || (github.event.inputs.platforms == '' && (secrets.JDK_SUBMIT_PLATFORMS == '' || contains(secrets.JDK_SUBMIT_PLATFORMS, 'windows x64'))) }}" + echo "::set-output name=platform_macos_x64::${{ contains(github.event.inputs.platforms, 'macos x64') || (github.event.inputs.platforms == '' && (secrets.JDK_SUBMIT_PLATFORMS == '' || contains(secrets.JDK_SUBMIT_PLATFORMS, 'macos x64'))) }}" + if: steps.check_submit.outputs.should_run != 'false' + + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + if: steps.check_submit.outputs.should_run != 'false' + + - name: Checkout the source + uses: actions/checkout@v2 + with: + path: jdk + if: steps.check_submit.outputs.should_run != 'false' + + - name: Determine versions and locations to be used for dependencies + id: check_deps + run: "echo ::set-output name=dependencies::`cat make/autoconf/version-numbers make/conf/test-dependencies | sed -e '1i {' -e 's/#.*//g' -e 's/\"//g' -e 's/\\(.*\\)=\\(.*\\)/\"\\1\": \"\\2\",/g' -e '$s/,\\s\\{0,\\}$/\\}/'`" + working-directory: jdk + if: steps.check_submit.outputs.should_run != 'false' + + - name: Print extracted dependencies to the log + run: "echo '${{ steps.check_deps.outputs.dependencies }}'" + if: steps.check_submit.outputs.should_run != 'false' + + - name: Determine the jtreg ref to checkout + run: "echo ::set-env name=JTREG_REF::jtreg${{ fromJson(steps.check_deps.outputs.dependencies).JTREG_VERSION }}-${{ fromJson(steps.check_deps.outputs.dependencies).JTREG_BUILD }}" + if: steps.check_submit.outputs.should_run != 'false' + + - name: Check if a jtreg image is present in the cache + id: jtreg + uses: actions/cache@v2 + with: + path: ~/jtreg/ + key: jtreg-${{ env.JTREG_REF }}-v1 + if: steps.check_submit.outputs.should_run != 'false' + + - name: Checkout the jtreg source + uses: actions/checkout@v2 + with: + repository: "openjdk/jtreg" + ref: ${{ env.JTREG_REF }} + path: jtreg + if: steps.check_submit.outputs.should_run != 'false' && steps.jtreg.outputs.cache-hit != 'true' + + - name: Build jtreg + run: sh make/build-all.sh ${JAVA_HOME} + working-directory: jtreg + if: steps.check_submit.outputs.should_run != 'false' && steps.jtreg.outputs.cache-hit != 'true' + + - name: Move jtreg image to destination folder + run: mv build/images/jtreg ~/ + working-directory: jtreg + if: steps.check_submit.outputs.should_run != 'false' && steps.jtreg.outputs.cache-hit != 'true' + + - name: Store jtreg for use by later steps + uses: actions/upload-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + if: steps.check_submit.outputs.should_run != 'false' + + linux_x64_build: + name: Linux x64 + runs-on: "ubuntu-latest" + needs: prerequisites + if: needs.prerequisites.outputs.should_run != 'false' && needs.prerequisites.outputs.platform_linux_x64 != 'false' + + strategy: + fail-fast: false + matrix: + flavor: + - build release + - build debug + - build hotspot no-pch + include: + - flavor: build debug + flags: --enable-debug + artifact: -debug + - flavor: build hotspot no-pch + flags: --disable-precompiled-headers + build-target: hotspot + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + + - name: Checkout the source + uses: actions/checkout@v2 + with: + path: jdk + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + wget -O "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" "${BOOT_JDK_URL}" + echo "${BOOT_JDK_SHA256} ${HOME}/bootjdk/${BOOT_JDK_FILENAME}" | sha256sum -c >/dev/null - + tar -xf "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" -C "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + mv "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"*/* "${HOME}/bootjdk/${BOOT_JDK_VERSION}/" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Checkout gtest sources + uses: actions/checkout@v2 + with: + repository: "google/googletest" + ref: "release-${{ fromJson(needs.prerequisites.outputs.dependencies).GTEST_VERSION }}" + path: gtest + + - name: Install dependencies + run: sudo apt-get install libxrandr-dev libxtst-dev libcups2-dev libasound2-dev + + - name: Configure + run: > + bash configure + --with-conf-name=linux-x64 + ${{ matrix.flags }} + --with-version-opt=${GITHUB_ACTOR}-${GITHUB_SHA} + --with-version-build=0 + --with-boot-jdk=${HOME}/bootjdk/${BOOT_JDK_VERSION} + --with-jtreg=${HOME}/jtreg + --with-gtest=${GITHUB_WORKSPACE}/gtest + --with-default-make-target="product-bundles test-bundles" + --with-zlib=system + --enable-jtreg-failure-handler + working-directory: jdk + + - name: Build + run: make CONF_NAME=linux-x64 ${{ matrix.build-target }} + working-directory: jdk + + - name: Persist test bundles + uses: actions/upload-artifact@v2 + with: + name: transient_jdk-linux-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: | + jdk/build/linux-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}.tar.gz + jdk/build/linux-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}.tar.gz + if: matrix.build-target == false + + linux_x64_test: + name: Linux x64 + runs-on: "ubuntu-latest" + needs: + - prerequisites + - linux_x64_build + + strategy: + fail-fast: false + matrix: + test: + - jdk/tier1 part 1 + - jdk/tier1 part 2 + - jdk/tier1 part 3 + - langtools/tier1 + - hs/tier1 common + - hs/tier1 compiler + - hs/tier1 gc + - hs/tier1 runtime + - hs/tier1 serviceability + include: + - test: jdk/tier1 part 1 + suites: test/jdk/:tier1_part1 + - test: jdk/tier1 part 2 + suites: test/jdk/:tier1_part2 + - test: jdk/tier1 part 3 + suites: test/jdk/:tier1_part3 + - test: langtools/tier1 + suites: test/langtools/:tier1 + - test: hs/tier1 common + suites: test/hotspot/jtreg/:tier1_common + artifact: -debug + - test: hs/tier1 compiler + suites: test/hotspot/jtreg/:tier1_compiler + artifact: -debug + - test: hs/tier1 gc + suites: test/hotspot/jtreg/:tier1_gc + artifact: -debug + - test: hs/tier1 runtime + suites: test/hotspot/jtreg/:tier1_runtime + artifact: -debug + - test: hs/tier1 serviceability + suites: test/hotspot/jtreg/:tier1_serviceability + artifact: -debug + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + + - name: Checkout the source + uses: actions/checkout@v2 + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + wget -O "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" "${BOOT_JDK_URL}" + echo "${BOOT_JDK_SHA256} ${HOME}/bootjdk/${BOOT_JDK_FILENAME}" | sha256sum -c >/dev/null - + tar -xf "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" -C "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + mv "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"*/* "${HOME}/bootjdk/${BOOT_JDK_VERSION}/" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Restore build artifacts + uses: actions/download-artifact@v2 + with: + name: transient_jdk-linux-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: ~/jdk-linux-x64${{ matrix.artifact }} + + - name: Unpack jdk + run: | + mkdir -p "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}" + + - name: Unpack tests + run: | + mkdir -p "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}" + + - name: Find root of jdk image dir + run: | + imageroot=`find ${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }} -name release -type f` + echo "::set-env name=imageroot::`dirname ${imageroot}`" + + - name: Run tests + run: > + JDK_IMAGE_DIR=${{ env.imageroot }} + TEST_IMAGE_DIR=${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }} + BOOT_JDK=${HOME}/bootjdk/${BOOT_JDK_VERSION} + JT_HOME=${HOME}/jtreg + make test-prebuilt + CONF_NAME=run-test-prebuilt + LOG_CMDLINES=true + JTREG_VERBOSE=fail,error,time + TEST="${{ matrix.suites }}" + TEST_OPTS_JAVA_OPTIONS= + JTREG_KEYWORDS="!headful" + + - name: Create suitable test log artifact name + if: always() + run: echo "::set-env name=logsuffix::`echo ${{ matrix.test }} | sed -e 's!/!_!'g -e 's! !_!'g`" + + - name: Persist test logs + if: always() + uses: actions/upload-artifact@v2 + with: + name: linux-x64${{ matrix.artifact }}_testlogs_${{ env.logsuffix }} + path: build/*/test-results + continue-on-error: true + + windows_x64_build: + name: Windows x64 + runs-on: "windows-latest" + needs: prerequisites + if: needs.prerequisites.outputs.should_run != 'false' && needs.prerequisites.outputs.platform_windows_x64 != 'false' + + strategy: + fail-fast: false + matrix: + flavor: + - build release + - build debug + include: + - flavor: build debug + flags: --enable-debug + artifact: -debug + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo ("::set-env name=bundleid::$env:GITHUB_ACTOR" + "_" + (-join "$env:GITHUB_SHA"[0..7])) + + - name: Restore cygwin packages from cache + id: cygwin + uses: actions/cache@v2 + with: + path: ~/cygwin/packages + key: cygwin-packages-${{ runner.os }}-v1 + + - name: Install cygwin + run: | + New-Item -Force -ItemType directory -Path "$HOME\cygwin" + & curl -L "https://www.cygwin.com/setup-x86_64.exe" -o "$HOME/cygwin/setup-x86_64.exe" + Start-Process -FilePath "$HOME\cygwin\setup-x86_64.exe" -ArgumentList "--quiet-mode --packages autoconf,make,zip,unzip --root $HOME\cygwin\cygwin64 --local-package-dir $HOME\cygwin\packages --site http://mirrors.kernel.org/sourceware/cygwin --no-desktop --no-shortcuts --no-startmenu --no-admin" -Wait -NoNewWindow + + - name: Checkout the source + uses: actions/checkout@v2 + with: + path: jdk + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p "$HOME\bootjdk\$env:BOOT_JDK_VERSION" + & curl -L "$env:BOOT_JDK_URL" -o "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" + $FileHash = Get-FileHash -Algorithm SHA256 "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" + $FileHash.Hash -eq $env:BOOT_JDK_SHA256 + & tar -xf "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" -C "$HOME/bootjdk/$env:BOOT_JDK_VERSION" + Get-ChildItem "$HOME\bootjdk\$env:BOOT_JDK_VERSION\*\*" | Move-Item -Destination "$HOME\bootjdk\$env:BOOT_JDK_VERSION" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Checkout gtest sources + uses: actions/checkout@v2 + with: + repository: "google/googletest" + ref: "release-${{ fromJson(needs.prerequisites.outputs.dependencies).GTEST_VERSION }}" + path: gtest + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Configure + run: > + $env:Path = "$HOME\cygwin\cygwin64\bin;$HOME\cygwin\cygwin64\bin;$env:Path" ; + $env:Path = $env:Path -split ";" -match "C:\\Windows|PowerShell|cygwin" -join ";" ; + & bash configure + --with-conf-name=windows-x64 + ${{ matrix.flags }} + --with-version-opt="$env:GITHUB_ACTOR-$env:GITHUB_SHA" + --with-version-build=0 + --with-boot-jdk="$HOME/bootjdk/$env:BOOT_JDK_VERSION" + --with-jtreg="$HOME/jtreg" + --with-gtest="$env:GITHUB_WORKSPACE/gtest" + --with-default-make-target="product-bundles test-bundles" + --enable-jtreg-failure-handler + working-directory: jdk + + - name: Build + run: | + $env:Path = "$HOME\cygwin\cygwin64\bin;$HOME\cygwin\cygwin64\bin;$env:Path" ; + $env:Path = $env:Path -split ";" -match "C:\\Windows|PowerShell|cygwin" -join ";" ; + & make CONF_NAME=windows-x64 ${{ matrix.build-target }} + working-directory: jdk + + - name: Persist test bundles + uses: actions/upload-artifact@v2 + with: + name: transient_jdk-windows-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: | + jdk/build/windows-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}.zip + jdk/build/windows-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin-tests${{ matrix.artifact }}.tar.gz + jdk/build/windows-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}-symbols.tar.gz + if: matrix.build-target == false + + windows_x64_test: + name: Windows x64 + runs-on: "windows-latest" + needs: + - prerequisites + - windows_x64_build + + strategy: + fail-fast: false + matrix: + test: + - jdk/tier1 part 1 + - jdk/tier1 part 2 + - jdk/tier1 part 3 + - langtools/tier1 + - hs/tier1 common + - hs/tier1 compiler + - hs/tier1 gc + - hs/tier1 runtime + - hs/tier1 serviceability + include: + - test: jdk/tier1 part 1 + suites: test/jdk/:tier1_part1 + - test: jdk/tier1 part 2 + suites: test/jdk/:tier1_part2 + - test: jdk/tier1 part 3 + suites: test/jdk/:tier1_part3 + - test: langtools/tier1 + suites: test/langtools/:tier1 + - test: hs/tier1 common + suites: test/hotspot/jtreg/:tier1_common + artifact: -debug + - test: hs/tier1 compiler + suites: test/hotspot/jtreg/:tier1_compiler + artifact: -debug + - test: hs/tier1 gc + suites: test/hotspot/jtreg/:tier1_gc + artifact: -debug + - test: hs/tier1 runtime + suites: test/hotspot/jtreg/:tier1_runtime + artifact: -debug + - test: hs/tier1 serviceability + suites: test/hotspot/jtreg/:tier1_serviceability + artifact: -debug + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).WINDOWS_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo ("::set-env name=bundleid::$env:GITHUB_ACTOR" + "_" + (-join "$env:GITHUB_SHA"[0..7])) + + - name: Checkout the source + uses: actions/checkout@v2 + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p "$HOME\bootjdk\$env:BOOT_JDK_VERSION" + & curl -L "$env:BOOT_JDK_URL" -o "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" + $FileHash = Get-FileHash -Algorithm SHA256 "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" + $FileHash.Hash -eq $env:BOOT_JDK_SHA256 + & tar -xf "$HOME/bootjdk/$env:BOOT_JDK_FILENAME" -C "$HOME/bootjdk/$env:BOOT_JDK_VERSION" + Get-ChildItem "$HOME\bootjdk\$env:BOOT_JDK_VERSION\*\*" | Move-Item -Destination "$HOME\bootjdk\$env:BOOT_JDK_VERSION" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Restore cygwin packages from cache + id: cygwin + uses: actions/cache@v2 + with: + path: ~/cygwin/packages + key: cygwin-packages-${{ runner.os }}-v1 + + - name: Install cygwin + run: | + New-Item -Force -ItemType directory -Path "$HOME\cygwin" + & curl -L "https://www.cygwin.com/setup-x86_64.exe" -o "$HOME/cygwin/setup-x86_64.exe" + Start-Process -FilePath "$HOME\cygwin\setup-x86_64.exe" -ArgumentList "--quiet-mode --packages autoconf,make,zip,unzip --root $HOME\cygwin\cygwin64 --local-package-dir $HOME\cygwin\packages --site http://mirrors.kernel.org/sourceware/cygwin --no-desktop --no-shortcuts --no-startmenu --no-admin" -Wait -NoNewWindow + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Restore build artifacts + uses: actions/download-artifact@v2 + with: + name: transient_jdk-windows-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: ~/jdk-windows-x64${{ matrix.artifact }} + + - name: Unpack jdk + run: | + mkdir -p "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}.zip" -C "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}" + + - name: Unpack symbols + run: | + mkdir -p "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}-symbols" + tar -xf "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}-symbols.tar.gz" -C "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }}-symbols" + + - name: Unpack tests + run: | + mkdir -p "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin-tests${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin-tests${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin-tests${{ matrix.artifact }}" + + - name: Find root of jdk image dir + run: echo ("::set-env name=imageroot::" + (Get-ChildItem -Path $HOME/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin${{ matrix.artifact }} -Filter release -Recurse -ErrorAction SilentlyContinue -Force).DirectoryName) + + - name: Run tests + run: > + $env:Path = "$HOME\cygwin\cygwin64\bin;$HOME\cygwin\cygwin64\bin;$env:Path" ; + $env:Path = $env:Path -split ";" -match "C:\\Windows|PowerShell|cygwin" -join ";" ; + $env:JDK_IMAGE_DIR = cygpath "${{ env.imageroot }}" ; + $env:SYMBOLS_IMAGE_DIR = cygpath "${{ env.imageroot }}" ; + $env:TEST_IMAGE_DIR = cygpath "$HOME/jdk-windows-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_windows-x64_bin-tests${{ matrix.artifact }}" ; + $env:BOOT_JDK = cygpath "$HOME/bootjdk/$env:BOOT_JDK_VERSION" ; + $env:JT_HOME = cygpath "$HOME/jtreg" ; + & make test-prebuilt + CONF_NAME=run-test-prebuilt + LOG_CMDLINES=true + JTREG_VERBOSE=fail,error,time + TEST=${{ matrix.suites }} + TEST_OPTS_JAVA_OPTIONS= + JTREG_KEYWORDS="!headful" + + - name: Create suitable test log artifact name + if: always() + run: echo ("::set-env name=logsuffix::" + ("${{ matrix.test }}" -replace "/", "_" -replace " ", "_")) + + - name: Persist test logs + if: always() + uses: actions/upload-artifact@v2 + with: + name: windows-x64${{ matrix.artifact }}_testlogs_${{ env.logsuffix }} + path: build/*/test-results + continue-on-error: true + + macos_x64_build: + name: macOS x64 + runs-on: "macos-latest" + needs: prerequisites + if: needs.prerequisites.outputs.should_run != 'false' && needs.prerequisites.outputs.platform_macos_x64 != 'false' + + strategy: + fail-fast: false + matrix: + flavor: + - build release + - build debug + include: + - flavor: build release + - flavor: build debug + flags: --enable-debug + artifact: -debug + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + + - name: Checkout the source + uses: actions/checkout@v2 + with: + path: jdk + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p ${HOME}/bootjdk/${BOOT_JDK_VERSION} || true + wget -O "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" "${BOOT_JDK_URL}" + echo "${BOOT_JDK_SHA256} ${HOME}/bootjdk/${BOOT_JDK_FILENAME}" | shasum -a 256 -c >/dev/null - + tar -xf "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" -C "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + mv "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"*/* "${HOME}/bootjdk/${BOOT_JDK_VERSION}/" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Checkout gtest sources + uses: actions/checkout@v2 + with: + repository: "google/googletest" + ref: "release-${{ fromJson(needs.prerequisites.outputs.dependencies).GTEST_VERSION }}" + path: gtest + + - name: Install dependencies + run: brew install make + + - name: Configure + run: > + bash configure + --with-conf-name=macos-x64 + ${{ matrix.flags }} + --with-version-opt=${GITHUB_ACTOR}-${GITHUB_SHA} + --with-version-build=0 + --with-boot-jdk=${HOME}/bootjdk/${BOOT_JDK_VERSION}/Contents/Home + --with-jtreg=${HOME}/jtreg + --with-gtest=${GITHUB_WORKSPACE}/gtest + --with-default-make-target="product-bundles test-bundles" + --with-zlib=system + --enable-jtreg-failure-handler + working-directory: jdk + + - name: Build + run: make CONF_NAME=macos-x64 ${{ matrix.build-target }} + working-directory: jdk + + - name: Persist test bundles + uses: actions/upload-artifact@v2 + with: + name: transient_jdk-macos-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: | + jdk/build/macos-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin${{ matrix.artifact }}.tar.gz + jdk/build/macos-x64/bundles/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin-tests${{ matrix.artifact }}.tar.gz + if: matrix.build-target == false + + macos_x64_test: + name: macOS x64 + runs-on: "macos-latest" + needs: + - prerequisites + - macos_x64_build + + strategy: + fail-fast: false + matrix: + test: + - jdk/tier1 part 1 + - jdk/tier1 part 2 + - jdk/tier1 part 3 + - langtools/tier1 + - hs/tier1 common + - hs/tier1 compiler + - hs/tier1 gc + - hs/tier1 runtime + - hs/tier1 serviceability + include: + - test: jdk/tier1 part 1 + suites: test/jdk/:tier1_part1 + - test: jdk/tier1 part 2 + suites: test/jdk/:tier1_part2 + - test: jdk/tier1 part 3 + suites: test/jdk/:tier1_part3 + - test: langtools/tier1 + suites: test/langtools/:tier1 + - test: hs/tier1 common + suites: test/hotspot/jtreg/:tier1_common + artifact: -debug + - test: hs/tier1 compiler + suites: test/hotspot/jtreg/:tier1_compiler + artifact: -debug + - test: hs/tier1 gc + suites: test/hotspot/jtreg/:tier1_gc + artifact: -debug + - test: hs/tier1 runtime + suites: test/hotspot/jtreg/:tier1_runtime + artifact: -debug + - test: hs/tier1 serviceability + suites: test/hotspot/jtreg/:tier1_serviceability + artifact: -debug + + env: + JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).DEFAULT_VERSION_FEATURE }}" + BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}" + BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_FILENAME }}" + BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_URL }}" + BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).MACOS_X64_BOOT_JDK_SHA256 }}" + + steps: + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + + - name: Checkout the source + uses: actions/checkout@v2 + + - name: Restore boot JDK from cache + id: bootjdk + uses: actions/cache@v2 + with: + path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }} + key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1 + + - name: Download boot JDK + run: | + mkdir -p ${HOME}/bootjdk/${BOOT_JDK_VERSION} || true + wget -O "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" "${BOOT_JDK_URL}" + echo "${BOOT_JDK_SHA256} ${HOME}/bootjdk/${BOOT_JDK_FILENAME}" | shasum -a 256 -c >/dev/null - + tar -xf "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" -C "${HOME}/bootjdk/${BOOT_JDK_VERSION}" + mv "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"*/* "${HOME}/bootjdk/${BOOT_JDK_VERSION}/" + if: steps.bootjdk.outputs.cache-hit != 'true' + + - name: Restore jtreg artifact + uses: actions/download-artifact@v2 + with: + name: transient_jtreg_${{ env.bundleid }} + path: ~/jtreg/ + + - name: Restore build artifacts + uses: actions/download-artifact@v2 + with: + name: transient_jdk-macos-x64${{ matrix.artifact }}_${{ env.bundleid }} + path: ~/jdk-macos-x64${{ matrix.artifact }} + + - name: Unpack jdk + run: | + mkdir -p "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin${{ matrix.artifact }}" + + - name: Unpack tests + run: | + mkdir -p "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin-tests${{ matrix.artifact }}" + tar -xf "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin-tests${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin-tests${{ matrix.artifact }}" + + - name: Install dependencies + run: brew install make + + - name: Find root of jdk image dir + run: | + imageroot=`find ${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin${{ matrix.artifact }} -name release -type f` + echo "::set-env name=imageroot::`dirname ${imageroot}`" + + - name: Run tests + run: > + JDK_IMAGE_DIR=${{ env.imageroot }} + TEST_IMAGE_DIR=${HOME}/jdk-macos-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_osx-x64_bin-tests${{ matrix.artifact }} + BOOT_JDK=${HOME}/bootjdk/${BOOT_JDK_VERSION}/Contents/Home + JT_HOME=${HOME}/jtreg + gmake test-prebuilt + CONF_NAME=run-test-prebuilt + LOG_CMDLINES=true + JTREG_VERBOSE=fail,error,time + TEST=${{ matrix.suites }} + TEST_OPTS_JAVA_OPTIONS= + JTREG_KEYWORDS="!headful" + + - name: Create suitable test log artifact name + if: always() + run: echo "::set-env name=logsuffix::`echo ${{ matrix.test }} | sed -e 's!/!_!'g -e 's! !_!'g`" + + - name: Persist test logs + if: always() + uses: actions/upload-artifact@v2 + with: + name: macos-x64${{ matrix.artifact }}_testlogs_${{ env.logsuffix }} + path: build/*/test-results + continue-on-error: true + + artifacts: + name: Post-process artifacts + runs-on: "ubuntu-latest" + if: always() + continue-on-error: true + needs: + - linux_x64_test + - windows_x64_test + - macos_x64_test + + steps: + - name: Determine current artifacts endpoint + id: actions_runtime + uses: actions/github-script@v3 + with: + script: "return { url: process.env['ACTIONS_RUNTIME_URL'], token: process.env['ACTIONS_RUNTIME_TOKEN'] }" + + - name: Display current artifacts + run: > + curl -s -H 'Accept: application/json;api-version=6.0-preview' + -H 'Authorization: Bearer ${{ fromJson(steps.actions_runtime.outputs.result).token }}' + '${{ fromJson(steps.actions_runtime.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview' + + - name: Delete transient artifacts + run: > + for url in ` + curl -s -H 'Accept: application/json;api-version=6.0-preview' + -H 'Authorization: Bearer ${{ fromJson(steps.actions_runtime.outputs.result).token }}' + '${{ fromJson(steps.actions_runtime.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview' | + jq -r -c '.value | map(select(.name|startswith("transient_"))) | .[].url'`; do + curl -s -H 'Accept: application/json;api-version=6.0-preview' + -H 'Authorization: Bearer ${{ fromJson(steps.actions_runtime.outputs.result).token }}' + -X DELETE "${url}"; + done + + - name: Fetch remaining artifacts (test results) + uses: actions/download-artifact@v2 + with: + path: test-results + + - name: Delete remaining artifacts + run: > + for url in ` + curl -s -H 'Accept: application/json;api-version=6.0-preview' + -H 'Authorization: Bearer ${{ fromJson(steps.actions_runtime.outputs.result).token }}' + '${{ fromJson(steps.actions_runtime.outputs.result).url }}_apis/pipelines/workflows/${{ github.run_id }}/artifacts?api-version=6.0-preview' | + jq -r -c '.value | .[].url'`; do + curl -s -H 'Accept: application/json;api-version=6.0-preview' + -H 'Authorization: Bearer ${{ fromJson(steps.actions_runtime.outputs.result).token }}' + -X DELETE "${url}"; + done + + - name: Determine unique bundle identifier + run: echo "::set-env name=bundleid::${GITHUB_ACTOR}_${GITHUB_SHA:0:8}" + + - name: Upload a combined test results artifact + uses: actions/upload-artifact@v2 + with: + name: test-results_${{ env.bundleid }} + path: test-results diff --git a/make/conf/test-dependencies b/make/conf/test-dependencies new file mode 100644 index 0000000000000..4cc4610daedee --- /dev/null +++ b/make/conf/test-dependencies @@ -0,0 +1,43 @@ +# +# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# Versions and download locations for dependencies used by pre-submit testing. + +BOOT_JDK_VERSION=15 +JTREG_VERSION=5.1 +JTREG_BUILD=b01 +GTEST_VERSION=1.8.1 + +LINUX_X64_BOOT_JDK_FILENAME=openjdk-15_linux-x64_bin.tar.gz +LINUX_X64_BOOT_JDK_URL=https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_linux-x64_bin.tar.gz +LINUX_X64_BOOT_JDK_SHA256=bb67cadee687d7b486583d03c9850342afea4593be4f436044d785fba9508fb7 + +WINDOWS_X64_BOOT_JDK_FILENAME=openjdk-15_windows-x64_bin.zip +WINDOWS_X64_BOOT_JDK_URL=https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_windows-x64_bin.zip +WINDOWS_X64_BOOT_JDK_SHA256=764e39a71252a9791118a31ae56a4247c049463bda5eb72497122ec50b1d07f8 + +MACOS_X64_BOOT_JDK_FILENAME=openjdk-115_osx-x64_bin.tar.gz +MACOS_X64_BOOT_JDK_URL=https://download.java.net/java/GA/jdk15/779bf45e88a44cbd9ea6621d33e33db1/36/GPL/openjdk-15_osx-x64_bin.tar.gz +MACOS_X64_BOOT_JDK_SHA256=ab842c8c0953b816be308c098c1a021177a4776bef24da85b6bafbbd657c7e1a From 16b8c3996436412dcf7cb1b64cede25507684d70 Mon Sep 17 00:00:00 2001 From: Patrick Concannon Date: Mon, 28 Sep 2020 13:17:46 +0000 Subject: [PATCH 39/79] 8253053: Javadoc clean up in Authenticator and BasicAuthenicator Reviewed-by: dfuchs, rriggs, chegar, michaelm --- .../com/sun/net/httpserver/Authenticator.java | 64 +++++++++---------- .../net/httpserver/BasicAuthenticator.java | 25 ++++---- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Authenticator.java b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Authenticator.java index eb961385f6c05..d6482e1940533 100644 --- a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Authenticator.java +++ b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/Authenticator.java @@ -41,7 +41,7 @@ public abstract class Authenticator { protected Authenticator () { } /** - * Base class for return type from authenticate() method + * Base class for return type from {@link #authenticate(HttpExchange)} method. */ public abstract static class Result { @@ -51,8 +51,6 @@ public abstract static class Result { protected Result () {} } - - /** * Indicates an authentication failure. The authentication * attempt has completed. @@ -64,7 +62,7 @@ public static class Failure extends Result { /** * Creates a {@code Failure} instance with given response code. * - * @param responseCode The response code to associate with this + * @param responseCode the response code to associate with this * {@code Failure} instance */ public Failure (int responseCode) { @@ -72,9 +70,9 @@ public Failure (int responseCode) { } /** - * returns the response code to send to the client + * Returns the response code to send to the client. * - * @return The response code associated with this {@code Failure} instance + * @return the response code associated with this {@code Failure} instance */ public int getResponseCode() { return responseCode; @@ -83,8 +81,8 @@ public int getResponseCode() { /** * Indicates an authentication has succeeded and the - * authenticated user principal can be acquired by calling - * getPrincipal(). + * authenticated user {@linkplain HttpPrincipal principal} can be acquired by calling + * {@link #getPrincipal()}. */ public static class Success extends Result { private HttpPrincipal principal; @@ -92,15 +90,16 @@ public static class Success extends Result { /** * Creates a {@code Success} instance with given {@code Principal}. * - * @param p The authenticated user you wish to set as Principal + * @param p the authenticated user you wish to set as {@code Principal} */ public Success (HttpPrincipal p) { principal = p; } + /** - * returns the authenticated user Principal + * Returns the authenticated user {@code Principal}. * - * @return The {@code Principal} instance associated with the authenticated user + * @return the {@code Principal} instance associated with the authenticated user * */ public HttpPrincipal getPrincipal() { @@ -111,9 +110,9 @@ public HttpPrincipal getPrincipal() { /** * Indicates an authentication must be retried. The * response code to be sent back is as returned from - * getResponseCode(). The Authenticator must also have - * set any necessary response headers in the given HttpExchange - * before returning this Retry object. + * {@link #getResponseCode()}. The {@code Authenticator} must also have + * set any necessary response headers in the given {@link HttpExchange} + * before returning this {@code Retry} object. */ public static class Retry extends Result { @@ -122,7 +121,7 @@ public static class Retry extends Result { /** * Creates a {@code Retry} instance with given response code. * - * @param responseCode The response code to associate with this + * @param responseCode the response code to associate with this * {@code Retry} instance */ public Retry (int responseCode) { @@ -130,9 +129,9 @@ public Retry (int responseCode) { } /** - * returns the response code to send to the client + * Returns the response code to send to the client. * - * @return The response code associated with this {@code Retry} instance + * @return the response code associated with this {@code Retry} instance */ public int getResponseCode() { return responseCode; @@ -140,23 +139,22 @@ public int getResponseCode() { } /** - * called to authenticate each incoming request. The implementation - * must return a Failure, Success or Retry object as appropriate :- - *

    - * Failure means the authentication has completed, but has failed - * due to invalid credentials. - *

    - * Sucess means that the authentication - * has succeeded, and a Principal object representing the user - * can be retrieved by calling Sucess.getPrincipal() . - *

    - * Retry means that another HTTP exchange is required. Any response - * headers needing to be sent back to the client are set in the - * given HttpExchange. The response code to be returned must be provided - * in the Retry object. Retry may occur multiple times. + * Called to authenticate each incoming request. The implementation + * must return a {@link Failure}, {@link Success} or {@link Retry} object as appropriate: + *

      + *
    • {@code Failure} means the authentication has completed, but has + * failed due to invalid credentials. + *
    • {@code Success} means that the authentication has succeeded, + * and a {@code Principal} object representing the user can be retrieved + * by calling {@link Success#getPrincipal()}. + *
    • {@code Retry} means that another HTTP {@linkplain HttpExchange exchange} + * is required. Any response headers needing to be sent back to the client are set + * in the given {@code HttpExchange}. The response code to be returned must be + * provided in the {@code Retry} object. {@code Retry} may occur multiple times. + *
        * - * @param exch The HttpExchange upon which authenticate is called - * @return The result + * @param exch the {@code HttpExchange} upon which authenticate is called + * @return the result */ public abstract Result authenticate (HttpExchange exch); } diff --git a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java index 36bf196a9a1ff..4b3faf10f8e99 100644 --- a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java +++ b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java @@ -45,11 +45,11 @@ public abstract class BasicAuthenticator extends Authenticator { private final boolean isUTF8; /** - * Creates a BasicAuthenticator for the given HTTP realm. + * Creates a {@code BasicAuthenticator} for the given HTTP realm. * The Basic authentication credentials (username and password) are decoded * using the platform's {@link Charset#defaultCharset() default character set}. * - * @param realm The HTTP Basic authentication realm + * @param realm the HTTP Basic authentication realm * @throws NullPointerException if realm is {@code null} * @throws IllegalArgumentException if realm is an empty string */ @@ -58,7 +58,7 @@ public BasicAuthenticator (String realm) { } /** - * Creates a BasicAuthenticator for the given HTTP realm and using the + * Creates a {@code BasicAuthenticator} for the given HTTP realm and using the * given {@link Charset} to decode the Basic authentication credentials * (username and password). * @@ -66,8 +66,8 @@ public BasicAuthenticator (String realm) { * communicated to the client, and therefore more likely to be used also * by the client. * - * @param realm The HTTP Basic authentication realm - * @param charset The Charset to decode incoming credentials from the client + * @param realm the HTTP Basic authentication realm + * @param charset the {@code Charset} to decode incoming credentials from the client * @throws NullPointerException if realm or charset are {@code null} * @throws IllegalArgumentException if realm is an empty string */ @@ -81,8 +81,9 @@ public BasicAuthenticator (String realm, Charset charset) { } /** - * returns the realm this BasicAuthenticator was created with - * @return the authenticator's realm string. + * Returns the realm this {@code BasicAuthenticator} was created with. + * + * @return the authenticator's realm string */ public String getRealm () { return realm; @@ -130,14 +131,14 @@ private void setAuthHeader(HttpExchange t) { } /** - * called for each incoming request to verify the + * Called for each incoming request to verify the * given name and password in the context of this - * Authenticator's realm. Any caching of credentials - * must be done by the implementation of this method + * authenticator's realm. Any caching of credentials + * must be done by the implementation of this method. + * * @param username the username from the request * @param password the password from the request - * @return true if the credentials are valid, - * false otherwise. + * @return {@code true} if the credentials are valid, {@code false} otherwise */ public abstract boolean checkCredentials (String username, String password); } From ec9bee68660acd6abf0b4dd4023ae69514542256 Mon Sep 17 00:00:00 2001 From: Anton Kozlov Date: Mon, 28 Sep 2020 13:52:10 +0000 Subject: [PATCH 40/79] 8253015: Aarch64: Move linux code out from generic CPU feature detection Reviewed-by: aph --- .../cpu/aarch64/macroAssembler_aarch64.cpp | 2 +- .../cpu/aarch64/vm_version_aarch64.cpp | 206 +++--------------- .../cpu/aarch64/vm_version_aarch64.hpp | 53 ++--- .../vm_version_linux_aarch64.cpp | 137 ++++++++++++ src/hotspot/share/jvmci/vmStructs_jvmci.cpp | 2 +- .../aarch64/AArch64HotSpotLIRGenerator.java | 24 +- .../hotspot/GraalHotSpotVMConfig.java | 5 +- 7 files changed, 220 insertions(+), 209 deletions(-) diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp index e904282a57345..2d9355c8ee6ca 100644 --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp @@ -5266,7 +5266,7 @@ void MacroAssembler::cache_wb(Address line) { assert(line.offset() == 0, "offset should be 0"); // would like to assert this // assert(line._ext.shift == 0, "shift should be zero"); - if (VM_Version::supports_dcpop()) { + if (VM_Version::features() & VM_Version::CPU_DCPOP) { // writeback using clear virtual address to point of persistence dc(Assembler::CVAP, line.base()); } else { diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp index decc17d1958ee..343a2bbd50fab 100644 --- a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp @@ -24,124 +24,36 @@ */ #include "precompiled.hpp" -#include "asm/macroAssembler.hpp" -#include "asm/macroAssembler.inline.hpp" -#include "memory/resourceArea.hpp" #include "runtime/arguments.hpp" #include "runtime/globals_extension.hpp" #include "runtime/java.hpp" #include "runtime/os.hpp" -#include "runtime/stubCodeGenerator.hpp" #include "runtime/vm_version.hpp" #include "utilities/formatBuffer.hpp" #include "utilities/macros.hpp" #include OS_HEADER_INLINE(os) -#include -#include -#include - -#ifndef HWCAP_AES -#define HWCAP_AES (1<<3) -#endif - -#ifndef HWCAP_PMULL -#define HWCAP_PMULL (1<<4) -#endif - -#ifndef HWCAP_SHA1 -#define HWCAP_SHA1 (1<<5) -#endif - -#ifndef HWCAP_SHA2 -#define HWCAP_SHA2 (1<<6) -#endif - -#ifndef HWCAP_CRC32 -#define HWCAP_CRC32 (1<<7) -#endif - -#ifndef HWCAP_ATOMICS -#define HWCAP_ATOMICS (1<<8) -#endif - -#ifndef HWCAP_SHA512 -#define HWCAP_SHA512 (1 << 21) -#endif - -#ifndef HWCAP_SVE -#define HWCAP_SVE (1 << 22) -#endif - -#ifndef HWCAP2_SVE2 -#define HWCAP2_SVE2 (1 << 1) -#endif - -#ifndef PR_SVE_GET_VL -// For old toolchains which do not have SVE related macros defined. -#define PR_SVE_SET_VL 50 -#define PR_SVE_GET_VL 51 -#endif - int VM_Version::_cpu; int VM_Version::_model; int VM_Version::_model2; int VM_Version::_variant; int VM_Version::_revision; int VM_Version::_stepping; -bool VM_Version::_dcpop; -int VM_Version::_initial_sve_vector_length; -VM_Version::PsrInfo VM_Version::_psr_info = { 0, }; - -static BufferBlob* stub_blob; -static const int stub_size = 550; - -extern "C" { - typedef void (*getPsrInfo_stub_t)(void*); -} -static getPsrInfo_stub_t getPsrInfo_stub = NULL; - - -class VM_Version_StubGenerator: public StubCodeGenerator { - public: - VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {} - - address generate_getPsrInfo() { - StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub"); -# define __ _masm-> - address start = __ pc(); - - // void getPsrInfo(VM_Version::PsrInfo* psr_info); - - address entry = __ pc(); - - __ enter(); - - __ get_dczid_el0(rscratch1); - __ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::dczid_el0_offset()))); - - __ get_ctr_el0(rscratch1); - __ strw(rscratch1, Address(c_rarg0, in_bytes(VM_Version::ctr_el0_offset()))); - - __ leave(); - __ ret(lr); - -# undef __ - - return start; - } -}; +int VM_Version::_zva_length; +int VM_Version::_dcache_line_size; +int VM_Version::_icache_line_size; +int VM_Version::_initial_sve_vector_length; -void VM_Version::get_processor_features() { +void VM_Version::initialize() { _supports_cx8 = true; _supports_atomic_getset4 = true; _supports_atomic_getadd4 = true; _supports_atomic_getset8 = true; _supports_atomic_getadd8 = true; - getPsrInfo_stub(&_psr_info); + get_os_cpu_info(); int dcache_line = VM_Version::dcache_line_size(); @@ -183,45 +95,12 @@ void VM_Version::get_processor_features() { SoftwarePrefetchHintDistance &= ~7; } - uint64_t auxv = getauxval(AT_HWCAP); - uint64_t auxv2 = getauxval(AT_HWCAP2); - - char buf[512]; - - _features = auxv; - - int cpu_lines = 0; - if (FILE *f = fopen("/proc/cpuinfo", "r")) { - // need a large buffer as the flags line may include lots of text - char buf[1024], *p; - while (fgets(buf, sizeof (buf), f) != NULL) { - if ((p = strchr(buf, ':')) != NULL) { - long v = strtol(p+1, NULL, 0); - if (strncmp(buf, "CPU implementer", sizeof "CPU implementer" - 1) == 0) { - _cpu = v; - cpu_lines++; - } else if (strncmp(buf, "CPU variant", sizeof "CPU variant" - 1) == 0) { - _variant = v; - } else if (strncmp(buf, "CPU part", sizeof "CPU part" - 1) == 0) { - if (_model != v) _model2 = _model; - _model = v; - } else if (strncmp(buf, "CPU revision", sizeof "CPU revision" - 1) == 0) { - _revision = v; - } else if (strncmp(buf, "flags", sizeof("flags") - 1) == 0) { - if (strstr(p+1, "dcpop")) { - _dcpop = true; - } - } - } - } - fclose(f); - } if (os::supports_map_sync()) { // if dcpop is available publish data cache line flush size via // generic field, otherwise let if default to zero thereby // disabling writeback - if (_dcpop) { + if (_features & CPU_DCPOP) { _data_cache_line_flush_size = dcache_line; } } @@ -302,30 +181,31 @@ void VM_Version::get_processor_features() { } if (_cpu == CPU_ARM && (_model == 0xd07 || _model2 == 0xd07)) _features |= CPU_STXR_PREFETCH; - // If an olde style /proc/cpuinfo (cpu_lines == 1) then if _model is an A57 (0xd07) + // If an olde style /proc/cpuinfo (cores == 1) then if _model is an A57 (0xd07) // we assume the worst and assume we could be on a big little system and have // undisclosed A53 cores which we could be swapped to at any stage - if (_cpu == CPU_ARM && cpu_lines == 1 && _model == 0xd07) _features |= CPU_A53MAC; + if (_cpu == CPU_ARM && os::processor_count() == 1 && _model == 0xd07) _features |= CPU_A53MAC; + char buf[512]; sprintf(buf, "0x%02x:0x%x:0x%03x:%d", _cpu, _variant, _model, _revision); if (_model2) sprintf(buf+strlen(buf), "(0x%03x)", _model2); - if (auxv & HWCAP_ASIMD) strcat(buf, ", simd"); - if (auxv & HWCAP_CRC32) strcat(buf, ", crc"); - if (auxv & HWCAP_AES) strcat(buf, ", aes"); - if (auxv & HWCAP_SHA1) strcat(buf, ", sha1"); - if (auxv & HWCAP_SHA2) strcat(buf, ", sha256"); - if (auxv & HWCAP_SHA512) strcat(buf, ", sha512"); - if (auxv & HWCAP_ATOMICS) strcat(buf, ", lse"); - if (auxv & HWCAP_SVE) strcat(buf, ", sve"); - if (auxv2 & HWCAP2_SVE2) strcat(buf, ", sve2"); + if (_features & CPU_ASIMD) strcat(buf, ", simd"); + if (_features & CPU_CRC32) strcat(buf, ", crc"); + if (_features & CPU_AES) strcat(buf, ", aes"); + if (_features & CPU_SHA1) strcat(buf, ", sha1"); + if (_features & CPU_SHA2) strcat(buf, ", sha256"); + if (_features & CPU_SHA512) strcat(buf, ", sha512"); + if (_features & CPU_LSE) strcat(buf, ", lse"); + if (_features & CPU_SVE) strcat(buf, ", sve"); + if (_features & CPU_SVE2) strcat(buf, ", sve2"); _features_string = os::strdup(buf); if (FLAG_IS_DEFAULT(UseCRC32)) { - UseCRC32 = (auxv & HWCAP_CRC32) != 0; + UseCRC32 = (_features & CPU_CRC32) != 0; } - if (UseCRC32 && (auxv & HWCAP_CRC32) == 0) { + if (UseCRC32 && (_features & CPU_CRC32) == 0) { warning("UseCRC32 specified, but not supported on this CPU"); FLAG_SET_DEFAULT(UseCRC32, false); } @@ -339,7 +219,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false); } - if (auxv & HWCAP_ATOMICS) { + if (_features & CPU_LSE) { if (FLAG_IS_DEFAULT(UseLSE)) FLAG_SET_DEFAULT(UseLSE, true); } else { @@ -349,7 +229,7 @@ void VM_Version::get_processor_features() { } } - if (auxv & HWCAP_AES) { + if (_features & CPU_AES) { UseAES = UseAES || FLAG_IS_DEFAULT(UseAES); UseAESIntrinsics = UseAESIntrinsics || (UseAES && FLAG_IS_DEFAULT(UseAESIntrinsics)); @@ -377,7 +257,7 @@ void VM_Version::get_processor_features() { UseCRC32Intrinsics = true; } - if (auxv & HWCAP_CRC32) { + if (_features & CPU_CRC32) { if (FLAG_IS_DEFAULT(UseCRC32CIntrinsics)) { FLAG_SET_DEFAULT(UseCRC32CIntrinsics, true); } @@ -395,7 +275,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseMD5Intrinsics, false); } - if (auxv & (HWCAP_SHA1 | HWCAP_SHA2)) { + if (_features & (CPU_SHA1 | CPU_SHA2)) { if (FLAG_IS_DEFAULT(UseSHA)) { FLAG_SET_DEFAULT(UseSHA, true); } @@ -404,7 +284,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseSHA, false); } - if (UseSHA && (auxv & HWCAP_SHA1)) { + if (UseSHA && (_features & CPU_SHA1)) { if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) { FLAG_SET_DEFAULT(UseSHA1Intrinsics, true); } @@ -413,7 +293,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseSHA1Intrinsics, false); } - if (UseSHA && (auxv & HWCAP_SHA2)) { + if (UseSHA && (_features & CPU_SHA2)) { if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) { FLAG_SET_DEFAULT(UseSHA256Intrinsics, true); } @@ -422,7 +302,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); } - if (UseSHA && (auxv & HWCAP_SHA512)) { + if (UseSHA && (_features & CPU_SHA512)) { // Do not auto-enable UseSHA512Intrinsics until it has been fully tested on hardware // if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) { // FLAG_SET_DEFAULT(UseSHA512Intrinsics, true); @@ -436,7 +316,7 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseSHA, false); } - if (auxv & HWCAP_PMULL) { + if (_features & CPU_PMULL) { if (FLAG_IS_DEFAULT(UseGHASHIntrinsics)) { FLAG_SET_DEFAULT(UseGHASHIntrinsics, true); } @@ -457,12 +337,12 @@ void VM_Version::get_processor_features() { FLAG_SET_DEFAULT(UseBlockZeroing, false); } - if (auxv & HWCAP_SVE) { + if (_features & CPU_SVE) { if (FLAG_IS_DEFAULT(UseSVE)) { - FLAG_SET_DEFAULT(UseSVE, (auxv2 & HWCAP2_SVE2) ? 2 : 1); + FLAG_SET_DEFAULT(UseSVE, (_features & CPU_SVE2) ? 2 : 1); } if (UseSVE > 0) { - _initial_sve_vector_length = prctl(PR_SVE_GET_VL); + _initial_sve_vector_length = get_current_sve_vector_length(); } } else if (UseSVE > 0) { warning("UseSVE specified, but not supported on current CPU. Disabling SVE."); @@ -510,11 +390,9 @@ void VM_Version::get_processor_features() { warning("SVE does not support vector length less than 16 bytes. Disabling SVE."); UseSVE = 0; } else if ((MaxVectorSize % 16) == 0 && is_power_of_2(MaxVectorSize)) { - int new_vl = prctl(PR_SVE_SET_VL, MaxVectorSize); + int new_vl = set_and_get_current_sve_vector_lenght(MaxVectorSize); _initial_sve_vector_length = new_vl; - // If MaxVectorSize is larger than system largest supported SVE vector length, above prctl() - // call will set task vector length to the system largest supported value. So, we also update - // MaxVectorSize to that largest supported value. + // Update MaxVectorSize to the largest supported value. if (new_vl < 0) { vm_exit_during_initialization( err_msg("Current system does not support SVE vector length for MaxVectorSize: %d", @@ -555,22 +433,6 @@ void VM_Version::get_processor_features() { AlignVector = AvoidUnalignedAccesses; } #endif -} - -void VM_Version::initialize() { - ResourceMark rm; - - stub_blob = BufferBlob::create("getPsrInfo_stub", stub_size); - if (stub_blob == NULL) { - vm_exit_during_initialization("Unable to allocate getPsrInfo_stub"); - } - - CodeBuffer c(stub_blob); - VM_Version_StubGenerator g(&c); - getPsrInfo_stub = CAST_TO_FN_PTR(getPsrInfo_stub_t, - g.generate_getPsrInfo()); - - get_processor_features(); UNSUPPORTED_OPTION(CriticalJNINatives); } diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp index 5dde5e89946c4..292550529b406 100644 --- a/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.hpp @@ -39,15 +39,20 @@ class VM_Version : public Abstract_VM_Version { static int _variant; static int _revision; static int _stepping; - static bool _dcpop; + + static int _zva_length; + static int _dcache_line_size; + static int _icache_line_size; static int _initial_sve_vector_length; - struct PsrInfo { - uint32_t dczid_el0; - uint32_t ctr_el0; - }; - static PsrInfo _psr_info; - static void get_processor_features(); + // Read additional info using OS-specific interfaces + static void get_os_cpu_info(); + + // Sets the SVE length and returns a new actual value or negative on error. + // If the len is larger than the system largest supported SVE vector length, + // the function sets the largest supported value. + static int set_and_get_current_sve_vector_lenght(int len); + static int get_current_sve_vector_length(); public: // Initialization @@ -97,8 +102,13 @@ class VM_Version : public Abstract_VM_Version { CPU_SHA2 = (1<<6), CPU_CRC32 = (1<<7), CPU_LSE = (1<<8), - CPU_STXR_PREFETCH= (1 << 29), - CPU_A53MAC = (1 << 30), + CPU_DCPOP = (1<<16), + CPU_SHA512 = (1<<21), + CPU_SVE = (1<<22), + // flags above must follow Linux HWCAP + CPU_SVE2 = (1<<28), + CPU_STXR_PREFETCH= (1<<29), + CPU_A53MAC = (1<<30), }; static int cpu_family() { return _cpu; } @@ -106,26 +116,17 @@ class VM_Version : public Abstract_VM_Version { static int cpu_model2() { return _model2; } static int cpu_variant() { return _variant; } static int cpu_revision() { return _revision; } - static bool supports_dcpop() { return _dcpop; } - static int get_initial_sve_vector_length() { return _initial_sve_vector_length; }; - static ByteSize dczid_el0_offset() { return byte_offset_of(PsrInfo, dczid_el0); } - static ByteSize ctr_el0_offset() { return byte_offset_of(PsrInfo, ctr_el0); } - static bool is_zva_enabled() { - // Check the DZP bit (bit 4) of dczid_el0 is zero - // and block size (bit 0~3) is not zero. - return ((_psr_info.dczid_el0 & 0x10) == 0 && - (_psr_info.dczid_el0 & 0xf) != 0); - } + + static bool is_zva_enabled() { return 0 <= _zva_length; } static int zva_length() { assert(is_zva_enabled(), "ZVA not available"); - return 4 << (_psr_info.dczid_el0 & 0xf); - } - static int icache_line_size() { - return (1 << (_psr_info.ctr_el0 & 0x0f)) * 4; - } - static int dcache_line_size() { - return (1 << ((_psr_info.ctr_el0 >> 16) & 0x0f)) * 4; + return _zva_length; } + + static int icache_line_size() { return _icache_line_size; } + static int dcache_line_size() { return _dcache_line_size; } + static int get_initial_sve_vector_length() { return _initial_sve_vector_length; }; + static bool supports_fast_class_init_checks() { return true; } }; diff --git a/src/hotspot/os_cpu/linux_aarch64/vm_version_linux_aarch64.cpp b/src/hotspot/os_cpu/linux_aarch64/vm_version_linux_aarch64.cpp index e4ae30c4cff45..d5fb3f4680b70 100644 --- a/src/hotspot/os_cpu/linux_aarch64/vm_version_linux_aarch64.cpp +++ b/src/hotspot/os_cpu/linux_aarch64/vm_version_linux_aarch64.cpp @@ -27,3 +27,140 @@ #include "runtime/os.hpp" #include "runtime/vm_version.hpp" +#include +#include +#include + +#ifndef HWCAP_AES +#define HWCAP_AES (1<<3) +#endif + +#ifndef HWCAP_PMULL +#define HWCAP_PMULL (1<<4) +#endif + +#ifndef HWCAP_SHA1 +#define HWCAP_SHA1 (1<<5) +#endif + +#ifndef HWCAP_SHA2 +#define HWCAP_SHA2 (1<<6) +#endif + +#ifndef HWCAP_CRC32 +#define HWCAP_CRC32 (1<<7) +#endif + +#ifndef HWCAP_ATOMICS +#define HWCAP_ATOMICS (1<<8) +#endif + +#ifndef HWCAP_DCPOP +#define HWCAP_DCPOP (1<<16) +#endif + +#ifndef HWCAP_SHA512 +#define HWCAP_SHA512 (1 << 21) +#endif + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SVE2 +#define HWCAP2_SVE2 (1 << 1) +#endif + +#ifndef PR_SVE_GET_VL +// For old toolchains which do not have SVE related macros defined. +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#endif + +int VM_Version::get_current_sve_vector_length() { + assert(_features & CPU_SVE, "should not call this"); + return prctl(PR_SVE_GET_VL); +} + +int VM_Version::set_and_get_current_sve_vector_lenght(int length) { + assert(_features & CPU_SVE, "should not call this"); + int new_length = prctl(PR_SVE_SET_VL, length); + return new_length; +} + +void VM_Version::get_os_cpu_info() { + + uint64_t auxv = getauxval(AT_HWCAP); + uint64_t auxv2 = getauxval(AT_HWCAP2); + + static_assert(CPU_FP == HWCAP_FP); + static_assert(CPU_ASIMD == HWCAP_ASIMD); + static_assert(CPU_EVTSTRM == HWCAP_EVTSTRM); + static_assert(CPU_AES == HWCAP_AES); + static_assert(CPU_PMULL == HWCAP_PMULL); + static_assert(CPU_SHA1 == HWCAP_SHA1); + static_assert(CPU_SHA2 == HWCAP_SHA2); + static_assert(CPU_CRC32 == HWCAP_CRC32); + static_assert(CPU_LSE == HWCAP_ATOMICS); + static_assert(CPU_DCPOP == HWCAP_DCPOP); + static_assert(CPU_SHA512 == HWCAP_SHA512); + static_assert(CPU_SVE == HWCAP_SVE); + _features = auxv & ( + HWCAP_FP | + HWCAP_ASIMD | + HWCAP_EVTSTRM | + HWCAP_AES | + HWCAP_PMULL | + HWCAP_SHA1 | + HWCAP_SHA2 | + HWCAP_CRC32 | + HWCAP_ATOMICS | + HWCAP_DCPOP | + HWCAP_SHA512 | + HWCAP_SVE); + + if (auxv2 & HWCAP2_SVE2) _features |= CPU_SVE2; + + uint64_t ctr_el0; + uint64_t dczid_el0; + __asm__ ( + "mrs %0, CTR_EL0\n" + "mrs %1, DCZID_EL0\n" + : "=r"(ctr_el0), "=r"(dczid_el0) + ); + + _icache_line_size = (1 << (ctr_el0 & 0x0f)) * 4; + _dcache_line_size = (1 << ((ctr_el0 >> 16) & 0x0f)) * 4; + + if (!(dczid_el0 & 0x10)) { + _zva_length = 4 << (dczid_el0 & 0xf); + } + + int cpu_lines = 0; + if (FILE *f = fopen("/proc/cpuinfo", "r")) { + // need a large buffer as the flags line may include lots of text + char buf[1024], *p; + while (fgets(buf, sizeof (buf), f) != NULL) { + if ((p = strchr(buf, ':')) != NULL) { + long v = strtol(p+1, NULL, 0); + if (strncmp(buf, "CPU implementer", sizeof "CPU implementer" - 1) == 0) { + _cpu = v; + cpu_lines++; + } else if (strncmp(buf, "CPU variant", sizeof "CPU variant" - 1) == 0) { + _variant = v; + } else if (strncmp(buf, "CPU part", sizeof "CPU part" - 1) == 0) { + if (_model != v) _model2 = _model; + _model = v; + } else if (strncmp(buf, "CPU revision", sizeof "CPU revision" - 1) == 0) { + _revision = v; + } else if (strncmp(buf, "flags", sizeof("flags") - 1) == 0) { + if (strstr(p+1, "dcpop")) { + guarantee(_features & CPU_DCPOP, "dcpop availability should be consistent"); + } + } + } + } + fclose(f); + } + guarantee(cpu_lines == os::processor_count(), "core count should be consistent"); +} diff --git a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp index 3a4b776d0a18f..9edc530d80220 100644 --- a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp +++ b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp @@ -724,7 +724,7 @@ #ifdef AARCH64 #define VM_STRUCTS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \ - static_field(VM_Version, _psr_info.dczid_el0, uint32_t) \ + static_field(VM_Version, _zva_length, int) \ volatile_nonstatic_field(JavaFrameAnchor, _last_Java_fp, intptr_t*) #define VM_INT_CONSTANTS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant) \ diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java index 6f197f47d5e4d..0139bbc412419 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotLIRGenerator.java @@ -551,14 +551,22 @@ public LIRInstruction createZapArgumentSpace(StackSlot[] zappedStack, JavaConsta @Override public void emitZeroMemory(Value address, Value length, boolean isAligned) { - int dczidValue = config.psrInfoDczidValue; - EnumSet flags = ((AArch64) target().arch).getFlags(); - - // ARMv8-A architecture reference manual D12.2.35 Data Cache Zero ID register says: - // * BS, bits [3:0] indicate log2 of the DC ZVA block size in (4-byte) words. - // * DZP, bit [4] of indicates whether use of DC ZVA instruction is prohibited. - int zvaLength = 4 << (dczidValue & 0xF); - boolean isDcZvaProhibited = ((dczidValue & 0x10) != 0); + final EnumSet flags = ((AArch64) target().arch).getFlags(); + + boolean isDcZvaProhibited = true; + int zvaLength = 0; + if (GraalHotSpotVMConfig.JDK >= 16) { + zvaLength = config.zvaLength; + isDcZvaProhibited = 0 == config.zvaLength; + } else { + int dczidValue = config.psrInfoDczidValue; + + // ARMv8-A architecture reference manual D12.2.35 Data Cache Zero ID register says: + // * BS, bits [3:0] indicate log2 of the DC ZVA block size in (4-byte) words. + // * DZP, bit [4] of indicates whether use of DC ZVA instruction is prohibited. + zvaLength = 4 << (dczidValue & 0xF); + isDcZvaProhibited = ((dczidValue & 0x10) != 0); + } // Use DC ZVA if it's not prohibited and AArch64 HotSpot flag UseBlockZeroing is on. boolean useDcZva = !isDcZvaProhibited && flags.contains(AArch64.Flag.UseBlockZeroing); diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java index 000a0043ee9dc..6d7d8941afd84 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/GraalHotSpotVMConfig.java @@ -719,7 +719,10 @@ public int threadTlabPfTopOffset() { // ARMv8-A architecture reference manual D12.2.35 Data Cache Zero ID register says: // * BS, bits [3:0] indicate log2 of the DC ZVA block size in (4-byte) words. // * DZP, bit [4] of indicates whether use of DC ZVA instruction is prohibited. - public final int psrInfoDczidValue = getFieldValue("VM_Version::_psr_info.dczid_el0", Integer.class, "uint32_t", 0x10, (JVMCI ? jvmciGE(JVMCI_19_3_b04) : JDK >= 14) && osArch.equals("aarch64")); + public final int psrInfoDczidValue = getFieldValue("VM_Version::_psr_info.dczid_el0", Integer.class, "uint32_t", 0x10, + (JVMCI ? jvmciGE(JVMCI_19_3_b04) : (JDK == 14 || JDK == 15)) && osArch.equals("aarch64")); + + public final int zvaLength = getFieldValue("VM_Version::_zva_length", Integer.class, "int", 0, JDK >= 16 && osArch.equals("aarch64")); // FIXME This is only temporary until the GC code is changed. public final boolean inlineContiguousAllocationSupported = getFieldValue("CompilerToVM::Data::_supports_inline_contig_alloc", Boolean.class); From 8e338f67b208e12c682fb3042660fd91c3244839 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Mon, 28 Sep 2020 15:14:56 +0000 Subject: [PATCH 41/79] 8253646: ZGC: Avoid overhead of sorting ZStatIterableValues on bootstrap Reviewed-by: pliden, eosterlund --- src/hotspot/share/gc/z/zStat.cpp | 41 ++++++++++++++++++++++---------- src/hotspot/share/gc/z/zStat.hpp | 2 ++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/hotspot/share/gc/z/zStat.cpp b/src/hotspot/share/gc/z/zStat.cpp index 21eacbe2b527a..183e8d5bcc41a 100644 --- a/src/hotspot/share/gc/z/zStat.cpp +++ b/src/hotspot/share/gc/z/zStat.cpp @@ -390,22 +390,35 @@ ZStatIterableValue::ZStatIterableValue(const char* group, template T* ZStatIterableValue::insert() const { - T** current = &_first; + T* const next = _first; + _first = (T*)this; + return next; +} - while (*current != NULL) { - // First sort by group, then by name - const int group_cmp = strcmp((*current)->group(), group()); - const int name_cmp = strcmp((*current)->name(), name()); - if ((group_cmp > 0) || (group_cmp == 0 && name_cmp > 0)) { - break; - } +template +void ZStatIterableValue::sort() { + T* first_unsorted = _first; + _first = NULL; + + while (first_unsorted != NULL) { + T* const value = first_unsorted; + first_unsorted = value->_next; + value->_next = NULL; + + T** current = &_first; + + while (*current != NULL) { + // First sort by group, then by name + const int group_cmp = strcmp((*current)->group(), value->group()); + if ((group_cmp > 0) || (group_cmp == 0 && strcmp((*current)->name(), value->name()) > 0)) { + break; + } - current = &(*current)->_next; + current = &(*current)->_next; + } + value->_next = *current; + *current = value; } - - T* const next = *current; - *current = (T*)this; - return next; } // @@ -882,6 +895,8 @@ void ZStat::run_service() { ZStatSamplerHistory* const history = new ZStatSamplerHistory[ZStatSampler::count()]; LogTarget(Info, gc, stats) log; + ZStatSampler::sort(); + // Main loop while (_metronome.wait_for_tick()) { sample_and_collect(history); diff --git a/src/hotspot/share/gc/z/zStat.hpp b/src/hotspot/share/gc/z/zStat.hpp index 9220327f6f7c4..3faac3b8ea504 100644 --- a/src/hotspot/share/gc/z/zStat.hpp +++ b/src/hotspot/share/gc/z/zStat.hpp @@ -101,6 +101,8 @@ class ZStatIterableValue : public ZStatValue { uint32_t size); public: + static void sort(); + static uint32_t count() { return _count; } From 0054c15f60cce6470be05d29bfacbdb74cfb7bc9 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Mon, 28 Sep 2020 15:42:10 +0000 Subject: [PATCH 42/79] 8253435: Cgroup: 'stomping of _mount_path' crash if manually mounted cpusets exist Reviewed-by: sgehwolf, bobv --- .../os/linux/cgroupSubsystem_linux.cpp | 18 +++++++++++-- .../cgroup/CgroupSubsystemFactory.java | 25 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/hotspot/os/linux/cgroupSubsystem_linux.cpp b/src/hotspot/os/linux/cgroupSubsystem_linux.cpp index d6396a529465b..fada2a732bf1a 100644 --- a/src/hotspot/os/linux/cgroupSubsystem_linux.cpp +++ b/src/hotspot/os/linux/cgroupSubsystem_linux.cpp @@ -302,8 +302,22 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, cg_infos[MEMORY_IDX]._root_mount_path = os::strdup(tmproot); cg_infos[MEMORY_IDX]._data_complete = true; } else if (strcmp(token, "cpuset") == 0) { - assert(cg_infos[CPUSET_IDX]._mount_path == NULL, "stomping of _mount_path"); - cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount); + if (cg_infos[CPUSET_IDX]._mount_path != NULL) { + // On some systems duplicate cpuset controllers get mounted in addition to + // the main cgroup controllers most likely under /sys/fs/cgroup. In that + // case pick the one under /sys/fs/cgroup and discard others. + if (strstr(cg_infos[CPUSET_IDX]._mount_path, "/sys/fs/cgroup") != cg_infos[CPUSET_IDX]._mount_path) { + log_warning(os, container)("Duplicate cpuset controllers detected. Picking %s, skipping %s.", + tmpmount, cg_infos[CPUSET_IDX]._mount_path); + os::free(cg_infos[CPUSET_IDX]._mount_path); + cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount); + } else { + log_warning(os, container)("Duplicate cpuset controllers detected. Picking %s, skipping %s.", + cg_infos[CPUSET_IDX]._mount_path, tmpmount); + } + } else { + cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount); + } cg_infos[CPUSET_IDX]._root_mount_path = os::strdup(tmproot); cg_infos[CPUSET_IDX]._data_complete = true; } else if (strcmp(token, "cpu") == 0) { diff --git a/test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java b/test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java index 9e9f4b897a338..3bbd1278626fe 100644 --- a/test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java +++ b/test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java @@ -60,6 +60,8 @@ public class CgroupSubsystemFactory { private Path cgroupv1CgInfoNonZeroHierarchy; private Path cgroupv1MntInfoNonZeroHierarchyOtherOrder; private Path cgroupv1MntInfoNonZeroHierarchy; + private Path cgroupv1MntInfoDoubleCpuset; + private Path cgroupv1MntInfoDoubleCpuset2; private String mntInfoEmpty = ""; private Path cgroupV1SelfCgroup; private Path cgroupV2SelfCgroup; @@ -102,11 +104,14 @@ public class CgroupSubsystemFactory { "41 30 0:37 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:13 - cgroup none rw,seclabel,devices\n" + "42 30 0:38 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:14 - cgroup none rw,seclabel,cpuset\n" + "43 30 0:39 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:15 - cgroup none rw,seclabel,blkio\n" + - "44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer"; + "44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer\n"; private String mntInfoHybridRest = cgroupv1MountInfoLineMemory + mntInfoHybridStub; private String mntInfoHybridMissingMemory = mntInfoHybridStub; private String mntInfoHybrid = cgroupV2LineHybrid + mntInfoHybridRest; private String mntInfoHybridFlippedOrder = mntInfoHybridRest + cgroupV2LineHybrid; + private String mntInfoCgroupv1MoreCpusetLine = "121 32 0:37 / /cpusets rw,relatime shared:69 - cgroup none rw,cpuset\n"; + private String mntInfoCgroupv1DoubleCpuset = mntInfoCgroupv1MoreCpusetLine + mntInfoHybrid; + private String mntInfoCgroupv1DoubleCpuset2 = mntInfoHybrid + mntInfoCgroupv1MoreCpusetLine; private String cgroupsNonZeroHierarchy = "#subsys_name hierarchy num_cgroups enabled\n" + "cpuset 3 1 1\n" + @@ -157,6 +162,12 @@ private void setup() { cgroupV2MntInfoMissingCgroupv2 = Paths.get(existingDirectory.toString(), "mnt_info_missing_cgroup2"); Files.writeString(cgroupV2MntInfoMissingCgroupv2, mntInfoHybridStub); + + cgroupv1MntInfoDoubleCpuset = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset"); + Files.writeString(cgroupv1MntInfoDoubleCpuset, mntInfoCgroupv1DoubleCpuset); + + cgroupv1MntInfoDoubleCpuset2 = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset2"); + Files.writeString(cgroupv1MntInfoDoubleCpuset2, mntInfoCgroupv1DoubleCpuset2); } catch (IOException e) { throw new RuntimeException(e); } @@ -174,6 +185,16 @@ private boolean isValidCgroup(int value) { return value == CGROUPS_V1 || value == CGROUPS_V2; } + public void testCgroupv1MultipleCpusetMounts(WhiteBox wb, Path mountInfo) { + String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString(); + String procSelfCgroup = cgroupV1SelfCgroup.toString(); + String procSelfMountinfo = mountInfo.toString(); + int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo); + Asserts.assertEQ(CGROUPS_V1, retval, "Multiple cpuset controllers, but only one in /sys/fs/cgroup"); + Asserts.assertTrue(isValidCgroup(retval)); + System.out.println("testCgroupv1MultipleCpusetMounts PASSED!"); + } + public void testCgroupv1NoMounts(WhiteBox wb) { String procCgroups = cgroupv1CgInfoZeroHierarchy.toString(); String procSelfCgroup = cgroupV1SelfCgroup.toString(); @@ -246,6 +267,8 @@ public static void main(String[] args) throws Exception { test.testCgroupV1HybridMntInfoOrder(wb); test.testCgroupv1MissingMemoryController(wb); test.testCgroupv2NoCgroup2Fs(wb); + test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset); + test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset2); } finally { test.teardown(); } From 77a0f3999afa322b64643afd4a161164440af975 Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Mon, 28 Sep 2020 15:49:02 +0000 Subject: [PATCH 43/79] 8253540: InterpreterRuntime::monitorexit should be a JRT_LEAF function Reviewed-by: rehn, mdoerr, dcubed, pchilanomate --- .../cpu/aarch64/interp_masm_aarch64.cpp | 8 ++--- src/hotspot/cpu/arm/interp_masm_arm.cpp | 4 +-- src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp | 10 +++---- src/hotspot/cpu/s390/interp_masm_s390.cpp | 8 ++--- src/hotspot/cpu/x86/interp_masm_x86.cpp | 12 +++----- src/hotspot/cpu/zero/zeroInterpreter_zero.cpp | 6 ++-- .../share/interpreter/interpreterRuntime.cpp | 29 +++++++++---------- .../share/interpreter/interpreterRuntime.hpp | 2 +- .../interpreter/zero/bytecodeInterpreter.cpp | 22 ++++---------- src/hotspot/share/runtime/sharedRuntime.cpp | 8 +++++ 10 files changed, 45 insertions(+), 64 deletions(-) diff --git a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp index ac32e21a9fee0..1d63542933699 100644 --- a/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp @@ -812,9 +812,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1"); if (UseHeavyMonitors) { - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); } else { Label done; @@ -850,9 +848,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) // Call the runtime routine for slow case. str(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); // restore obj - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); bind(done); diff --git a/src/hotspot/cpu/arm/interp_masm_arm.cpp b/src/hotspot/cpu/arm/interp_masm_arm.cpp index 9b0605744d02b..78f7a7fb77c23 100644 --- a/src/hotspot/cpu/arm/interp_masm_arm.cpp +++ b/src/hotspot/cpu/arm/interp_masm_arm.cpp @@ -990,7 +990,7 @@ void InterpreterMacroAssembler::unlock_object(Register Rlock) { assert(Rlock == R1, "the second argument"); if (UseHeavyMonitors) { - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock); } else { Label done, slow_case; @@ -1031,7 +1031,7 @@ void InterpreterMacroAssembler::unlock_object(Register Rlock) { // Call the runtime routine for slow case. str(Robj, Address(Rlock, obj_offset)); // restore obj - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), Rlock); bind(done); } diff --git a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp index 3e843cce943ca..555cfd414183f 100644 --- a/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp +++ b/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp @@ -997,8 +997,7 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) { // Throw IllegalMonitorException if object is not locked by current thread. void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_exceptions) { if (UseHeavyMonitors) { - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - monitor, check_for_exceptions); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); } else { // template code: @@ -1011,7 +1010,7 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_e // monitor->set_obj(NULL); // } else { // // Slow path. - // InterpreterRuntime::monitorexit(THREAD, monitor); + // InterpreterRuntime::monitorexit(monitor); // } const Register object = R7_ARG5; @@ -1065,13 +1064,12 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_e // } else { // // Slow path. - // InterpreterRuntime::monitorexit(THREAD, monitor); + // InterpreterRuntime::monitorexit(monitor); // The lock has been converted into a heavy lock and hence // we need to get into the slow case. bind(slow_case); - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - monitor, check_for_exceptions); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); // } Label done; diff --git a/src/hotspot/cpu/s390/interp_masm_s390.cpp b/src/hotspot/cpu/s390/interp_masm_s390.cpp index fdcfe42719b56..d612d528c5140 100644 --- a/src/hotspot/cpu/s390/interp_masm_s390.cpp +++ b/src/hotspot/cpu/s390/interp_masm_s390.cpp @@ -1080,7 +1080,7 @@ void InterpreterMacroAssembler::lock_object(Register monitor, Register object) { void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) { if (UseHeavyMonitors) { - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); return; } @@ -1095,7 +1095,7 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) // monitor->set_obj(NULL); // } else { // // Slow path. - // InterpreterRuntime::monitorexit(THREAD, monitor); + // InterpreterRuntime::monitorexit(monitor); // } const Register displaced_header = Z_ARG4; @@ -1149,12 +1149,12 @@ void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) // } else { // // Slow path. - // InterpreterRuntime::monitorexit(THREAD, monitor); + // InterpreterRuntime::monitorexit(monitor); // The lock has been converted into a heavy lock and hence // we need to get into the slow case. z_stg(object, obj_entry); // Restore object entry, has been cleared above. - call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); // } diff --git a/src/hotspot/cpu/x86/interp_masm_x86.cpp b/src/hotspot/cpu/x86/interp_masm_x86.cpp index 8956b1dd1fc04..384d5795d7f48 100644 --- a/src/hotspot/cpu/x86/interp_masm_x86.cpp +++ b/src/hotspot/cpu/x86/interp_masm_x86.cpp @@ -1281,9 +1281,7 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) { "The argument is only for looks. It must be c_rarg1"); if (UseHeavyMonitors) { - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); } else { Label done; @@ -1324,12 +1322,10 @@ void InterpreterMacroAssembler::unlock_object(Register lock_reg) { // zero for simple unlock of a stack-lock case jcc(Assembler::zero, done); + // Call the runtime routine for slow case. - movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), - obj_reg); // restore obj - call_VM(noreg, - CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), - lock_reg); + movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj + call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg); bind(done); diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp index 9aae3e751e5b9..1fcc8ef0f22dd 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp @@ -459,10 +459,8 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { if (header.to_pointer() != NULL) { markWord old_header = markWord::encode(lock); if (rcvr->cas_set_mark(header, old_header) != old_header) { - monitor->set_obj(rcvr); { - HandleMark hm(thread); - CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); - } + monitor->set_obj(rcvr); + InterpreterRuntime::monitorexit(monitor); } } } diff --git a/src/hotspot/share/interpreter/interpreterRuntime.cpp b/src/hotspot/share/interpreter/interpreterRuntime.cpp index 853013dd7f326..3273d05acc34f 100644 --- a/src/hotspot/share/interpreter/interpreterRuntime.cpp +++ b/src/hotspot/share/interpreter/interpreterRuntime.cpp @@ -733,24 +733,21 @@ JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, Ba JRT_END -//%note monitor_1 -JRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem)) -#ifdef ASSERT - thread->last_frame().interpreter_frame_verify_monitor(elem); -#endif - Handle h_obj(thread, elem->obj()); - assert(Universe::heap()->is_in_or_null(h_obj()), - "must be NULL or an object"); - if (elem == NULL || h_obj()->is_unlocked()) { - THROW(vmSymbols::java_lang_IllegalMonitorStateException()); +JRT_LEAF(void, InterpreterRuntime::monitorexit(BasicObjectLock* elem)) + oop obj = elem->obj(); + assert(Universe::heap()->is_in(obj), "must be an object"); + // The object could become unlocked through a JNI call, which we have no other checks for. + // Give a fatal message if CheckJNICalls. Otherwise we ignore it. + if (obj->is_unlocked()) { + if (CheckJNICalls) { + fatal("Object has been unlocked by JNI"); + } + return; } - ObjectSynchronizer::exit(h_obj(), elem->lock(), thread); - // Free entry. This must be done here, since a pending exception might be installed on - // exit. If it is not cleared, the exception handling code will try to unlock the monitor again. + ObjectSynchronizer::exit(obj, elem->lock(), Thread::current()); + // Free entry. If it is not cleared, the exception handling code will try to unlock the monitor + // again at method exit or in the case of an exception. elem->set_obj(NULL); -#ifdef ASSERT - thread->last_frame().interpreter_frame_verify_monitor(elem); -#endif JRT_END diff --git a/src/hotspot/share/interpreter/interpreterRuntime.hpp b/src/hotspot/share/interpreter/interpreterRuntime.hpp index 083c572d655d8..73fbf31128860 100644 --- a/src/hotspot/share/interpreter/interpreterRuntime.hpp +++ b/src/hotspot/share/interpreter/interpreterRuntime.hpp @@ -101,7 +101,7 @@ class InterpreterRuntime: AllStatic { public: // Synchronization static void monitorenter(JavaThread* thread, BasicObjectLock* elem); - static void monitorexit (JavaThread* thread, BasicObjectLock* elem); + static void monitorexit (BasicObjectLock* elem); static void throw_illegal_monitor_state_exception(JavaThread* thread); static void new_illegal_monitor_state_exception(JavaThread* thread); diff --git a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp index fe3ac9fdbaccf..ba162c3570307 100644 --- a/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp +++ b/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp @@ -627,7 +627,7 @@ BytecodeInterpreter::run(interpreterState istate) { (* BiasedLocking::rebiased_lock_entry_count_addr())++; } } else { - CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception); + InterpreterRuntime::monitorenter(THREAD, mon); } success = true; } else { @@ -1822,7 +1822,7 @@ BytecodeInterpreter::run(interpreterState istate) { if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) { // restore object for the slow case most_recent->set_obj(lockee); - CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception); + InterpreterRuntime::monitorexit(most_recent); } } } @@ -2959,11 +2959,7 @@ BytecodeInterpreter::run(interpreterState istate) { if (lockee->cas_set_mark(header, old_header) != old_header) { // restore object for the slow case end->set_obj(lockee); - { - // Prevent any HandleMarkCleaner from freeing our live handles - HandleMark __hm(THREAD); - CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end)); - } + InterpreterRuntime::monitorexit(end); } } } @@ -3013,11 +3009,7 @@ BytecodeInterpreter::run(interpreterState istate) { THREAD->clear_pending_exception(); } } else if (UseHeavyMonitors) { - { - // Prevent any HandleMarkCleaner from freeing our live handles. - HandleMark __hm(THREAD); - CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base)); - } + InterpreterRuntime::monitorexit(base); if (THREAD->has_pending_exception()) { if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception()); THREAD->clear_pending_exception(); @@ -3035,11 +3027,7 @@ BytecodeInterpreter::run(interpreterState istate) { if (rcvr->cas_set_mark(header, old_header) != old_header) { // restore object for the slow case base->set_obj(rcvr); - { - // Prevent any HandleMarkCleaner from freeing our live handles - HandleMark __hm(THREAD); - CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base)); - } + InterpreterRuntime::monitorexit(base); if (THREAD->has_pending_exception()) { if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception()); THREAD->clear_pending_exception(); diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index 92e2f20b928cc..44e2da7f39953 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -2097,6 +2097,14 @@ void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThrea assert(JavaThread::current() == thread, "invariant"); // Exit must be non-blocking, and therefore no exceptions can be thrown. EXCEPTION_MARK; + // The object could become unlocked through a JNI call, which we have no other checks for. + // Give a fatal message if CheckJNICalls. Otherwise we ignore it. + if (obj->is_unlocked()) { + if (CheckJNICalls) { + fatal("Object has been unlocked by JNI"); + } + return; + } ObjectSynchronizer::exit(obj, lock, THREAD); } From 1ae6b533fbba433e64868aa3b6846041e3a91136 Mon Sep 17 00:00:00 2001 From: Pankaj Bansal Date: Mon, 28 Sep 2020 16:05:38 +0000 Subject: [PATCH 44/79] 8252194: Add automated test for fix done in JDK-8218469 Reviewed-by: serb, jdv, kizune --- .../swing/JSlider/TestJSliderRendering.java | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 test/jdk/javax/swing/JSlider/TestJSliderRendering.java diff --git a/test/jdk/javax/swing/JSlider/TestJSliderRendering.java b/test/jdk/javax/swing/JSlider/TestJSliderRendering.java new file mode 100644 index 0000000000000..ebf12021ced86 --- /dev/null +++ b/test/jdk/javax/swing/JSlider/TestJSliderRendering.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2020, 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 + * @requires (os.family == "linux") + * @key headful + * @bug 8218469 + * @summary Tests JSlider is rendered properly with gtk3 + * @run main TestJSliderRendering + */ + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; +import java.awt.Color; +import java.awt.Component; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; + +public class TestJSliderRendering { + private static JFrame frame; + private static JSlider slider; + private static Point point; + private static Rectangle rect; + private static Robot robot; + private static final String GTK_LAF_CLASS = "GTKLookAndFeel"; + private static int minColorDifference = 50; + + private static void blockTillDisplayed(Component comp) { + Point p = null; + while (p == null) { + try { + p = comp.getLocationOnScreen(); + } catch (IllegalStateException e) { + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + } + } + } + } + + private static int getMaxColorDiff(Color c1, Color c2) { + return Math.max(Math.abs(c1.getRed() - c2.getRed()), + Math.max(Math.abs(c1.getGreen() - c2.getGreen()), + Math.abs(c1.getBlue() - c2.getBlue()))); + } + + public static void main(String[] args) throws Exception { + if (!System.getProperty("os.name").startsWith("Linux")) { + System.out.println("This test is meant for Linux platform only"); + return; + } + + for (UIManager.LookAndFeelInfo lookAndFeelInfo : + UIManager.getInstalledLookAndFeels()) { + if (lookAndFeelInfo.getClassName().contains(GTK_LAF_CLASS)) { + try { + UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); + } catch (final UnsupportedLookAndFeelException ignored) { + System.out.println("GTK L&F could not be set, so this " + + "test can not be run in this scenario "); + return; + } + } + } + + robot = new Robot(); + robot.setAutoDelay(100); + + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JPanel panel = new JPanel(); + slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50); + panel.add(slider); + frame = new JFrame("TestJSliderRendering"); + frame.add(panel); + frame.setSize(200, 200); + frame.setAlwaysOnTop(true); + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + }); + + robot.waitForIdle(); + robot.delay(500); + + blockTillDisplayed(slider); + SwingUtilities.invokeAndWait(() -> { + point = slider.getLocationOnScreen(); + rect = slider.getBounds(); + }); + robot.waitForIdle(); + robot.delay(500); + + int h = point.y+rect.height*6/7; + + Color backgroundColor = robot + .getPixelColor(point.x+rect.width/4, h); + robot.waitForIdle(); + + boolean knobFound = false; + for (int i=point.x+rect.width/4;i minColorDifference) { + knobFound = true; + break; + } + robot.waitForIdle(); + } + if (!knobFound) { + throw new RuntimeException("The slider is not rendered properly"); + } + } finally { + if (frame != null) { + SwingUtilities.invokeAndWait(frame::dispose); + } + } + } +} From 821bd08cd691fba338ba86b771b8573fd51c06c8 Mon Sep 17 00:00:00 2001 From: "Daniel D. Daugherty" Date: Mon, 28 Sep 2020 16:41:35 +0000 Subject: [PATCH 45/79] 8253667: ProblemList tools/jlink/JLinkReproducible{,3}Test.java on linux-aarch64 Reviewed-by: dfuchs, iignatyev --- test/jdk/ProblemList.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 56e8d3f291d27..aeac8f61fe037 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -854,7 +854,8 @@ sanity/client/SwingSet/src/ScrollPaneDemoTest.java 8225013 linux-all # core_tools -tools/jlink/JLinkReproducibleTest.java 8217166 windows-all +tools/jlink/JLinkReproducibleTest.java 8217166 windows-all,linux-aarch64 +tools/jlink/JLinkReproducible3Test.java 8253688 linux-aarch64 tools/jlink/plugins/CompressorPluginTest.java 8247407 generic-all ############################################################################ From d25b03e987396ef72534abc3c49bd7b53380a561 Mon Sep 17 00:00:00 2001 From: Mikael Vidstedt Date: Mon, 28 Sep 2020 18:31:30 +0000 Subject: [PATCH 46/79] 8253616: Change to GCC 10.2 for building on Linux at Oracle Reviewed-by: erikj --- doc/building.html | 4 ++-- doc/building.md | 4 ++-- make/conf/jib-profiles.js | 4 ++-- make/devkit/Tools.gmk | 34 +++++++++++++++++++++++++++------- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/doc/building.html b/doc/building.html index 55a434305386a..5f615f9d4eff5 100644 --- a/doc/building.html +++ b/doc/building.html @@ -265,7 +265,7 @@

        Native Compiler (Toolchain) Requ Linux -gcc 9.2.0 +gcc 10.2.0 macOS @@ -280,7 +280,7 @@

        Native Compiler (Toolchain) Requ

        All compilers are expected to be able to compile to the C99 language standard, as some C99 features are used in the source code. Microsoft Visual Studio doesn't fully support C99 so in practice shared code is limited to using C99 features that it does support.

        gcc

        The minimum accepted version of gcc is 5.0. Older versions will generate a warning by configure and are unlikely to work.

        -

        The JDK is currently known to be able to compile with at least version 9.2 of gcc.

        +

        The JDK is currently known to be able to compile with at least version 10.2 of gcc.

        In general, any version between these two should be usable.

        clang

        The minimum accepted version of clang is 3.5. Older versions will not be accepted by configure.

        diff --git a/doc/building.md b/doc/building.md index 0f3ce6e12e2d3..47fa445998d19 100644 --- a/doc/building.md +++ b/doc/building.md @@ -302,7 +302,7 @@ issues. Operating system Toolchain version ------------------ ------------------------------------------------------- - Linux gcc 9.2.0 + Linux gcc 10.2.0 macOS Apple Xcode 10.1 (using clang 10.0.0) Windows Microsoft Visual Studio 2019 update 16.7.2 @@ -316,7 +316,7 @@ features that it does support. The minimum accepted version of gcc is 5.0. Older versions will generate a warning by `configure` and are unlikely to work. -The JDK is currently known to be able to compile with at least version 9.2 of +The JDK is currently known to be able to compile with at least version 10.2 of gcc. In general, any version between these two should be usable. diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js index a186c77168683..4d848791cdb25 100644 --- a/make/conf/jib-profiles.js +++ b/make/conf/jib-profiles.js @@ -959,10 +959,10 @@ var getJibProfilesProfiles = function (input, common, data) { var getJibProfilesDependencies = function (input, common) { var devkit_platform_revisions = { - linux_x64: "gcc9.2.0-OL6.4+1.0", + linux_x64: "gcc10.2.0-OL6.4+1.0", macosx_x64: "Xcode11.3.1-MacOSX10.15+1.0", windows_x64: "VS2019-16.7.2+1.0", - linux_aarch64: "gcc9.2.0-OL7.6+1.0", + linux_aarch64: "gcc10.2.0-OL7.6+1.0", linux_arm: "gcc8.2.0-Fedora27+1.0", linux_ppc64le: "gcc8.2.0-Fedora27+1.0", linux_s390x: "gcc8.2.0-Fedora27+1.0" diff --git a/make/devkit/Tools.gmk b/make/devkit/Tools.gmk index b6ea735eaaf43..d5ef8eac84942 100644 --- a/make/devkit/Tools.gmk +++ b/make/devkit/Tools.gmk @@ -87,11 +87,20 @@ endif # Define external dependencies # Latest that could be made to work. -GCC_VER := 9.2.0 -ifeq ($(GCC_VER), 9.2.0) +GCC_VER := 10.2.0 +ifeq ($(GCC_VER), 10.2.0) + gcc_ver := gcc-10.2.0 + binutils_ver := binutils-2.35 + ccache_ver := ccache-3.7.11 + mpfr_ver := mpfr-4.1.0 + gmp_ver := gmp-6.2.0 + mpc_ver := mpc-1.1.0 + gdb_ver := gdb-9.2 + REQUIRED_MIN_MAKE_MAJOR_VERSION := 4 +else ifeq ($(GCC_VER), 9.2.0) gcc_ver := gcc-9.2.0 binutils_ver := binutils-2.34 - ccache_ver := 3.7.3 + ccache_ver := ccache-3.7.3 mpfr_ver := mpfr-3.1.5 gmp_ver := gmp-6.1.2 mpc_ver := mpc-1.0.3 @@ -99,7 +108,7 @@ ifeq ($(GCC_VER), 9.2.0) else ifeq ($(GCC_VER), 8.3.0) gcc_ver := gcc-8.3.0 binutils_ver := binutils-2.32 - ccache_ver := 3.7.3 + ccache_ver := ccache-3.7.3 mpfr_ver := mpfr-3.1.5 gmp_ver := gmp-6.1.2 mpc_ver := mpc-1.0.3 @@ -107,7 +116,7 @@ else ifeq ($(GCC_VER), 8.3.0) else ifeq ($(GCC_VER), 7.3.0) gcc_ver := gcc-7.3.0 binutils_ver := binutils-2.30 - ccache_ver := 3.3.6 + ccache_ver := ccache-3.3.6 mpfr_ver := mpfr-3.1.5 gmp_ver := gmp-6.1.2 mpc_ver := mpc-1.0.3 @@ -115,7 +124,7 @@ else ifeq ($(GCC_VER), 7.3.0) else ifeq ($(GCC_VER), 4.9.2) gcc_ver := gcc-4.9.2 binutils_ver := binutils-2.25 - ccache_ver := 3.2.1 + ccache_ver := ccache-3.2.1 mpfr_ver := mpfr-3.0.1 gmp_ver := gmp-4.3.2 mpc_ver := mpc-1.0.1 @@ -124,9 +133,20 @@ else $(error Unsupported GCC version) endif +ifneq ($(REQUIRED_MIN_MAKE_MAJOR_VERSION),) + MAKE_MAJOR_VERSION := $(word 1,$(subst ., ,$(MAKE_VERSION))) + SUPPORTED_MAKE_VERSION := $(shell [ $(MAKE_MAJOR_VERSION) -ge $(REQUIRED_MIN_MAKE_MAJOR_VERSION) ] && echo true) + ifneq ($(SUPPORTED_MAKE_VERSION),true) + $(error "Make v$(MAKE_VERSION) is too old, must use v$(REQUIRED_MIN_MAKE_MAJOR_VERSION) or above") + endif +endif + +ccache_ver_only := $(patsubst ccache-%,%,$(ccache_ver)) + + GCC := http://ftp.gnu.org/pub/gnu/gcc/$(gcc_ver)/$(gcc_ver).tar.xz BINUTILS := http://ftp.gnu.org/pub/gnu/binutils/$(binutils_ver).tar.gz -CCACHE := https://github.com/ccache/ccache/releases/download/v$(ccache_ver)/ccache-$(ccache_ver).tar.xz +CCACHE := https://github.com/ccache/ccache/releases/download/v$(ccache_ver_only)/$(ccache_ver).tar.xz MPFR := https://www.mpfr.org/${mpfr_ver}/${mpfr_ver}.tar.bz2 GMP := http://ftp.gnu.org/pub/gnu/gmp/${gmp_ver}.tar.bz2 MPC := http://ftp.gnu.org/pub/gnu/mpc/${mpc_ver}.tar.gz From ac15d6445b9241c2955349fd4b573aa84b82d13f Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Mon, 28 Sep 2020 21:20:14 +0000 Subject: [PATCH 47/79] 8241151: Incorrect lint warning for no definition of serialVersionUID in a record Co-authored-by: Bernard Blaser Co-authored-by: Vicente Romero Reviewed-by: jjg --- .../com/sun/tools/javac/comp/Attr.java | 4 ++-- .../javac/records/RecordCompilationTests.java | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index b5cae83e3f47c..a12c7e81ee5f0 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -5348,8 +5348,8 @@ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { } if (svuid == null) { - log.warning(LintCategory.SERIAL, - tree.pos(), Warnings.MissingSVUID(c)); + if (!c.isRecord()) + log.warning(LintCategory.SERIAL, tree.pos(), Warnings.MissingSVUID(c)); return; } diff --git a/test/langtools/tools/javac/records/RecordCompilationTests.java b/test/langtools/tools/javac/records/RecordCompilationTests.java index 55911df1ebdac..279ded7443d51 100644 --- a/test/langtools/tools/javac/records/RecordCompilationTests.java +++ b/test/langtools/tools/javac/records/RecordCompilationTests.java @@ -26,7 +26,7 @@ /** * RecordCompilationTests * - * @test 8250629 8252307 8247352 + * @test 8250629 8252307 8247352 8241151 * @summary Negative compilation tests, and positive compilation (smoke) tests for records * @library /lib/combo /tools/lib /tools/javac/lib * @modules @@ -145,8 +145,10 @@ public boolean process(Set annotations, RoundEnvironment } } + boolean useAP; + public RecordCompilationTests() { - boolean useAP = System.getProperty("useAP") == null ? false : System.getProperty("useAP").equals("true"); + useAP = System.getProperty("useAP", "false").equals("true"); setDefaultFilename("R.java"); setCompileOptions(useAP ? PREVIEW_OPTIONS_WITH_AP : PREVIEW_OPTIONS); System.out.println(useAP ? "running all tests using an annotation processor" : "running all tests without annotation processor"); @@ -1664,4 +1666,20 @@ record R(T t[]) {} """ ); } + + public void testNoWarningForSerializableRecords() { + if (!useAP) { + /* dont execute this test when the default annotation processor is on as it will fail due to + * spurious warnings + */ + appendCompileOptions("-Werror", "-Xlint:serial"); + assertOK( + """ + import java.io.*; + record R() implements java.io.Serializable {} + """ + ); + removeLastCompileOptions(2); + } + } } From 527b0e44eba9ec70cc2b3622a1d1e94b06b8017d Mon Sep 17 00:00:00 2001 From: Mikael Vidstedt Date: Mon, 28 Sep 2020 21:22:00 +0000 Subject: [PATCH 48/79] 8248984: Bump minimum boot jdk to JDK 15 Reviewed-by: darcy, erikj, dholmes --- make/autoconf/version-numbers | 2 +- make/conf/jib-profiles.js | 21 ++++----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/make/autoconf/version-numbers b/make/autoconf/version-numbers index 81874ad65f19d..ca9a577244555 100644 --- a/make/autoconf/version-numbers +++ b/make/autoconf/version-numbers @@ -36,7 +36,7 @@ DEFAULT_VERSION_EXTRA3=0 DEFAULT_VERSION_DATE=2021-03-16 DEFAULT_VERSION_CLASSFILE_MAJOR=60 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`" DEFAULT_VERSION_CLASSFILE_MINOR=0 -DEFAULT_ACCEPTABLE_BOOT_VERSIONS="14 15 16" +DEFAULT_ACCEPTABLE_BOOT_VERSIONS="15 16" DEFAULT_JDK_SOURCE_TARGET_VERSION=16 DEFAULT_PROMOTED_VERSION_PRE=ea diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js index 4d848791cdb25..e70d6617745af 100644 --- a/make/conf/jib-profiles.js +++ b/make/conf/jib-profiles.js @@ -381,7 +381,7 @@ var getJibProfilesCommon = function (input, data) { }; }; - common.boot_jdk_version = "14"; + common.boot_jdk_version = "15"; common.boot_jdk_build_number = "36"; common.boot_jdk_home = input.get("boot_jdk", "install_path") + "/jdk-" + common.boot_jdk_version @@ -994,17 +994,8 @@ var getJibProfilesDependencies = function (input, common) { ? input.get("gnumake", "install_path") + "/cygwin/bin" : input.get("gnumake", "install_path") + "/bin"); - if (input.build_cpu == 'aarch64') { - boot_jdk = { - organization: common.organization, - ext: "tar.gz", - module: "jdk-linux_aarch64", - revision: "14+1.0", - configure_args: "--with-boot-jdk=" + common.boot_jdk_home, - environment_path: common.boot_jdk_home + "/bin" - } - } else { - boot_jdk = { + var dependencies = { + boot_jdk: { server: "jpg", product: "jdk", version: common.boot_jdk_version, @@ -1013,11 +1004,7 @@ var getJibProfilesDependencies = function (input, common) { + boot_jdk_platform + "_bin" + boot_jdk_ext, configure_args: "--with-boot-jdk=" + common.boot_jdk_home, environment_path: common.boot_jdk_home + "/bin" - } - } - - var dependencies = { - boot_jdk: boot_jdk, + }, devkit: { organization: common.organization, From 70b0fccf79ac7193b36c49aff0286fdc09bb370c Mon Sep 17 00:00:00 2001 From: Patric Hedlin Date: Mon, 28 Sep 2020 21:48:55 +0000 Subject: [PATCH 49/79] 8253728: tests fail with "assert(fr.is_compiled_frame()) failed: Wrong frame type" Reviewed-by: kvn --- src/hotspot/share/runtime/deoptimization.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hotspot/share/runtime/deoptimization.cpp b/src/hotspot/share/runtime/deoptimization.cpp index 59eb4583f40e2..8c850cda39c01 100644 --- a/src/hotspot/share/runtime/deoptimization.cpp +++ b/src/hotspot/share/runtime/deoptimization.cpp @@ -1623,7 +1623,6 @@ void Deoptimization::deoptimize_frame_internal(JavaThread* thread, intptr_t* id, while (fr.id() != id) { fr = fr.sender(®_map); } - assert(fr.is_compiled_frame(), "Wrong frame type"); deoptimize(thread, fr, reason); } From 9c17a35e50e86eaa1274389f8a4709da3a9c6402 Mon Sep 17 00:00:00 2001 From: Jie Fu Date: Tue, 29 Sep 2020 06:37:46 +0000 Subject: [PATCH 50/79] 8253748: StressIGV tests fail with release VMs Reviewed-by: thartmann --- .../jtreg/compiler/arguments/TestStressIGVNOptions.java | 4 ++-- test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java | 2 +- test/hotspot/jtreg/compiler/debug/TestStressIGVN.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java b/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java index 4077fb3dbb929..d55bc640e246e 100644 --- a/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java +++ b/test/hotspot/jtreg/compiler/arguments/TestStressIGVNOptions.java @@ -27,9 +27,9 @@ * @requires vm.compiler2.enabled * @summary Tests that different combinations of the options -XX:+StressIGVN and * -XX:StressSeed=N are accepted. - * @run main/othervm -XX:+StressIGVN + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN * compiler.arguments.TestStressIGVNOptions - * @run main/othervm -XX:+StressIGVN -XX:StressSeed=42 + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:StressSeed=42 * compiler.arguments.TestStressIGVNOptions */ diff --git a/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java b/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java index e256c46f9f8eb..a477f590d7048 100644 --- a/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java +++ b/test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java @@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception { String className = TestGenerateStressSeed.class.getName(); String log = "test.log"; String[] procArgs = { - "-Xcomp", "-XX:-TieredCompilation", + "-Xcomp", "-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:CompileOnly=" + className + "::sum", "-XX:+StressIGVN", "-XX:+LogCompilation", "-XX:LogFile=" + log, className, "10"}; ProcessTools.createJavaProcessBuilder(procArgs).start().waitFor(); diff --git a/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java b/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java index 0b64a9cffe809..37103bd6ef525 100644 --- a/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java +++ b/test/hotspot/jtreg/compiler/debug/TestStressIGVN.java @@ -30,7 +30,7 @@ /* * @test * @bug 8252219 - * @requires vm.compiler2.enabled + * @requires vm.debug == true & vm.compiler2.enabled * @summary Tests that compilations with the same seed yield the same IGVN * trace, and compilations with different seeds yield different IGVN * traces. From e63b90cc17d3ad08361f0a959f919ae79dd768bf Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 29 Sep 2020 07:25:08 +0000 Subject: [PATCH 51/79] 8251358: Clean up Access configuration after Shenandoah barrier change Reviewed-by: eosterlund, rkennke, shade --- .../share/classfile/javaClasses.inline.hpp | 6 +- .../share/gc/g1/g1FullGCCompactTask.cpp | 4 +- .../share/gc/g1/g1FullGCCompactionPoint.cpp | 8 +-- .../share/gc/g1/g1FullGCMarker.inline.hpp | 2 +- .../gc/g1/g1FullGCOopClosures.inline.hpp | 6 +- .../share/gc/g1/g1OopClosures.inline.hpp | 6 +- .../share/gc/g1/g1ParScanThreadState.cpp | 8 +-- .../parallel/psCompactionManager.inline.hpp | 2 +- .../share/gc/parallel/psPromotionLAB.cpp | 2 +- .../gc/parallel/psPromotionManager.inline.hpp | 4 +- .../share/gc/serial/defNewGeneration.cpp | 2 +- src/hotspot/share/gc/serial/markSweep.cpp | 6 +- .../share/gc/serial/markSweep.inline.hpp | 14 ++-- .../share/gc/shared/barrierSetConfig.hpp | 16 ----- src/hotspot/share/gc/shared/memAllocator.cpp | 4 +- .../share/gc/shared/preservedMarks.inline.hpp | 4 +- src/hotspot/share/gc/shared/space.cpp | 6 +- src/hotspot/share/gc/shared/space.inline.hpp | 4 +- .../shenandoahForwarding.inline.hpp | 10 +-- .../gc/shenandoah/shenandoahMarkCompact.cpp | 8 +-- src/hotspot/share/memory/heapShared.cpp | 2 +- src/hotspot/share/oops/access.hpp | 5 -- src/hotspot/share/oops/accessBackend.hpp | 24 +------ .../share/oops/accessBackend.inline.hpp | 2 +- src/hotspot/share/oops/accessDecorators.hpp | 14 +--- src/hotspot/share/oops/arrayOop.hpp | 1 - src/hotspot/share/oops/arrayOop.inline.hpp | 5 -- .../share/oops/instanceKlass.inline.hpp | 6 +- src/hotspot/share/oops/objArrayKlass.cpp | 8 +-- .../share/oops/objArrayKlass.inline.hpp | 8 +-- src/hotspot/share/oops/objArrayOop.hpp | 2 - src/hotspot/share/oops/objArrayOop.inline.hpp | 6 -- src/hotspot/share/oops/oop.cpp | 2 +- src/hotspot/share/oops/oop.hpp | 21 +++--- src/hotspot/share/oops/oop.inline.hpp | 65 +++++++------------ src/hotspot/share/prims/jvmtiTagMap.cpp | 3 +- src/hotspot/share/prims/unsafe.cpp | 8 +-- .../gtest/gc/shared/test_preservedMarks.cpp | 8 +-- 38 files changed, 110 insertions(+), 202 deletions(-) diff --git a/src/hotspot/share/classfile/javaClasses.inline.hpp b/src/hotspot/share/classfile/javaClasses.inline.hpp index a654516a37799..3e880da8ae5ed 100644 --- a/src/hotspot/share/classfile/javaClasses.inline.hpp +++ b/src/hotspot/share/classfile/javaClasses.inline.hpp @@ -113,7 +113,7 @@ void java_lang_ref_Reference::set_referent_raw(oop ref, oop value) { } HeapWord* java_lang_ref_Reference::referent_addr_raw(oop ref) { - return ref->obj_field_addr_raw(_referent_offset); + return ref->obj_field_addr(_referent_offset); } oop java_lang_ref_Reference::next(oop ref) { @@ -129,7 +129,7 @@ void java_lang_ref_Reference::set_next_raw(oop ref, oop value) { } HeapWord* java_lang_ref_Reference::next_addr_raw(oop ref) { - return ref->obj_field_addr_raw(_next_offset); + return ref->obj_field_addr(_next_offset); } oop java_lang_ref_Reference::discovered(oop ref) { @@ -145,7 +145,7 @@ void java_lang_ref_Reference::set_discovered_raw(oop ref, oop value) { } HeapWord* java_lang_ref_Reference::discovered_addr_raw(oop ref) { - return ref->obj_field_addr_raw(_discovered_offset); + return ref->obj_field_addr(_discovered_offset); } bool java_lang_ref_Reference::is_final(oop ref) { diff --git a/src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp b/src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp index 97742d26ee94f..be35978ba17da 100644 --- a/src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp +++ b/src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp @@ -48,7 +48,7 @@ class G1ResetHumongousClosure : public HeapRegionClosure { if (_bitmap->is_marked(obj)) { // Clear bitmap and fix mark word. _bitmap->clear(obj); - obj->init_mark_raw(); + obj->init_mark(); } else { assert(current->is_empty(), "Should have been cleared in phase 2."); } @@ -71,7 +71,7 @@ size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) { HeapWord* obj_addr = cast_from_oop(obj); assert(obj_addr != destination, "everything in this pass should be moving"); Copy::aligned_conjoint_words(obj_addr, destination, size); - oop(destination)->init_mark_raw(); + oop(destination)->init_mark(); assert(oop(destination)->klass() != NULL, "should have a class"); return size; diff --git a/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.cpp b/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.cpp index a27f7e73ad99d..2799ac5109e20 100644 --- a/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.cpp +++ b/src/hotspot/share/gc/g1/g1FullGCCompactionPoint.cpp @@ -112,15 +112,15 @@ void G1FullGCCompactionPoint::forward(oop object, size_t size) { // with BiasedLocking, in this case forwardee() will return NULL // even if the mark-word is used. This is no problem since // forwardee() will return NULL in the compaction phase as well. - object->init_mark_raw(); + object->init_mark(); } else { // Make sure object has the correct mark-word set or that it will be // fixed when restoring the preserved marks. - assert(object->mark_raw() == markWord::prototype_for_klass(object->klass()) || // Correct mark + assert(object->mark() == markWord::prototype_for_klass(object->klass()) || // Correct mark object->mark_must_be_preserved() || // Will be restored by PreservedMarksSet - (UseBiasedLocking && object->has_bias_pattern_raw()), // Will be restored by BiasedLocking + (UseBiasedLocking && object->has_bias_pattern()), // Will be restored by BiasedLocking "should have correct prototype obj: " PTR_FORMAT " mark: " PTR_FORMAT " prototype: " PTR_FORMAT, - p2i(object), object->mark_raw().value(), markWord::prototype_for_klass(object->klass()).value()); + p2i(object), object->mark().value(), markWord::prototype_for_klass(object->klass()).value()); } assert(object->forwardee() == NULL, "should be forwarded to NULL"); } diff --git a/src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp b/src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp index 5baadbb0edf60..efa0fb91bbf7a 100644 --- a/src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp +++ b/src/hotspot/share/gc/g1/g1FullGCMarker.inline.hpp @@ -50,7 +50,7 @@ inline bool G1FullGCMarker::mark_object(oop obj) { } // Marked by us, preserve if needed. - markWord mark = obj->mark_raw(); + markWord mark = obj->mark(); if (obj->mark_must_be_preserved(mark) && !G1ArchiveAllocator::is_open_archive_object(obj)) { preserved_stack()->push(obj, mark); diff --git a/src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp b/src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp index e79eea7785109..16c34eace8df6 100644 --- a/src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp +++ b/src/hotspot/share/gc/g1/g1FullGCOopClosures.inline.hpp @@ -77,11 +77,11 @@ template inline void G1AdjustClosure::adjust_pointer(T* p) { oop forwardee = obj->forwardee(); if (forwardee == NULL) { // Not forwarded, return current reference. - assert(obj->mark_raw() == markWord::prototype_for_klass(obj->klass()) || // Correct mark + assert(obj->mark() == markWord::prototype_for_klass(obj->klass()) || // Correct mark obj->mark_must_be_preserved() || // Will be restored by PreservedMarksSet - (UseBiasedLocking && obj->has_bias_pattern_raw()), // Will be restored by BiasedLocking + (UseBiasedLocking && obj->has_bias_pattern()), // Will be restored by BiasedLocking "Must have correct prototype or be preserved, obj: " PTR_FORMAT ", mark: " PTR_FORMAT ", prototype: " PTR_FORMAT, - p2i(obj), obj->mark_raw().value(), markWord::prototype_for_klass(obj->klass()).value()); + p2i(obj), obj->mark().value(), markWord::prototype_for_klass(obj->klass()).value()); return; } diff --git a/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp b/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp index d77ebb91ad524..012f6d8a8b256 100644 --- a/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp +++ b/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp @@ -47,8 +47,8 @@ inline void G1ScanClosureBase::prefetch_and_push(T* p, const oop obj) { // stall. We'll try to prefetch the object (for write, given that // we might need to install the forwarding reference) and we'll // get back to it when pop it from the queue - Prefetch::write(obj->mark_addr_raw(), 0); - Prefetch::read(obj->mark_addr_raw(), (HeapWordSize*2)); + Prefetch::write(obj->mark_addr(), 0); + Prefetch::read(obj->mark_addr(), (HeapWordSize*2)); // slightly paranoid test; I'm trying to catch potential // problems before we go into push_on_queue to know where the @@ -231,7 +231,7 @@ void G1ParCopyClosure::do_oop_work(T* p) { const G1HeapRegionAttr state = _g1h->region_attr(obj); if (state.is_in_cset()) { oop forwardee; - markWord m = obj->mark_raw(); + markWord m = obj->mark(); if (m.is_marked()) { forwardee = (oop) m.decode_pointer(); } else { diff --git a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp index 00d9876bec417..19f7a44befe5c 100644 --- a/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp +++ b/src/hotspot/share/gc/g1/g1ParScanThreadState.cpp @@ -193,7 +193,7 @@ void G1ParScanThreadState::do_oop_evac(T* p) { return; } - markWord m = obj->mark_raw(); + markWord m = obj->mark(); if (m.is_marked()) { obj = (oop) m.decode_pointer(); } else { @@ -485,15 +485,15 @@ oop G1ParScanThreadState::do_copy_to_survivor_space(G1HeapRegionAttr const regio // In this case, we have to install the mark word first, // otherwise obj looks to be forwarded (the old mark word, // which contains the forward pointer, was copied) - obj->set_mark_raw(old_mark); + obj->set_mark(old_mark); markWord new_mark = old_mark.displaced_mark_helper().set_age(age); old_mark.set_displaced_mark_helper(new_mark); } else { - obj->set_mark_raw(old_mark.set_age(age)); + obj->set_mark(old_mark.set_age(age)); } _age_table.add(age, word_sz); } else { - obj->set_mark_raw(old_mark); + obj->set_mark(old_mark); } // Most objects are not arrays, so do one array check rather than diff --git a/src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp b/src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp index 1d38e0c01b4a1..979db9e2870b8 100644 --- a/src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp +++ b/src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp @@ -133,7 +133,7 @@ inline void follow_array_specialized(objArrayOop obj, int index, ParCompactionMa const size_t stride = MIN2(len - beg_index, (size_t)ObjArrayMarkingStride); const size_t end_index = beg_index + stride; - T* const base = (T*)obj->base_raw(); + T* const base = (T*)obj->base(); T* const beg = base + beg_index; T* const end = base + end_index; diff --git a/src/hotspot/share/gc/parallel/psPromotionLAB.cpp b/src/hotspot/share/gc/parallel/psPromotionLAB.cpp index cc21fa340a0f0..f119084cd1c36 100644 --- a/src/hotspot/share/gc/parallel/psPromotionLAB.cpp +++ b/src/hotspot/share/gc/parallel/psPromotionLAB.cpp @@ -83,7 +83,7 @@ void PSPromotionLAB::flush() { // so they can always fill with an array. HeapWord* tlab_end = end() + filler_header_size; typeArrayOop filler_oop = (typeArrayOop) top(); - filler_oop->set_mark_raw(markWord::prototype()); + filler_oop->set_mark(markWord::prototype()); filler_oop->set_klass(Universe::intArrayKlassObj()); const size_t array_length = pointer_delta(tlab_end, top()) - typeArrayOopDesc::header_size(T_INT); diff --git a/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp b/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp index 9280d41fa007c..3dc587da9e089 100644 --- a/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp +++ b/src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp @@ -53,7 +53,7 @@ inline void PSPromotionManager::claim_or_forward_depth(T* p) { assert(should_scavenge(p, true), "revisiting object?"); assert(ParallelScavengeHeap::heap()->is_in(p), "pointer outside heap"); oop obj = RawAccess::oop_load(p); - Prefetch::write(obj->mark_addr_raw(), 0); + Prefetch::write(obj->mark_addr(), 0); push_depth(ScannerTask(p)); } @@ -141,7 +141,7 @@ inline oop PSPromotionManager::copy_to_survivor_space(oop o) { // NOTE! We must be very careful with any methods that access the mark // in o. There may be multiple threads racing on it, and it may be forwarded // at any time. Do not use oop methods for accessing the mark! - markWord test_mark = o->mark_raw(); + markWord test_mark = o->mark(); // The same test as "o->is_forwarded()" if (!test_mark.is_marked()) { diff --git a/src/hotspot/share/gc/serial/defNewGeneration.cpp b/src/hotspot/share/gc/serial/defNewGeneration.cpp index 83a5e1f641212..4234adbc091e2 100644 --- a/src/hotspot/share/gc/serial/defNewGeneration.cpp +++ b/src/hotspot/share/gc/serial/defNewGeneration.cpp @@ -693,7 +693,7 @@ void DefNewGeneration::handle_promotion_failure(oop old) { _promotion_failed = true; _promotion_failed_info.register_copy_failure(old->size()); - _preserved_marks_set.get()->push_if_necessary(old, old->mark_raw()); + _preserved_marks_set.get()->push_if_necessary(old, old->mark()); // forward to self old->forward_to(old); diff --git a/src/hotspot/share/gc/serial/markSweep.cpp b/src/hotspot/share/gc/serial/markSweep.cpp index ebe0da2576647..5ed5df58a5c6e 100644 --- a/src/hotspot/share/gc/serial/markSweep.cpp +++ b/src/hotspot/share/gc/serial/markSweep.cpp @@ -132,7 +132,7 @@ template inline void MarkSweep::follow_root(T* p) { T heap_oop = RawAccess<>::oop_load(p); if (!CompressedOops::is_null(heap_oop)) { oop obj = CompressedOops::decode_not_null(heap_oop); - if (!obj->mark_raw().is_marked()) { + if (!obj->mark().is_marked()) { mark_object(obj); follow_object(obj); } @@ -148,7 +148,7 @@ void PreservedMark::adjust_pointer() { } void PreservedMark::restore() { - _obj->set_mark_raw(_mark); + _obj->set_mark(_mark); } // We preserve the mark which should be replaced at the end and the location @@ -205,7 +205,7 @@ void MarkSweep::restore_marks() { while (!_preserved_oop_stack.is_empty()) { oop obj = _preserved_oop_stack.pop(); markWord mark = _preserved_mark_stack.pop(); - obj->set_mark_raw(mark); + obj->set_mark(mark); } } diff --git a/src/hotspot/share/gc/serial/markSweep.inline.hpp b/src/hotspot/share/gc/serial/markSweep.inline.hpp index a207f16c1180d..4b3875f754c31 100644 --- a/src/hotspot/share/gc/serial/markSweep.inline.hpp +++ b/src/hotspot/share/gc/serial/markSweep.inline.hpp @@ -38,8 +38,8 @@ inline void MarkSweep::mark_object(oop obj) { // some marks may contain information we need to preserve so we store them away // and overwrite the mark. We'll restore it at the end of markSweep. - markWord mark = obj->mark_raw(); - obj->set_mark_raw(markWord::prototype().set_marked()); + markWord mark = obj->mark(); + obj->set_mark(markWord::prototype().set_marked()); if (obj->mark_must_be_preserved(mark)) { preserve_mark(obj, mark); @@ -50,7 +50,7 @@ template inline void MarkSweep::mark_and_push(T* p) { T heap_oop = RawAccess<>::oop_load(p); if (!CompressedOops::is_null(heap_oop)) { oop obj = CompressedOops::decode_not_null(heap_oop); - if (!obj->mark_raw().is_marked()) { + if (!obj->mark().is_marked()) { mark_object(obj); _marking_stack.push(obj); } @@ -79,11 +79,11 @@ template inline void MarkSweep::adjust_pointer(T* p) { oop obj = CompressedOops::decode_not_null(heap_oop); assert(Universe::heap()->is_in(obj), "should be in heap"); - oop new_obj = oop(obj->mark_raw().decode_pointer()); + oop new_obj = oop(obj->mark().decode_pointer()); - assert(new_obj != NULL || // is forwarding ptr? - obj->mark_raw() == markWord::prototype() || // not gc marked? - (UseBiasedLocking && obj->mark_raw().has_bias_pattern()), + assert(new_obj != NULL || // is forwarding ptr? + obj->mark() == markWord::prototype() || // not gc marked? + (UseBiasedLocking && obj->mark().has_bias_pattern()), // not gc marked? "should be forwarded"); diff --git a/src/hotspot/share/gc/shared/barrierSetConfig.hpp b/src/hotspot/share/gc/shared/barrierSetConfig.hpp index 8ede0fa990eaf..e20e9ef6f7cbd 100644 --- a/src/hotspot/share/gc/shared/barrierSetConfig.hpp +++ b/src/hotspot/share/gc/shared/barrierSetConfig.hpp @@ -43,20 +43,4 @@ FOR_EACH_ABSTRACT_BARRIER_SET_DO(f) \ FOR_EACH_CONCRETE_BARRIER_SET_DO(f) -// To enable runtime-resolution of GC barriers on primitives, please -// define SUPPORT_BARRIER_ON_PRIMITIVES. -#ifdef SUPPORT_BARRIER_ON_PRIMITIVES -#define ACCESS_PRIMITIVE_SUPPORT INTERNAL_BT_BARRIER_ON_PRIMITIVES -#else -#define ACCESS_PRIMITIVE_SUPPORT DECORATORS_NONE -#endif - -#ifdef SUPPORT_NOT_TO_SPACE_INVARIANT -#define ACCESS_TO_SPACE_INVARIANT_SUPPORT DECORATORS_NONE -#else -#define ACCESS_TO_SPACE_INVARIANT_SUPPORT INTERNAL_BT_TO_SPACE_INVARIANT -#endif - -#define BT_BUILDTIME_DECORATORS (ACCESS_PRIMITIVE_SUPPORT | ACCESS_TO_SPACE_INVARIANT_SUPPORT) - #endif // SHARE_GC_SHARED_BARRIERSETCONFIG_HPP diff --git a/src/hotspot/share/gc/shared/memAllocator.cpp b/src/hotspot/share/gc/shared/memAllocator.cpp index b41d27f541a65..f35a29334c529 100644 --- a/src/hotspot/share/gc/shared/memAllocator.cpp +++ b/src/hotspot/share/gc/shared/memAllocator.cpp @@ -383,10 +383,10 @@ void MemAllocator::mem_clear(HeapWord* mem) const { oop MemAllocator::finish(HeapWord* mem) const { assert(mem != NULL, "NULL object pointer"); if (UseBiasedLocking) { - oopDesc::set_mark_raw(mem, _klass->prototype_header()); + oopDesc::set_mark(mem, _klass->prototype_header()); } else { // May be bootstrapping - oopDesc::set_mark_raw(mem, markWord::prototype()); + oopDesc::set_mark(mem, markWord::prototype()); } // Need a release store to ensure array/class length, mark word, and // object zeroing are visible before setting the klass non-NULL, for diff --git a/src/hotspot/share/gc/shared/preservedMarks.inline.hpp b/src/hotspot/share/gc/shared/preservedMarks.inline.hpp index c7dfb51e366b9..82df737a7b871 100644 --- a/src/hotspot/share/gc/shared/preservedMarks.inline.hpp +++ b/src/hotspot/share/gc/shared/preservedMarks.inline.hpp @@ -47,7 +47,7 @@ inline void PreservedMarks::push_if_necessary(oop obj, markWord m) { } inline void PreservedMarks::init_forwarded_mark(oop obj) { - obj->init_mark_raw(); + obj->init_mark(); } inline PreservedMarks::PreservedMarks() @@ -59,7 +59,7 @@ inline PreservedMarks::PreservedMarks() 0 /* max_cache_size */) { } void PreservedMarks::OopAndMarkWord::set_mark() const { - _o->set_mark_raw(_m); + _o->set_mark(_m); } #endif // SHARE_GC_SHARED_PRESERVEDMARKS_INLINE_HPP diff --git a/src/hotspot/share/gc/shared/space.cpp b/src/hotspot/share/gc/shared/space.cpp index 6e215c8e6b7bf..c267f1c0c3e08 100644 --- a/src/hotspot/share/gc/shared/space.cpp +++ b/src/hotspot/share/gc/shared/space.cpp @@ -379,7 +379,7 @@ HeapWord* CompactibleSpace::forward(oop q, size_t size, } else { // if the object isn't moving we can just set the mark to the default // mark and handle it specially later on. - q->init_mark_raw(); + q->init_mark(); assert(q->forwardee() == NULL, "should be forwarded to NULL"); } @@ -617,14 +617,14 @@ void ContiguousSpace::allocate_temporary_filler(int factor) { // allocate uninitialized int array typeArrayOop t = (typeArrayOop) allocate(size); assert(t != NULL, "allocation should succeed"); - t->set_mark_raw(markWord::prototype()); + t->set_mark(markWord::prototype()); t->set_klass(Universe::intArrayKlassObj()); t->set_length((int)length); } else { assert(size == CollectedHeap::min_fill_size(), "size for smallest fake object doesn't match"); instanceOop obj = (instanceOop) allocate(size); - obj->set_mark_raw(markWord::prototype()); + obj->set_mark(markWord::prototype()); obj->set_klass_gap(0); obj->set_klass(SystemDictionary::Object_klass()); } diff --git a/src/hotspot/share/gc/shared/space.inline.hpp b/src/hotspot/share/gc/shared/space.inline.hpp index 9cfb1418ccef5..e7d9e025ec922 100644 --- a/src/hotspot/share/gc/shared/space.inline.hpp +++ b/src/hotspot/share/gc/shared/space.inline.hpp @@ -117,7 +117,7 @@ class DeadSpacer : StackObj { _allowed_deadspace_words -= dead_length; CollectedHeap::fill_with_object(dead_start, dead_length); oop obj = oop(dead_start); - obj->set_mark_raw(obj->mark_raw().set_marked()); + obj->set_mark(obj->mark().set_marked()); assert(dead_length == (size_t)obj->size(), "bad filler object size"); log_develop_trace(gc, compaction)("Inserting object to dead space: " PTR_FORMAT ", " PTR_FORMAT ", " SIZE_FORMAT "b", @@ -336,7 +336,7 @@ inline void CompactibleSpace::scan_and_compact(SpaceType* space) { // copy object and reinit its mark assert(cur_obj != compaction_top, "everything in this pass should be moving"); Copy::aligned_conjoint_words(cur_obj, compaction_top, size); - oop(compaction_top)->init_mark_raw(); + oop(compaction_top)->init_mark(); assert(oop(compaction_top)->klass() != NULL, "should have a class"); debug_only(prev_obj = cur_obj); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp index 85daeeb8df117..e271dfb1f2fe5 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahForwarding.inline.hpp @@ -40,7 +40,7 @@ inline HeapWord* ShenandoahForwarding::get_forwardee_raw_unchecked(oop obj) { // On this path, we can encounter the "marked" object, but with NULL // fwdptr. That object is still not forwarded, and we need to return // the object itself. - markWord mark = obj->mark_raw(); + markWord mark = obj->mark(); if (mark.is_marked()) { HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer(); if (fwdptr != NULL) { @@ -55,7 +55,7 @@ inline oop ShenandoahForwarding::get_forwardee_mutator(oop obj) { shenandoah_assert_correct(NULL, obj); assert(Thread::current()->is_Java_thread(), "Must be a mutator thread"); - markWord mark = obj->mark_raw(); + markWord mark = obj->mark(); if (mark.is_marked()) { HeapWord* fwdptr = (HeapWord*) mark.clear_lock_bits().to_pointer(); assert(fwdptr != NULL, "Forwarding pointer is never null here"); @@ -71,17 +71,17 @@ inline oop ShenandoahForwarding::get_forwardee(oop obj) { } inline bool ShenandoahForwarding::is_forwarded(oop obj) { - return obj->mark_raw().is_marked(); + return obj->mark().is_marked(); } inline oop ShenandoahForwarding::try_update_forwardee(oop obj, oop update) { - markWord old_mark = obj->mark_raw(); + markWord old_mark = obj->mark(); if (old_mark.is_marked()) { return oop(old_mark.clear_lock_bits().to_pointer()); } markWord new_mark = markWord::encode_pointer_as_mark(update); - markWord prev_mark = obj->cas_set_mark_raw(new_mark, old_mark); + markWord prev_mark = obj->cas_set_mark(new_mark, old_mark, memory_order_conservative); if (prev_mark == old_mark) { return update; } else { diff --git a/src/hotspot/share/gc/shenandoah/shenandoahMarkCompact.cpp b/src/hotspot/share/gc/shenandoah/shenandoahMarkCompact.cpp index 3b5bfb66931f7..9993a9c612b86 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahMarkCompact.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahMarkCompact.cpp @@ -323,7 +323,7 @@ class ShenandoahPrepareForCompactionObjectClosure : public ObjectClosure { // Object fits into current region, record new location: assert(_compact_point + obj_size <= _to_region->end(), "must fit"); shenandoah_assert_not_forwarded(NULL, p); - _preserved_marks->push_if_necessary(p, p->mark_raw()); + _preserved_marks->push_if_necessary(p, p->mark()); p->forward_to(oop(_compact_point)); _compact_point += obj_size; } @@ -431,7 +431,7 @@ void ShenandoahMarkCompact::calculate_target_humongous_objects() { if (start >= to_begin && start != r->index()) { // Fits into current window, and the move is non-trivial. Record the move then, and continue scan. - _preserved_marks->get(0)->push_if_necessary(old_obj, old_obj->mark_raw()); + _preserved_marks->get(0)->push_if_necessary(old_obj, old_obj->mark()); old_obj->forward_to(oop(heap->get_region(start)->bottom())); to_end = start; continue; @@ -806,7 +806,7 @@ class ShenandoahCompactObjectsClosure : public ObjectClosure { HeapWord* compact_to = cast_from_oop(p->forwardee()); Copy::aligned_conjoint_words(compact_from, compact_to, size); oop new_obj = oop(compact_to); - new_obj->init_mark_raw(); + new_obj->init_mark(); } } }; @@ -922,7 +922,7 @@ void ShenandoahMarkCompact::compact_humongous_objects() { ShenandoahHeapRegion::region_size_words()*num_regions); oop new_obj = oop(heap->get_region(new_start)->bottom()); - new_obj->init_mark_raw(); + new_obj->init_mark(); { for (size_t c = old_start; c <= old_end; c++) { diff --git a/src/hotspot/share/memory/heapShared.cpp b/src/hotspot/share/memory/heapShared.cpp index 905d1aef56c92..b84c8033af4c2 100644 --- a/src/hotspot/share/memory/heapShared.cpp +++ b/src/hotspot/share/memory/heapShared.cpp @@ -192,7 +192,7 @@ oop HeapShared::archive_heap_object(oop obj, Thread* THREAD) { // identity_hash for all shared objects, so they are less likely to be written // into during run time, increasing the potential of memory sharing. int hash_original = obj->identity_hash(); - archived_oop->set_mark_raw(markWord::prototype().copy_set_hash(hash_original)); + archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original)); assert(archived_oop->mark().is_unlocked(), "sanity"); DEBUG_ONLY(int hash_archived = archived_oop->identity_hash()); diff --git a/src/hotspot/share/oops/access.hpp b/src/hotspot/share/oops/access.hpp index 3e516d38e9d6f..ac4a7ed169f5f 100644 --- a/src/hotspot/share/oops/access.hpp +++ b/src/hotspot/share/oops/access.hpp @@ -269,11 +269,6 @@ class Access: public AllStatic { OopType new_oop_value = new_value; return AccessInternal::atomic_xchg(addr, new_oop_value); } - - static oop resolve(oop obj) { - verify_decorators(); - return AccessInternal::resolve(obj); - } }; // Helper for performing raw accesses (knows only of memory ordering diff --git a/src/hotspot/share/oops/accessBackend.hpp b/src/hotspot/share/oops/accessBackend.hpp index c1ffb73667ee0..de68ca9b2c8b4 100644 --- a/src/hotspot/share/oops/accessBackend.hpp +++ b/src/hotspot/share/oops/accessBackend.hpp @@ -649,8 +649,7 @@ namespace AccessInternal { template static bool is_hardwired_primitive() { - return !HasDecorator::value && - !HasDecorator::value; + return !HasDecorator::value; } template @@ -946,21 +945,6 @@ namespace AccessInternal { clone(oop src, oop dst, size_t size) { RuntimeDispatch::clone(src, dst, size); } - - template - inline static typename EnableIf< - HasDecorator::value, oop>::type - resolve(oop obj) { - typedef RawAccessBarrier Raw; - return Raw::resolve(obj); - } - - template - inline static typename EnableIf< - !HasDecorator::value, oop>::type - resolve(oop obj) { - return RuntimeDispatch::resolve(obj); - } }; // Step 2: Reduce types. @@ -1253,12 +1237,6 @@ namespace AccessInternal { PreRuntimeDispatch::clone(src, dst, size); } - template - inline oop resolve(oop obj) { - const DecoratorSet expanded_decorators = DecoratorFixup::value; - return PreRuntimeDispatch::resolve(obj); - } - // Infer the type that should be returned from an Access::oop_load. template class OopLoadProxy: public StackObj { diff --git a/src/hotspot/share/oops/accessBackend.inline.hpp b/src/hotspot/share/oops/accessBackend.inline.hpp index 9b3e9c81e5ffd..e28b4c228120e 100644 --- a/src/hotspot/share/oops/accessBackend.inline.hpp +++ b/src/hotspot/share/oops/accessBackend.inline.hpp @@ -362,7 +362,7 @@ inline void RawAccessBarrier::clone(oop src, oop dst, size_t size) { reinterpret_cast((oopDesc*)dst), align_object_size(size) / HeapWordsPerLong); // Clear the header - dst->init_mark_raw(); + dst->init_mark(); } #endif // SHARE_OOPS_ACCESSBACKEND_INLINE_HPP diff --git a/src/hotspot/share/oops/accessDecorators.hpp b/src/hotspot/share/oops/accessDecorators.hpp index 34f33c3d35273..21bcff9113d31 100644 --- a/src/hotspot/share/oops/accessDecorators.hpp +++ b/src/hotspot/share/oops/accessDecorators.hpp @@ -54,20 +54,13 @@ const DecoratorSet DECORATORS_NONE = UCONST64(0); const DecoratorSet INTERNAL_CONVERT_COMPRESSED_OOP = UCONST64(1) << 1; const DecoratorSet INTERNAL_VALUE_IS_OOP = UCONST64(1) << 2; -// == Internal build-time Decorators == -// * INTERNAL_BT_BARRIER_ON_PRIMITIVES: This is set in the barrierSetConfig.hpp file. -// * INTERNAL_BT_TO_SPACE_INVARIANT: This is set in the barrierSetConfig.hpp file iff -// no GC is bundled in the build that is to-space invariant. -const DecoratorSet INTERNAL_BT_BARRIER_ON_PRIMITIVES = UCONST64(1) << 3; -const DecoratorSet INTERNAL_BT_TO_SPACE_INVARIANT = UCONST64(1) << 4; - // == Internal run-time Decorators == // * INTERNAL_RT_USE_COMPRESSED_OOPS: This decorator will be set in runtime resolved // access backends iff UseCompressedOops is true. const DecoratorSet INTERNAL_RT_USE_COMPRESSED_OOPS = UCONST64(1) << 5; const DecoratorSet INTERNAL_DECORATOR_MASK = INTERNAL_CONVERT_COMPRESSED_OOP | INTERNAL_VALUE_IS_OOP | - INTERNAL_BT_BARRIER_ON_PRIMITIVES | INTERNAL_RT_USE_COMPRESSED_OOPS; + INTERNAL_RT_USE_COMPRESSED_OOPS; // == Memory Ordering Decorators == // The memory ordering decorators can be described in the following way: @@ -238,7 +231,7 @@ namespace AccessInternal { // If no barrier strength has been picked, normal will be used static const DecoratorSet barrier_strength_default = memory_ordering_default | ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : DECORATORS_NONE); - static const DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS; + static const DecoratorSet value = barrier_strength_default; }; // This function implements the above DecoratorFixup rules, but without meta @@ -254,8 +247,7 @@ namespace AccessInternal { // If no barrier strength has been picked, normal will be used DecoratorSet barrier_strength_default = memory_ordering_default | ((AS_DECORATOR_MASK & memory_ordering_default) == 0 ? AS_NORMAL : DECORATORS_NONE); - DecoratorSet value = barrier_strength_default | BT_BUILDTIME_DECORATORS; - return value; + return barrier_strength_default; } } diff --git a/src/hotspot/share/oops/arrayOop.hpp b/src/hotspot/share/oops/arrayOop.hpp index 42dc7b0ab51d2..a87a7e6c4cce9 100644 --- a/src/hotspot/share/oops/arrayOop.hpp +++ b/src/hotspot/share/oops/arrayOop.hpp @@ -91,7 +91,6 @@ class arrayOopDesc : public oopDesc { // Returns the address of the first element. The elements in the array will not // relocate from this address until a subsequent thread transition. inline void* base(BasicType type) const; - inline void* base_raw(BasicType type) const; // GC barrier invariant template static T* obj_offset_to_raw(arrayOop obj, size_t offset_in_bytes, T* raw) { diff --git a/src/hotspot/share/oops/arrayOop.inline.hpp b/src/hotspot/share/oops/arrayOop.inline.hpp index 7db448c42411e..7b9aad1a2fbdb 100644 --- a/src/hotspot/share/oops/arrayOop.inline.hpp +++ b/src/hotspot/share/oops/arrayOop.inline.hpp @@ -29,11 +29,6 @@ #include "oops/arrayOop.hpp" void* arrayOopDesc::base(BasicType type) const { - oop resolved_obj = Access<>::resolve(as_oop()); - return arrayOop(resolved_obj)->base_raw(type); -} - -void* arrayOopDesc::base_raw(BasicType type) const { return reinterpret_cast(cast_from_oop(as_oop()) + base_offset_in_bytes(type)); } diff --git a/src/hotspot/share/oops/instanceKlass.inline.hpp b/src/hotspot/share/oops/instanceKlass.inline.hpp index 6026a3a7d0a80..69d50bf251d74 100644 --- a/src/hotspot/share/oops/instanceKlass.inline.hpp +++ b/src/hotspot/share/oops/instanceKlass.inline.hpp @@ -57,7 +57,7 @@ inline void InstanceKlass::release_set_methods_jmethod_ids(jmethodID* jmeths) { template ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure) { - T* p = (T*)obj->obj_field_addr_raw(map->offset()); + T* p = (T*)obj->obj_field_addr(map->offset()); T* const end = p + map->count(); for (; p < end; ++p) { @@ -67,7 +67,7 @@ ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop o template ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_reverse(OopMapBlock* map, oop obj, OopClosureType* closure) { - T* const start = (T*)obj->obj_field_addr_raw(map->offset()); + T* const start = (T*)obj->obj_field_addr(map->offset()); T* p = start + map->count(); while (start < p) { @@ -78,7 +78,7 @@ ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_reverse(OopMapBlock* ma template ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_bounded(OopMapBlock* map, oop obj, OopClosureType* closure, MemRegion mr) { - T* p = (T*)obj->obj_field_addr_raw(map->offset()); + T* p = (T*)obj->obj_field_addr(map->offset()); T* end = p + map->count(); T* const l = (T*)mr.start(); diff --git a/src/hotspot/share/oops/objArrayKlass.cpp b/src/hotspot/share/oops/objArrayKlass.cpp index 9268cb789f392..6c218d98e95fe 100644 --- a/src/hotspot/share/oops/objArrayKlass.cpp +++ b/src/hotspot/share/oops/objArrayKlass.cpp @@ -294,17 +294,17 @@ void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset(src_pos); size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset(dst_pos); assert(arrayOopDesc::obj_offset_to_raw(s, src_offset, NULL) == - objArrayOop(s)->obj_at_addr_raw(src_pos), "sanity"); + objArrayOop(s)->obj_at_addr(src_pos), "sanity"); assert(arrayOopDesc::obj_offset_to_raw(d, dst_offset, NULL) == - objArrayOop(d)->obj_at_addr_raw(dst_pos), "sanity"); + objArrayOop(d)->obj_at_addr(dst_pos), "sanity"); do_copy(s, src_offset, d, dst_offset, length, CHECK); } else { size_t src_offset = (size_t) objArrayOopDesc::obj_at_offset(src_pos); size_t dst_offset = (size_t) objArrayOopDesc::obj_at_offset(dst_pos); assert(arrayOopDesc::obj_offset_to_raw(s, src_offset, NULL) == - objArrayOop(s)->obj_at_addr_raw(src_pos), "sanity"); + objArrayOop(s)->obj_at_addr(src_pos), "sanity"); assert(arrayOopDesc::obj_offset_to_raw(d, dst_offset, NULL) == - objArrayOop(d)->obj_at_addr_raw(dst_pos), "sanity"); + objArrayOop(d)->obj_at_addr(dst_pos), "sanity"); do_copy(s, src_offset, d, dst_offset, length, CHECK); } } diff --git a/src/hotspot/share/oops/objArrayKlass.inline.hpp b/src/hotspot/share/oops/objArrayKlass.inline.hpp index 6943aea468a40..fb25fd3de8029 100644 --- a/src/hotspot/share/oops/objArrayKlass.inline.hpp +++ b/src/hotspot/share/oops/objArrayKlass.inline.hpp @@ -37,7 +37,7 @@ template void ObjArrayKlass::oop_oop_iterate_elements(objArrayOop a, OopClosureType* closure) { - T* p = (T*)a->base_raw(); + T* p = (T*)a->base(); T* const end = p + a->length(); for (;p < end; p++) { @@ -52,7 +52,7 @@ void ObjArrayKlass::oop_oop_iterate_elements_bounded( T* const l = (T*)low; T* const h = (T*)high; - T* p = (T*)a->base_raw(); + T* p = (T*)a->base(); T* end = p + a->length(); if (p < l) { @@ -101,8 +101,8 @@ void ObjArrayKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, Me // for objArrayOops. template void ObjArrayKlass::oop_oop_iterate_range(objArrayOop a, OopClosureType* closure, int start, int end) { - T* low = (T*)a->base_raw() + start; - T* high = (T*)a->base_raw() + end; + T* low = (T*)a->base() + start; + T* high = (T*)a->base() + end; oop_oop_iterate_elements_bounded(a, closure, low, high); } diff --git a/src/hotspot/share/oops/objArrayOop.hpp b/src/hotspot/share/oops/objArrayOop.hpp index 07f89a6df3c72..5952c058ef582 100644 --- a/src/hotspot/share/oops/objArrayOop.hpp +++ b/src/hotspot/share/oops/objArrayOop.hpp @@ -40,7 +40,6 @@ class objArrayOopDesc : public arrayOopDesc { friend class CSetMarkWordClosure; template T* obj_at_addr(int index) const; - template T* obj_at_addr_raw(int index) const; template static ptrdiff_t obj_at_offset(int index) { @@ -81,7 +80,6 @@ class objArrayOopDesc : public arrayOopDesc { // base is the address following the header. HeapWord* base() const; - HeapWord* base_raw() const; // Accessing oop obj_at(int index) const; diff --git a/src/hotspot/share/oops/objArrayOop.inline.hpp b/src/hotspot/share/oops/objArrayOop.inline.hpp index 5862edcc48c83..4a9e9540c4c39 100644 --- a/src/hotspot/share/oops/objArrayOop.inline.hpp +++ b/src/hotspot/share/oops/objArrayOop.inline.hpp @@ -32,18 +32,12 @@ #include "runtime/globals.hpp" inline HeapWord* objArrayOopDesc::base() const { return (HeapWord*) arrayOopDesc::base(T_OBJECT); } -inline HeapWord* objArrayOopDesc::base_raw() const { return (HeapWord*) arrayOopDesc::base_raw(T_OBJECT); } template T* objArrayOopDesc::obj_at_addr(int index) const { assert(is_within_bounds(index), "index %d out of bounds %d", index, length()); return &((T*)base())[index]; } -template T* objArrayOopDesc::obj_at_addr_raw(int index) const { - assert(is_within_bounds(index), "index %d out of bounds %d", index, length()); - return &((T*)base_raw())[index]; -} - inline oop objArrayOopDesc::obj_at(int index) const { assert(is_within_bounds(index), "index %d out of bounds %d", index, length()); ptrdiff_t offset = UseCompressedOops ? obj_at_offset(index) : obj_at_offset(index); diff --git a/src/hotspot/share/oops/oop.cpp b/src/hotspot/share/oops/oop.cpp index 9ed805ba94406..c7e1a02de8a8a 100644 --- a/src/hotspot/share/oops/oop.cpp +++ b/src/hotspot/share/oops/oop.cpp @@ -111,7 +111,7 @@ bool oopDesc::is_oop(oop obj, bool ignore_mark_word) { if (ignore_mark_word) { return true; } - if (obj->mark_raw().value() != 0) { + if (obj->mark().value() != 0) { return true; } return !SafepointSynchronize::is_at_safepoint(); diff --git a/src/hotspot/share/oops/oop.hpp b/src/hotspot/share/oops/oop.hpp index 2cdf9227d48d6..926556d73d699 100644 --- a/src/hotspot/share/oops/oop.hpp +++ b/src/hotspot/share/oops/oop.hpp @@ -59,21 +59,18 @@ class oopDesc { public: inline markWord mark() const; - inline markWord mark_raw() const; - inline markWord* mark_addr_raw() const; + inline markWord* mark_addr() const; inline void set_mark(markWord m); - inline void set_mark_raw(markWord m); - static inline void set_mark_raw(HeapWord* mem, markWord m); + static inline void set_mark(HeapWord* mem, markWord m); inline void release_set_mark(markWord m); inline markWord cas_set_mark(markWord new_mark, markWord old_mark); - inline markWord cas_set_mark_raw(markWord new_mark, markWord old_mark, atomic_memory_order order = memory_order_conservative); + inline markWord cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order); // Used only to re-initialize the mark word (e.g., of promoted // objects during a GC) -- requires a valid klass pointer inline void init_mark(); - inline void init_mark_raw(); inline Klass* klass() const; inline Klass* klass_or_null() const; @@ -117,11 +114,10 @@ class oopDesc { public: // field addresses in oop - inline void* field_addr(int offset) const; - inline void* field_addr_raw(int offset) const; + inline void* field_addr(int offset) const; // Need this as public for garbage collection. - template inline T* obj_field_addr_raw(int offset) const; + template inline T* obj_field_addr(int offset) const; template inline size_t field_offset(T* p) const; @@ -237,7 +233,6 @@ class oopDesc { inline bool is_locked() const; inline bool is_unlocked() const; inline bool has_bias_pattern() const; - inline bool has_bias_pattern_raw() const; // asserts and guarantees static bool is_oop(oop obj, bool ignore_mark_word = false); @@ -291,9 +286,9 @@ class oopDesc { intptr_t slow_identity_hash(); // marks are forwarded to stack when object is locked - inline bool has_displaced_mark_raw() const; - inline markWord displaced_mark_raw() const; - inline void set_displaced_mark_raw(markWord m); + inline bool has_displaced_mark() const; + inline markWord displaced_mark() const; + inline void set_displaced_mark(markWord m); // Checks if the mark word needs to be preserved inline bool mark_must_be_preserved() const; diff --git a/src/hotspot/share/oops/oop.inline.hpp b/src/hotspot/share/oops/oop.inline.hpp index a88cf0f0cab01..a2f7c9edd9def 100644 --- a/src/hotspot/share/oops/oop.inline.hpp +++ b/src/hotspot/share/oops/oop.inline.hpp @@ -47,11 +47,7 @@ markWord oopDesc::mark() const { return markWord(v); } -markWord oopDesc::mark_raw() const { - return Atomic::load(&_mark); -} - -markWord* oopDesc::mark_addr_raw() const { +markWord* oopDesc::mark_addr() const { return (markWord*) &_mark; } @@ -59,11 +55,7 @@ void oopDesc::set_mark(markWord m) { HeapAccess::store_at(as_oop(), mark_offset_in_bytes(), m.value()); } -void oopDesc::set_mark_raw(markWord m) { - Atomic::store(&_mark, m); -} - -void oopDesc::set_mark_raw(HeapWord* mem, markWord m) { +void oopDesc::set_mark(HeapWord* mem, markWord m) { *(markWord*)(((char*)mem) + mark_offset_in_bytes()) = m; } @@ -76,7 +68,7 @@ markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark) { return markWord(v); } -markWord oopDesc::cas_set_mark_raw(markWord new_mark, markWord old_mark, atomic_memory_order order) { +markWord oopDesc::cas_set_mark(markWord new_mark, markWord old_mark, atomic_memory_order order) { return Atomic::cmpxchg(&_mark, old_mark, new_mark, order); } @@ -84,10 +76,6 @@ void oopDesc::init_mark() { set_mark(markWord::prototype_for_klass(klass())); } -void oopDesc::init_mark_raw() { - set_mark_raw(markWord::prototype_for_klass(klass())); -} - Klass* oopDesc::klass() const { if (UseCompressedClassPointers) { return CompressedKlassPointers::decode_not_null(_metadata._compressed_klass); @@ -216,11 +204,10 @@ bool oopDesc::is_array() const { return klass()->is_array_klass(); } bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); } bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); } -void* oopDesc::field_addr_raw(int offset) const { return reinterpret_cast(cast_from_oop(as_oop()) + offset); } -void* oopDesc::field_addr(int offset) const { return Access<>::resolve(as_oop())->field_addr_raw(offset); } +void* oopDesc::field_addr(int offset) const { return reinterpret_cast(cast_from_oop(as_oop()) + offset); } template -T* oopDesc::obj_field_addr_raw(int offset) const { return (T*) field_addr_raw(offset); } +T* oopDesc::obj_field_addr(int offset) const { return (T*) field_addr(offset); } template size_t oopDesc::field_offset(T* p) const { return pointer_delta((void*)p, (void*)this, 1); } @@ -269,20 +256,16 @@ bool oopDesc::has_bias_pattern() const { return mark().has_bias_pattern(); } -bool oopDesc::has_bias_pattern_raw() const { - return mark_raw().has_bias_pattern(); -} - // Used only for markSweep, scavenging bool oopDesc::is_gc_marked() const { - return mark_raw().is_marked(); + return mark().is_marked(); } // Used by scavengers bool oopDesc::is_forwarded() const { // The extra heap check is needed since the obj might be locked, in which case the // mark would point to a stack location and have the sentinel bit cleared - return mark_raw().is_marked(); + return mark().is_marked(); } // Used by scavengers @@ -290,7 +273,7 @@ void oopDesc::forward_to(oop p) { verify_forwardee(p); markWord m = markWord::encode_pointer_as_mark(p); assert(m.decode_pointer() == p, "encoding must be reversable"); - set_mark_raw(m); + set_mark(m); } // Used by parallel scavengers @@ -298,14 +281,14 @@ bool oopDesc::cas_forward_to(oop p, markWord compare, atomic_memory_order order) verify_forwardee(p); markWord m = markWord::encode_pointer_as_mark(p); assert(m.decode_pointer() == p, "encoding must be reversable"); - return cas_set_mark_raw(m, compare, order) == compare; + return cas_set_mark(m, compare, order) == compare; } oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order order) { verify_forwardee(p); markWord m = markWord::encode_pointer_as_mark(p); assert(m.decode_pointer() == p, "encoding must be reversable"); - markWord old_mark = cas_set_mark_raw(m, compare, order); + markWord old_mark = cas_set_mark(m, compare, order); if (old_mark == compare) { return NULL; } else { @@ -317,7 +300,7 @@ oop oopDesc::forward_to_atomic(oop p, markWord compare, atomic_memory_order orde // The forwardee is used when copying during scavenge and mark-sweep. // It does need to clear the low two locking- and GC-related bits. oop oopDesc::forwardee() const { - return (oop) mark_raw().decode_pointer(); + return (oop) mark().decode_pointer(); } // Note that the forwardee is not the same thing as the displaced_mark. @@ -330,19 +313,19 @@ oop oopDesc::forwardee_acquire() const { // The following method needs to be MT safe. uint oopDesc::age() const { assert(!is_forwarded(), "Attempt to read age from forwarded mark"); - if (has_displaced_mark_raw()) { - return displaced_mark_raw().age(); + if (has_displaced_mark()) { + return displaced_mark().age(); } else { - return mark_raw().age(); + return mark().age(); } } void oopDesc::incr_age() { assert(!is_forwarded(), "Attempt to increment age of forwarded mark"); - if (has_displaced_mark_raw()) { - set_displaced_mark_raw(displaced_mark_raw().incr_age()); + if (has_displaced_mark()) { + set_displaced_mark(displaced_mark().incr_age()); } else { - set_mark_raw(mark_raw().incr_age()); + set_mark(mark().incr_age()); } } @@ -394,16 +377,16 @@ intptr_t oopDesc::identity_hash() { } } -bool oopDesc::has_displaced_mark_raw() const { - return mark_raw().has_displaced_mark_helper(); +bool oopDesc::has_displaced_mark() const { + return mark().has_displaced_mark_helper(); } -markWord oopDesc::displaced_mark_raw() const { - return mark_raw().displaced_mark_helper(); +markWord oopDesc::displaced_mark() const { + return mark().displaced_mark_helper(); } -void oopDesc::set_displaced_mark_raw(markWord m) { - mark_raw().set_displaced_mark_helper(m); +void oopDesc::set_displaced_mark(markWord m) { + mark().set_displaced_mark_helper(m); } // Supports deferred calling of obj->klass(). @@ -420,7 +403,7 @@ class DeferredObjectToKlass { }; bool oopDesc::mark_must_be_preserved() const { - return mark_must_be_preserved(mark_raw()); + return mark_must_be_preserved(mark()); } bool oopDesc::mark_must_be_preserved(markWord m) const { diff --git a/src/hotspot/share/prims/jvmtiTagMap.cpp b/src/hotspot/share/prims/jvmtiTagMap.cpp index a911dc947304e..94f1fcc541ef6 100644 --- a/src/hotspot/share/prims/jvmtiTagMap.cpp +++ b/src/hotspot/share/prims/jvmtiTagMap.cpp @@ -187,8 +187,7 @@ class JvmtiTagHashmap : public CHeapObj { // hash a given key (oop) with the specified size static unsigned int hash(oop key, int size) { - const oop obj = Access<>::resolve(key); - const unsigned int hash = Universe::heap()->hash_oop(obj); + const unsigned int hash = Universe::heap()->hash_oop(key); return hash % size; } diff --git a/src/hotspot/share/prims/unsafe.cpp b/src/hotspot/share/prims/unsafe.cpp index fd56d5931794e..fc8ea88313061 100644 --- a/src/hotspot/share/prims/unsafe.cpp +++ b/src/hotspot/share/prims/unsafe.cpp @@ -115,8 +115,8 @@ static inline void assert_field_offset_sane(oop p, jlong field_offset) { assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); if (byte_offset == (jint)byte_offset) { void* ptr_plus_disp = cast_from_oop
        (p) + byte_offset; - assert(p->field_addr_raw((jint)byte_offset) == ptr_plus_disp, - "raw [ptr+disp] must be consistent with oop::field_addr_raw"); + assert(p->field_addr((jint)byte_offset) == ptr_plus_disp, + "raw [ptr+disp] must be consistent with oop::field_addr"); } jlong p_size = HeapWordSize * (jlong)(p->size()); assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, (int64_t)byte_offset, (int64_t)p_size); @@ -128,10 +128,6 @@ static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) assert_field_offset_sane(p, field_offset); jlong byte_offset = field_offset_to_byte_offset(field_offset); - if (p != NULL) { - p = Access<>::resolve(p); - } - if (sizeof(char*) == sizeof(jint)) { // (this constant folds!) return cast_from_oop
        (p) + (jint) byte_offset; } else { diff --git a/test/hotspot/gtest/gc/shared/test_preservedMarks.cpp b/test/hotspot/gtest/gc/shared/test_preservedMarks.cpp index 3f2d7b9a65b65..c5fd1680f5a89 100644 --- a/test/hotspot/gtest/gc/shared/test_preservedMarks.cpp +++ b/test/hotspot/gtest/gc/shared/test_preservedMarks.cpp @@ -39,14 +39,14 @@ class FakeOop { oopDesc _oop; public: - FakeOop() : _oop() { _oop.set_mark_raw(originalMark()); } + FakeOop() : _oop() { _oop.set_mark(originalMark()); } oop get_oop() { return &_oop; } - markWord mark() { return _oop.mark_raw(); } - void set_mark(markWord m) { _oop.set_mark_raw(m); } + markWord mark() { return _oop.mark(); } + void set_mark(markWord m) { _oop.set_mark(m); } void forward_to(oop obj) { markWord m = markWord::encode_pointer_as_mark(obj); - _oop.set_mark_raw(m); + _oop.set_mark(m); } static markWord originalMark() { return markWord(markWord::lock_mask_in_place); } From b65913249f58e4bfbdf383d5e46e3e014c9b1c47 Mon Sep 17 00:00:00 2001 From: John Tortugo Date: Tue, 29 Sep 2020 08:15:41 +0000 Subject: [PATCH 52/79] 8252888: Collapse G1MMUTracker class hierarchy Reviewed-by: ayang, sjohanss, kbarrett --- src/hotspot/share/gc/g1/g1MMUTracker.cpp | 21 +++-- src/hotspot/share/gc/g1/g1MMUTracker.hpp | 98 +++++++++++------------- src/hotspot/share/gc/g1/g1Policy.cpp | 2 +- 3 files changed, 54 insertions(+), 67 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1MMUTracker.cpp b/src/hotspot/share/gc/g1/g1MMUTracker.cpp index 5cd43a590781e..259bff9f65497 100644 --- a/src/hotspot/share/gc/g1/g1MMUTracker.cpp +++ b/src/hotspot/share/gc/g1/g1MMUTracker.cpp @@ -39,15 +39,12 @@ G1MMUTracker::G1MMUTracker(double time_slice, double max_gc_time) : _time_slice(time_slice), - _max_gc_time(max_gc_time) { } - -G1MMUTrackerQueue::G1MMUTrackerQueue(double time_slice, double max_gc_time) : - G1MMUTracker(time_slice, max_gc_time), + _max_gc_time(max_gc_time), _head_index(0), _tail_index(trim_index(_head_index+1)), _no_entries(0) { } -void G1MMUTrackerQueue::remove_expired_entries(double current_time) { +void G1MMUTracker::remove_expired_entries(double current_time) { double limit = current_time - _time_slice; while (_no_entries > 0) { if (is_double_geq(limit, _array[_tail_index].end_time())) { @@ -59,12 +56,12 @@ void G1MMUTrackerQueue::remove_expired_entries(double current_time) { guarantee(_no_entries == 0, "should have no entries in the array"); } -double G1MMUTrackerQueue::calculate_gc_time(double current_time) { +double G1MMUTracker::calculate_gc_time(double current_time) { double gc_time = 0.0; double limit = current_time - _time_slice; for (int i = 0; i < _no_entries; ++i) { int index = trim_index(_tail_index + i); - G1MMUTrackerQueueElem *elem = &_array[index]; + G1MMUTrackerElem *elem = &_array[index]; if (elem->end_time() > limit) { if (elem->start_time() > limit) gc_time += elem->duration(); @@ -75,7 +72,7 @@ double G1MMUTrackerQueue::calculate_gc_time(double current_time) { return gc_time; } -void G1MMUTrackerQueue::add_pause(double start, double end) { +void G1MMUTracker::add_pause(double start, double end) { remove_expired_entries(end); if (_no_entries == QueueLength) { // OK, we've filled up the queue. There are a few ways @@ -99,7 +96,7 @@ void G1MMUTrackerQueue::add_pause(double start, double end) { _head_index = trim_index(_head_index + 1); ++_no_entries; } - _array[_head_index] = G1MMUTrackerQueueElem(start, end); + _array[_head_index] = G1MMUTrackerElem(start, end); // Current entry needs to be added before calculating the value double slice_time = calculate_gc_time(end); @@ -114,7 +111,7 @@ void G1MMUTrackerQueue::add_pause(double start, double end) { } } -double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { +double G1MMUTracker::when_sec(double current_time, double pause_time) { // if the pause is over the maximum, just assume that it's the maximum double adjusted_pause_time = (pause_time > max_gc_time()) ? max_gc_time() : pause_time; @@ -126,13 +123,13 @@ double G1MMUTrackerQueue::when_sec(double current_time, double pause_time) { return 0.0; if (adjusted_pause_time == max_gc_time()) { - G1MMUTrackerQueueElem *elem = &_array[_head_index]; + G1MMUTrackerElem *elem = &_array[_head_index]; return elem->end_time() - limit; } int index = _tail_index; while ( 1 ) { - G1MMUTrackerQueueElem *elem = &_array[index]; + G1MMUTrackerElem *elem = &_array[index]; if (elem->end_time() > limit) { if (elem->start_time() > limit) diff -= elem->duration(); diff --git a/src/hotspot/share/gc/g1/g1MMUTracker.hpp b/src/hotspot/share/gc/g1/g1MMUTracker.hpp index cf35f15dd8784..0b27a89bedd55 100644 --- a/src/hotspot/share/gc/g1/g1MMUTracker.hpp +++ b/src/hotspot/share/gc/g1/g1MMUTracker.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2020, 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,45 +29,7 @@ #include "memory/allocation.hpp" #include "utilities/debug.hpp" -// Two major user controls over G1 behavior are setting a pause time goal (MaxGCPauseMillis), -// over a time slice (GCPauseIntervalMillis). This defines the Minimum Mutator -// Utilisation (MMU) goal. -// -// * Definitions * -// Mutator Utilisation: -// - for a given time slice duration "ts", -// - mutator utilisation is the following fraction: -// non_gc_time / ts -// -// Minimum Mutator Utilisation (MMU): -// - the worst mutator utilisation across all time slices. -// -// G1MMUTracker keeps track of the GC work and decides when it is OK to do GC work -// and for how long so that the MMU invariants are maintained. -// -// ***** ALL TIMES ARE IN SECS!!!!!!! ***** -// this is the "interface" -class G1MMUTracker: public CHeapObj { -protected: - double _time_slice; - double _max_gc_time; // this is per time slice - -public: - G1MMUTracker(double time_slice, double max_gc_time); - - virtual void add_pause(double start, double end) = 0; - virtual double when_sec(double current_time, double pause_time) = 0; - - double max_gc_time() const { - return _max_gc_time; - } - - inline double when_max_gc_sec(double current_time) { - return when_sec(current_time, max_gc_time()); - } -}; - -class G1MMUTrackerQueueElem { +class G1MMUTrackerElem { private: double _start_time; double _end_time; @@ -77,25 +39,45 @@ class G1MMUTrackerQueueElem { inline double end_time() { return _end_time; } inline double duration() { return _end_time - _start_time; } - G1MMUTrackerQueueElem() { + G1MMUTrackerElem() { _start_time = 0.0; _end_time = 0.0; } - G1MMUTrackerQueueElem(double start_time, double end_time) { + G1MMUTrackerElem(double start_time, double end_time) { _start_time = start_time; _end_time = end_time; } }; -// this is an implementation of the MMUTracker using a (fixed-size) queue -// that keeps track of all the recent pause times -class G1MMUTrackerQueue: public G1MMUTracker { + +// Two major user controls over G1 behavior are setting a pause +// time goal (MaxGCPauseMillis), over a time slice (GCPauseIntervalMillis). +// This defines the Minimum Mutator Utilisation (MMU) goal. +// +// * Definitions * +// Mutator Utilisation: +// - for a given time slice duration "ts", +// - mutator utilisation is the following fraction: +// non_gc_time / ts +// +// Minimum Mutator Utilisation (MMU): +// - the worst mutator utilisation across all time slices. +// +// The G1MMUTracker uses a fixed-size queue to keep track of all +// recent pause times. The pause time data is used to avoid +// breaking the MMU. +// +// ***** ALL TIMES ARE IN SECS!!!!!!! ***** +class G1MMUTracker: public CHeapObj { private: enum PrivateConstants { QueueLength = 64 }; + double _time_slice; + double _max_gc_time; // this is per time slice + // The array keeps track of all the pauses that fall within a time // slice (the last time slice during which pauses took place). // The data structure implemented is a circular queue. @@ -105,13 +87,13 @@ class G1MMUTrackerQueue: public G1MMUTracker { // If the array is full, an easy fix is to look for the pauses with // the shortest gap between them and consolidate them. // For now, we have taken the expedient alternative of forgetting - // the oldest entry in the event that +G1UseFixedWindowMMUTracker, thus - // potentially violating MMU specs for some time thereafter. + // the oldest entry, thus potentially violating MMU specs for + // some time thereafter. - G1MMUTrackerQueueElem _array[QueueLength]; - int _head_index; - int _tail_index; - int _no_entries; + G1MMUTrackerElem _array[QueueLength]; + int _head_index; + int _tail_index; + int _no_entries; inline int trim_index(int index) { return (index + QueueLength) % QueueLength; @@ -121,11 +103,19 @@ class G1MMUTrackerQueue: public G1MMUTracker { double calculate_gc_time(double current_time); public: - G1MMUTrackerQueue(double time_slice, double max_gc_time); + G1MMUTracker(double time_slice, double max_gc_time); + + void add_pause(double start, double end); - virtual void add_pause(double start, double end); + double when_sec(double current_time, double pause_time); - virtual double when_sec(double current_time, double pause_time); + double max_gc_time() const { + return _max_gc_time; + } + + double when_max_gc_sec(double current_time) { + return when_sec(current_time, max_gc_time()); + } }; #endif // SHARE_GC_G1_G1MMUTRACKER_HPP diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index cd38cc684b692..1354296cb9bb2 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -56,7 +56,7 @@ G1Policy::G1Policy(STWGCTimer* gc_timer) : _predictor(G1ConfidencePercent / 100.0), _analytics(new G1Analytics(&_predictor)), _remset_tracker(), - _mmu_tracker(new G1MMUTrackerQueue(GCPauseIntervalMillis / 1000.0, MaxGCPauseMillis / 1000.0)), + _mmu_tracker(new G1MMUTracker(GCPauseIntervalMillis / 1000.0, MaxGCPauseMillis / 1000.0)), _old_gen_alloc_tracker(), _ihop_control(create_ihop_control(&_old_gen_alloc_tracker, &_predictor)), _policy_counters(new GCPolicyCounters("GarbageFirst", 1, 2)), From 55c90a171f28b878beeacd24092c7176cd23f51e Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Tue, 29 Sep 2020 08:20:21 +0000 Subject: [PATCH 53/79] 6514600: AbstractAction can throw NullPointerException when clone()d Reviewed-by: serb, pbansal --- .../share/classes/javax/swing/ArrayTable.java | 24 ++++---- .../javax/swing/Action/AbstractActionBug.java | 57 +++++++++++++++++++ 2 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 test/jdk/javax/swing/Action/AbstractActionBug.java diff --git a/src/java.desktop/share/classes/javax/swing/ArrayTable.java b/src/java.desktop/share/classes/javax/swing/ArrayTable.java index 53cf7129582be..7c38f9fb57707 100644 --- a/src/java.desktop/share/classes/javax/swing/ArrayTable.java +++ b/src/java.desktop/share/classes/javax/swing/ArrayTable.java @@ -255,17 +255,19 @@ public void clear() { */ public Object clone() { ArrayTable newArrayTable = new ArrayTable(); - if (isArray()) { - Object[] array = (Object[])table; - for (int i = 0 ;i < array.length-1 ; i+=2) { - newArrayTable.put(array[i], array[i+1]); - } - } else { - Hashtable tmp = (Hashtable)table; - Enumeration keys = tmp.keys(); - while (keys.hasMoreElements()) { - Object o = keys.nextElement(); - newArrayTable.put(o,tmp.get(o)); + if (table != null) { + if (isArray()) { + Object[] array = (Object[]) table; + for (int i = 0; i < array.length - 1; i += 2) { + newArrayTable.put(array[i], array[i + 1]); + } + } else { + Hashtable tmp = (Hashtable) table; + Enumeration keys = tmp.keys(); + while (keys.hasMoreElements()) { + Object o = keys.nextElement(); + newArrayTable.put(o, tmp.get(o)); + } } } return newArrayTable; diff --git a/test/jdk/javax/swing/Action/AbstractActionBug.java b/test/jdk/javax/swing/Action/AbstractActionBug.java new file mode 100644 index 0000000000000..4a25251c726c7 --- /dev/null +++ b/test/jdk/javax/swing/Action/AbstractActionBug.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020, 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 6514600 + @summary Verifies if AbstractAction throws NullPointerException when cloned + @run main AbstractActionBug + */ +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; + +public final class AbstractActionBug extends AbstractAction implements Cloneable +{ + public static final void main(String[] args) throws Exception + { + AbstractActionBug a1 = new AbstractActionBug("a1"); + a1 = (AbstractActionBug) a1.clone(); + System.out.println("a1 cloned ok"); + + AbstractActionBug a2 = new AbstractActionBug("a2"); + a2.putValue(NAME, "null"); + a2 = (AbstractActionBug) a2.clone(); + System.out.println("a2 cloned ok"); + + AbstractActionBug a3 = new AbstractActionBug(null); + a3 = (AbstractActionBug) a3.clone(); + System.out.println("a3 cloned ok"); + } + + private AbstractActionBug(String name) { + putValue(NAME, name); + } + + public void actionPerformed(ActionEvent e) + { + } +} \ No newline at end of file From 6d19fe65d1c1d8f41fd2f18afd09de134912505f Mon Sep 17 00:00:00 2001 From: Per Liden Date: Tue, 29 Sep 2020 08:39:09 +0000 Subject: [PATCH 54/79] 8253763: ParallelObjectIterator should have virtual destructor Reviewed-by: shade, stefank --- src/hotspot/share/gc/shared/collectedHeap.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hotspot/share/gc/shared/collectedHeap.hpp b/src/hotspot/share/gc/shared/collectedHeap.hpp index 9fed67ed33a6f..328cfbd43b312 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.hpp +++ b/src/hotspot/share/gc/shared/collectedHeap.hpp @@ -90,6 +90,7 @@ class GCHeapLog : public EventLogBase { class ParallelObjectIterator : public CHeapObj { public: virtual void object_iterate(ObjectClosure* cl, uint worker_id) = 0; + virtual ~ParallelObjectIterator() {} }; // From 6bddeb709d1d263d0d753909cabce7e755e7e27d Mon Sep 17 00:00:00 2001 From: Robbin Ehn Date: Tue, 29 Sep 2020 08:50:54 +0000 Subject: [PATCH 55/79] 8238761: Asynchronous handshakes Reviewed-by: pchilanomate, dcubed, dholmes, coleenp, sspitsyn --- src/hotspot/share/memory/iterator.hpp | 4 +- src/hotspot/share/prims/jvmtiEnv.cpp | 39 +- src/hotspot/share/prims/jvmtiEnvBase.cpp | 46 +-- src/hotspot/share/prims/jvmtiEnvBase.hpp | 77 ++-- .../share/prims/jvmtiEnvThreadState.cpp | 23 +- .../share/prims/jvmtiEventController.cpp | 17 +- src/hotspot/share/prims/jvmtiThreadState.cpp | 12 +- src/hotspot/share/prims/whitebox.cpp | 27 ++ src/hotspot/share/runtime/biasedLocking.cpp | 13 +- src/hotspot/share/runtime/handshake.cpp | 366 +++++++++--------- src/hotspot/share/runtime/handshake.hpp | 103 ++--- .../share/runtime/interfaceSupport.inline.hpp | 7 +- src/hotspot/share/runtime/mutexLocker.cpp | 2 +- .../share/runtime/safepointMechanism.cpp | 6 +- .../share/runtime/safepointMechanism.hpp | 2 +- src/hotspot/share/runtime/thread.cpp | 19 +- src/hotspot/share/runtime/thread.hpp | 22 +- src/hotspot/share/utilities/filterQueue.hpp | 86 ++++ .../share/utilities/filterQueue.inline.hpp | 114 ++++++ .../gtest/utilities/test_filterQueue.cpp | 186 +++++++++ .../AsyncHandshakeWalkStackTest.java | 110 ++++++ .../handshake/HandshakeDirectTest.java | 2 +- .../MixedHandshakeWalkStackTest.java | 66 ++++ test/lib/sun/hotspot/WhiteBox.java | 1 + 24 files changed, 975 insertions(+), 375 deletions(-) create mode 100644 src/hotspot/share/utilities/filterQueue.hpp create mode 100644 src/hotspot/share/utilities/filterQueue.inline.hpp create mode 100644 test/hotspot/gtest/utilities/test_filterQueue.cpp create mode 100644 test/hotspot/jtreg/runtime/handshake/AsyncHandshakeWalkStackTest.java create mode 100644 test/hotspot/jtreg/runtime/handshake/MixedHandshakeWalkStackTest.java diff --git a/src/hotspot/share/memory/iterator.hpp b/src/hotspot/share/memory/iterator.hpp index df351f1fd9487..fb3a4c2ca347f 100644 --- a/src/hotspot/share/memory/iterator.hpp +++ b/src/hotspot/share/memory/iterator.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2020, 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 @@ -44,7 +44,7 @@ class Thread; class Closure : public StackObj { }; // Thread iterator -class ThreadClosure: public Closure { +class ThreadClosure { public: virtual void do_thread(Thread* thread) = 0; }; diff --git a/src/hotspot/share/prims/jvmtiEnv.cpp b/src/hotspot/share/prims/jvmtiEnv.cpp index d50f903c7df26..139788f902f26 100644 --- a/src/hotspot/share/prims/jvmtiEnv.cpp +++ b/src/hotspot/share/prims/jvmtiEnv.cpp @@ -1213,8 +1213,8 @@ JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count } else { // get owned monitors info with handshake GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } jint owned_monitor_count = owned_monitors_list->length(); if (err == JVMTI_ERROR_NONE) { @@ -1258,8 +1258,8 @@ JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_i } else { // get owned monitors info with handshake GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } jint owned_monitor_count = owned_monitors_list->length(); @@ -1302,8 +1302,8 @@ JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_p } else { // get contended monitor information with handshake GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } return err; } /* end GetCurrentContendedMonitor */ @@ -1540,8 +1540,8 @@ JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_fram } else { // Get stack trace with handshake. GetStackTraceClosure op(this, start_depth, max_frame_count, frame_buffer, count_ptr); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } return err; @@ -1585,8 +1585,8 @@ JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list } GetSingleStackTraceClosure op(this, current_thread, *thread_list, max_frame_count); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); if (err == JVMTI_ERROR_NONE) { *stack_info_ptr = op.stack_info(); } @@ -1623,8 +1623,8 @@ JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) { } else { // get java stack frame count with handshake. GetFrameCountClosure op(this, state, count_ptr); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } return err; } /* end GetFrameCount */ @@ -1721,10 +1721,9 @@ JvmtiEnv::PopFrame(JavaThread* java_thread) { state->update_for_pop_top_frame(); } else { UpdateForPopTopFrameClosure op(state); - bool executed = Handshake::execute_direct(&op, java_thread); - jvmtiError err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; - if (err != JVMTI_ERROR_NONE) { - return err; + Handshake::execute(&op, java_thread); + if (op.result() != JVMTI_ERROR_NONE) { + return op.result(); } } } @@ -1756,8 +1755,8 @@ JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* metho } else { // JVMTI get java stack frame location via direct handshake. GetFrameLocationClosure op(this, depth, method_ptr, location_ptr); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } return err; } /* end GetFrameLocation */ @@ -1805,8 +1804,8 @@ JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) { state->env_thread_state(this)->set_frame_pop(frame_number); } else { SetFramePopClosure op(this, state, depth); - bool executed = Handshake::execute_direct(&op, java_thread); - err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE; + Handshake::execute(&op, java_thread); + err = op.result(); } return err; } /* end NotifyFramePop */ diff --git a/src/hotspot/share/prims/jvmtiEnvBase.cpp b/src/hotspot/share/prims/jvmtiEnvBase.cpp index 21acadd8a7179..6dfde0054ddcb 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.cpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.cpp @@ -649,10 +649,9 @@ JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) { jvmtiError JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) { - JavaThread *current_jt = JavaThread::current(); - assert(current_jt == java_thread || - current_jt == java_thread->active_handshaker(), - "call by myself or at direct handshake"); + Thread *current_thread = Thread::current(); + assert(java_thread->is_handshake_safe_for(current_thread), + "call by myself or at handshake"); oop obj = NULL; // The ObjectMonitor* can't be async deflated since we are either // at a safepoint or the calling thread is operating on itself so @@ -676,8 +675,8 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre if (obj == NULL) { *monitor_ptr = NULL; } else { - HandleMark hm(current_jt); - Handle hobj(current_jt, obj); + HandleMark hm(current_thread); + Handle hobj(current_thread, obj); *monitor_ptr = jni_reference(calling_thread, hobj); } return JVMTI_ERROR_NONE; @@ -687,15 +686,19 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre jvmtiError JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread, GrowableArray *owned_monitors_list) { + // Note: + // calling_thread is the thread that requested the list of monitors for java_thread. + // java_thread is the thread owning the monitors. + // current_thread is the thread executing this code, can be a non-JavaThread (e.g. VM Thread). + // And they all may be different threads. jvmtiError err = JVMTI_ERROR_NONE; - JavaThread *current_jt = JavaThread::current(); - assert(current_jt == java_thread || - current_jt == java_thread->active_handshaker(), - "call by myself or at direct handshake"); + Thread *current_thread = Thread::current(); + assert(java_thread->is_handshake_safe_for(current_thread), + "call by myself or at handshake"); if (java_thread->has_last_Java_frame()) { - ResourceMark rm(current_jt); - HandleMark hm(current_jt); + ResourceMark rm(current_thread); + HandleMark hm(current_thread); RegisterMap reg_map(java_thread); int depth = 0; @@ -819,9 +822,8 @@ JvmtiEnvBase::get_stack_trace(JavaThread *java_thread, uint32_t debug_bits = 0; #endif Thread *current_thread = Thread::current(); - assert(current_thread == java_thread || - SafepointSynchronize::is_at_safepoint() || - current_thread == java_thread->active_handshaker(), + assert(SafepointSynchronize::is_at_safepoint() || + java_thread->is_handshake_safe_for(current_thread), "call by myself / at safepoint / at handshake"); int count = 0; if (java_thread->has_last_Java_frame()) { @@ -903,9 +905,8 @@ JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth, uint32_t debug_bits = 0; #endif Thread* current_thread = Thread::current(); - assert(current_thread == java_thread || - current_thread == java_thread->active_handshaker(), - "call by myself or at direct handshake"); + assert(java_thread->is_handshake_safe_for(current_thread), + "call by myself or at handshake"); ResourceMark rm(current_thread); vframe *vf = vframeFor(java_thread, depth); @@ -1159,9 +1160,8 @@ void MultipleStackTracesCollector::fill_frames(jthread jt, JavaThread *thr, oop thread_oop) { #ifdef ASSERT Thread *current_thread = Thread::current(); - assert(current_thread == thr || - SafepointSynchronize::is_at_safepoint() || - current_thread == thr->active_handshaker(), + assert(SafepointSynchronize::is_at_safepoint() || + thr->is_handshake_safe_for(current_thread), "call by myself / at safepoint / at handshake"); #endif @@ -1305,7 +1305,7 @@ VM_GetAllStackTraces::doit() { // HandleMark must be defined in the caller only. // It is to keep a ret_ob_h handle alive after return to the caller. jvmtiError -JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread, +JvmtiEnvBase::check_top_frame(Thread* current_thread, JavaThread* java_thread, jvalue value, TosState tos, Handle* ret_ob_h) { ResourceMark rm(current_thread); @@ -1368,7 +1368,7 @@ JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_threa jvmtiError JvmtiEnvBase::force_early_return(JavaThread* java_thread, jvalue value, TosState tos) { - JavaThread* current_thread = JavaThread::current(); + Thread* current_thread = Thread::current(); HandleMark hm(current_thread); uint32_t debug_bits = 0; diff --git a/src/hotspot/share/prims/jvmtiEnvBase.hpp b/src/hotspot/share/prims/jvmtiEnvBase.hpp index 21d518cea7c1f..7d3db0799577e 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.hpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.hpp @@ -306,7 +306,7 @@ class JvmtiEnvBase : public CHeapObj { jobject *monitor_ptr); jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread, GrowableArray *owned_monitors_list); - jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread, + jvmtiError check_top_frame(Thread* current_thread, JavaThread* java_thread, jvalue value, TosState tos, Handle* ret_ob_h); jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos); }; @@ -336,58 +336,58 @@ class JvmtiEnvIterator : public StackObj { JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); } }; +class JvmtiHandshakeClosure : public HandshakeClosure { + protected: + jvmtiError _result; + public: + JvmtiHandshakeClosure(const char* name) + : HandshakeClosure(name), + _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} + jvmtiError result() { return _result; } +}; + // HandshakeClosure to update for pop top frame. -class UpdateForPopTopFrameClosure : public HandshakeClosure { +class UpdateForPopTopFrameClosure : public JvmtiHandshakeClosure { private: JvmtiThreadState* _state; - jvmtiError _result; public: UpdateForPopTopFrameClosure(JvmtiThreadState* state) - : HandshakeClosure("UpdateForPopTopFrame"), - _state(state), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} - jvmtiError result() { return _result; } + : JvmtiHandshakeClosure("UpdateForPopTopFrame"), + _state(state) {} void do_thread(Thread *target); }; // HandshakeClosure to set frame pop. -class SetFramePopClosure : public HandshakeClosure { +class SetFramePopClosure : public JvmtiHandshakeClosure { private: JvmtiEnv *_env; JvmtiThreadState* _state; jint _depth; - jvmtiError _result; public: SetFramePopClosure(JvmtiEnv *env, JvmtiThreadState* state, jint depth) - : HandshakeClosure("SetFramePop"), + : JvmtiHandshakeClosure("SetFramePop"), _env(env), _state(state), - _depth(depth), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} - jvmtiError result() { return _result; } + _depth(depth) {} void do_thread(Thread *target); }; - // HandshakeClosure to get monitor information with stack depth. -class GetOwnedMonitorInfoClosure : public HandshakeClosure { +class GetOwnedMonitorInfoClosure : public JvmtiHandshakeClosure { private: JavaThread* _calling_thread; JvmtiEnv *_env; - jvmtiError _result; GrowableArray *_owned_monitors_list; public: GetOwnedMonitorInfoClosure(JavaThread* calling_thread, JvmtiEnv* env, GrowableArray* owned_monitor_list) - : HandshakeClosure("GetOwnedMonitorInfo"), + : JvmtiHandshakeClosure("GetOwnedMonitorInfo"), _calling_thread(calling_thread), _env(env), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE), _owned_monitors_list(owned_monitor_list) {} - jvmtiError result() { return _result; } void do_thread(Thread *target); }; @@ -417,46 +417,39 @@ class VM_GetObjectMonitorUsage : public VM_Operation { }; // HandshakeClosure to get current contended monitor. -class GetCurrentContendedMonitorClosure : public HandshakeClosure { +class GetCurrentContendedMonitorClosure : public JvmtiHandshakeClosure { private: JavaThread *_calling_thread; JvmtiEnv *_env; jobject *_owned_monitor_ptr; - jvmtiError _result; public: GetCurrentContendedMonitorClosure(JavaThread* calling_thread, JvmtiEnv *env, jobject *mon_ptr) - : HandshakeClosure("GetCurrentContendedMonitor"), + : JvmtiHandshakeClosure("GetCurrentContendedMonitor"), _calling_thread(calling_thread), _env(env), - _owned_monitor_ptr(mon_ptr), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} - jvmtiError result() { return _result; } + _owned_monitor_ptr(mon_ptr) {} void do_thread(Thread *target); }; // HandshakeClosure to get stack trace. -class GetStackTraceClosure : public HandshakeClosure { +class GetStackTraceClosure : public JvmtiHandshakeClosure { private: JvmtiEnv *_env; jint _start_depth; jint _max_count; jvmtiFrameInfo *_frame_buffer; jint *_count_ptr; - jvmtiError _result; public: GetStackTraceClosure(JvmtiEnv *env, jint start_depth, jint max_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) - : HandshakeClosure("GetStackTrace"), + : JvmtiHandshakeClosure("GetStackTrace"), _env(env), _start_depth(start_depth), _max_count(max_count), _frame_buffer(frame_buffer), - _count_ptr(count_ptr), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) { - } - jvmtiError result() { return _result; } + _count_ptr(count_ptr) {} void do_thread(Thread *target); }; @@ -556,45 +549,37 @@ class GetSingleStackTraceClosure : public HandshakeClosure { }; // HandshakeClosure to count stack frames. -class GetFrameCountClosure : public HandshakeClosure { +class GetFrameCountClosure : public JvmtiHandshakeClosure { private: JvmtiEnv *_env; JvmtiThreadState *_state; jint *_count_ptr; - jvmtiError _result; public: GetFrameCountClosure(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) - : HandshakeClosure("GetFrameCount"), + : JvmtiHandshakeClosure("GetFrameCount"), _env(env), _state(state), - _count_ptr(count_ptr), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) { - } - jvmtiError result() { return _result; } + _count_ptr(count_ptr) {} void do_thread(Thread *target); }; // HandshakeClosure to get frame location. -class GetFrameLocationClosure : public HandshakeClosure { +class GetFrameLocationClosure : public JvmtiHandshakeClosure { private: JvmtiEnv *_env; jint _depth; jmethodID* _method_ptr; jlocation* _location_ptr; - jvmtiError _result; public: GetFrameLocationClosure(JvmtiEnv *env, jint depth, jmethodID* method_ptr, jlocation* location_ptr) - : HandshakeClosure("GetFrameLocation"), + : JvmtiHandshakeClosure("GetFrameLocation"), _env(env), _depth(depth), _method_ptr(method_ptr), - _location_ptr(location_ptr), - _result(JVMTI_ERROR_THREAD_NOT_ALIVE) { - } - jvmtiError result() { return _result; } + _location_ptr(location_ptr) {} void do_thread(Thread *target); }; diff --git a/src/hotspot/share/prims/jvmtiEnvThreadState.cpp b/src/hotspot/share/prims/jvmtiEnvThreadState.cpp index c6ed99e4a6717..a154f82a810ff 100644 --- a/src/hotspot/share/prims/jvmtiEnvThreadState.cpp +++ b/src/hotspot/share/prims/jvmtiEnvThreadState.cpp @@ -194,7 +194,7 @@ JvmtiFramePops* JvmtiEnvThreadState::get_frame_pops() { #ifdef ASSERT Thread *current = Thread::current(); #endif - assert(get_thread() == current || current == get_thread()->active_handshaker(), + assert(get_thread()->is_handshake_safe_for(current), "frame pop data only accessible from same thread or direct handshake"); if (_frame_pops == NULL) { _frame_pops = new JvmtiFramePops(); @@ -212,7 +212,7 @@ void JvmtiEnvThreadState::set_frame_pop(int frame_number) { #ifdef ASSERT Thread *current = Thread::current(); #endif - assert(get_thread() == current || current == get_thread()->active_handshaker(), + assert(get_thread()->is_handshake_safe_for(current), "frame pop data only accessible from same thread or direct handshake"); JvmtiFramePop fpop(frame_number); JvmtiEventController::set_frame_pop(this, fpop); @@ -223,7 +223,7 @@ void JvmtiEnvThreadState::clear_frame_pop(int frame_number) { #ifdef ASSERT Thread *current = Thread::current(); #endif - assert(get_thread() == current || current == get_thread()->active_handshaker(), + assert(get_thread()->is_handshake_safe_for(current), "frame pop data only accessible from same thread or direct handshake"); JvmtiFramePop fpop(frame_number); JvmtiEventController::clear_frame_pop(this, fpop); @@ -234,7 +234,7 @@ bool JvmtiEnvThreadState::is_frame_pop(int cur_frame_number) { #ifdef ASSERT Thread *current = Thread::current(); #endif - assert(get_thread() == current || current == get_thread()->active_handshaker(), + assert(get_thread()->is_handshake_safe_for(current), "frame pop data only accessible from same thread or direct handshake"); if (!get_thread()->is_interp_only_mode() || _frame_pops == NULL) { return false; @@ -248,12 +248,13 @@ class GetCurrentLocationClosure : public HandshakeClosure { private: jmethodID _method_id; int _bci; - + bool _completed; public: GetCurrentLocationClosure() : HandshakeClosure("GetCurrentLocation"), _method_id(NULL), - _bci(0) {} + _bci(0), + _completed(false) {} void do_thread(Thread *target) { JavaThread *jt = target->as_Java_thread(); ResourceMark rmark; // jt != Thread::current() @@ -272,11 +273,15 @@ class GetCurrentLocationClosure : public HandshakeClosure { _method_id = (jmethodID)NULL; _bci = 0; } + _completed = true; } void get_current_location(jmethodID *method_id, int *bci) { *method_id = _method_id; *bci = _bci; } + bool completed() { + return _completed; + } }; void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool enabled) { @@ -314,11 +319,11 @@ void JvmtiEnvThreadState::reset_current_location(jvmtiEvent event_type, bool ena // so get current location with direct handshake. GetCurrentLocationClosure op; Thread *current = Thread::current(); - if (current == _thread || _thread->active_handshaker() == current) { + if (_thread->is_handshake_safe_for(current)) { op.do_thread(_thread); } else { - bool executed = Handshake::execute_direct(&op, _thread); - guarantee(executed, "Direct handshake failed. Target thread is not alive?"); + Handshake::execute(&op, _thread); + guarantee(op.completed(), "Handshake failed. Target thread is not alive?"); } op.get_current_location(&method_id, &bci); set_current_location(method_id, bci); diff --git a/src/hotspot/share/prims/jvmtiEventController.cpp b/src/hotspot/share/prims/jvmtiEventController.cpp index 5d6b49b22aa93..ace58f4a3e0b3 100644 --- a/src/hotspot/share/prims/jvmtiEventController.cpp +++ b/src/hotspot/share/prims/jvmtiEventController.cpp @@ -194,9 +194,10 @@ JvmtiEnvEventEnable::~JvmtiEnvEventEnable() { // class EnterInterpOnlyModeClosure : public HandshakeClosure { - -public: - EnterInterpOnlyModeClosure() : HandshakeClosure("EnterInterpOnlyMode") { } + private: + bool _completed; + public: + EnterInterpOnlyModeClosure() : HandshakeClosure("EnterInterpOnlyMode"), _completed(false) { } void do_thread(Thread* th) { JavaThread* jt = th->as_Java_thread(); JvmtiThreadState* state = jt->jvmti_thread_state(); @@ -220,6 +221,10 @@ class EnterInterpOnlyModeClosure : public HandshakeClosure { } } } + _completed = true; + } + bool completed() { + return _completed = true; } }; @@ -333,11 +338,11 @@ void JvmtiEventControllerPrivate::enter_interp_only_mode(JvmtiThreadState *state EnterInterpOnlyModeClosure hs; JavaThread *target = state->get_thread(); Thread *current = Thread::current(); - if (target == current || target->active_handshaker() == current) { + if (target->is_handshake_safe_for(current)) { hs.do_thread(target); } else { - bool executed = Handshake::execute_direct(&hs, target); - guarantee(executed, "Direct handshake failed. Target thread is not alive?"); + Handshake::execute(&hs, target); + guarantee(hs.completed(), "Handshake failed: Target thread is not alive?"); } } diff --git a/src/hotspot/share/prims/jvmtiThreadState.cpp b/src/hotspot/share/prims/jvmtiThreadState.cpp index 94db78c122664..1d1dc7aced32e 100644 --- a/src/hotspot/share/prims/jvmtiThreadState.cpp +++ b/src/hotspot/share/prims/jvmtiThreadState.cpp @@ -224,9 +224,8 @@ int JvmtiThreadState::count_frames() { #ifdef ASSERT Thread *current_thread = Thread::current(); #endif - assert(current_thread == get_thread() || - SafepointSynchronize::is_at_safepoint() || - current_thread == get_thread()->active_handshaker(), + assert(SafepointSynchronize::is_at_safepoint() || + get_thread()->is_handshake_safe_for(current_thread), "call by myself / at safepoint / at handshake"); if (!get_thread()->has_last_Java_frame()) return 0; // no Java frames @@ -246,8 +245,7 @@ int JvmtiThreadState::count_frames() { void JvmtiThreadState::invalidate_cur_stack_depth() { assert(SafepointSynchronize::is_at_safepoint() || - JavaThread::current() == get_thread() || - Thread::current() == get_thread()->active_handshaker(), + get_thread()->is_handshake_safe_for(Thread::current()), "bad synchronization with owner thread"); _cur_stack_depth = UNKNOWN_STACK_DEPTH; @@ -277,8 +275,8 @@ void JvmtiThreadState::decr_cur_stack_depth() { } int JvmtiThreadState::cur_stack_depth() { - JavaThread *current = JavaThread::current(); - guarantee(current == get_thread() || current == get_thread()->active_handshaker(), + Thread *current = Thread::current(); + guarantee(get_thread()->is_handshake_safe_for(current), "must be current thread or direct handshake"); if (!is_interp_only_mode() || _cur_stack_depth == UNKNOWN_STACK_DEPTH) { diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 3bc077a1727b4..2360b5cc6f40d 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -2026,6 +2026,32 @@ WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_han return tsc.num_threads_completed(); WB_END +WB_ENTRY(void, WB_AsyncHandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle)) + class TraceSelfClosure : public AsyncHandshakeClosure { + JavaThread* _self; + void do_thread(Thread* th) { + assert(th->is_Java_thread(), "sanity"); + // AsynchHandshake handshakes are only executed by target. + assert(_self == th, "Must be"); + assert(Thread::current() == th, "Must be"); + JavaThread* jt = th->as_Java_thread(); + ResourceMark rm; + jt->print_on(tty); + jt->print_stack_on(tty); + tty->cr(); + } + + public: + TraceSelfClosure(JavaThread* self_target) : AsyncHandshakeClosure("WB_TraceSelf"), _self(self_target) {} + }; + oop thread_oop = JNIHandles::resolve(thread_handle); + if (thread_oop != NULL) { + JavaThread* target = java_lang_Thread::thread(thread_oop); + TraceSelfClosure* tsc = new TraceSelfClosure(target); + Handshake::execute(tsc, target); + } +WB_END + //Some convenience methods to deal with objects from java int WhiteBox::offset_for_field(const char* field_name, oop object, Symbol* signature_symbol) { @@ -2487,6 +2513,7 @@ static JNINativeMethod methods[] = { {CC"clearInlineCaches0", CC"(Z)V", (void*)&WB_ClearInlineCaches }, {CC"handshakeWalkStack", CC"(Ljava/lang/Thread;Z)I", (void*)&WB_HandshakeWalkStack }, + {CC"asyncHandshakeWalkStack", CC"(Ljava/lang/Thread;)V", (void*)&WB_AsyncHandshakeWalkStack }, {CC"checkThreadObjOfTerminatingThread", CC"(Ljava/lang/Thread;)V", (void*)&WB_CheckThreadObjOfTerminatingThread }, {CC"addCompilerDirective", CC"(Ljava/lang/String;)I", (void*)&WB_AddCompilerDirective }, diff --git a/src/hotspot/share/runtime/biasedLocking.cpp b/src/hotspot/share/runtime/biasedLocking.cpp index 9d4a03834b89e..67f232b1f5194 100644 --- a/src/hotspot/share/runtime/biasedLocking.cpp +++ b/src/hotspot/share/runtime/biasedLocking.cpp @@ -509,6 +509,7 @@ class RevokeOneBias : public HandshakeClosure { JavaThread* _biased_locker; BiasedLocking::Condition _status_code; traceid _biased_locker_id; + bool _executed; public: RevokeOneBias(Handle obj, JavaThread* requesting_thread, JavaThread* biased_locker) @@ -517,10 +518,14 @@ class RevokeOneBias : public HandshakeClosure { , _requesting_thread(requesting_thread) , _biased_locker(biased_locker) , _status_code(BiasedLocking::NOT_BIASED) - , _biased_locker_id(0) {} + , _biased_locker_id(0) + , _executed(false) {} + + bool executed() { return _executed; } void do_thread(Thread* target) { assert(target == _biased_locker, "Wrong thread"); + _executed = true; oop o = _obj(); markWord mark = o->mark(); @@ -622,11 +627,11 @@ BiasedLocking::Condition BiasedLocking::single_revoke_with_handshake(Handle obj, p2i(biaser), p2i(obj())); RevokeOneBias revoke(obj, requester, biaser); - bool executed = Handshake::execute_direct(&revoke, biaser); + Handshake::execute(&revoke, biaser); if (revoke.status_code() == NOT_REVOKED) { return NOT_REVOKED; } - if (executed) { + if (revoke.executed()) { log_info(biasedlocking, handshake)("Handshake revocation for object " INTPTR_FORMAT " succeeded. Bias was %srevoked", p2i(obj()), (revoke.status_code() == BIAS_REVOKED ? "" : "already ")); if (event.should_commit() && revoke.status_code() == BIAS_REVOKED) { @@ -668,7 +673,7 @@ BiasedLocking::Condition BiasedLocking::single_revoke_with_handshake(Handle obj, void BiasedLocking::walk_stack_and_revoke(oop obj, JavaThread* biased_locker) { Thread* cur = Thread::current(); assert(!SafepointSynchronize::is_at_safepoint(), "this should always be executed outside safepoints"); - assert(cur == biased_locker || cur == biased_locker->active_handshaker(), "wrong thread"); + assert(biased_locker->is_handshake_safe_for(cur), "wrong thread"); markWord mark = obj->mark(); assert(mark.biased_locker() == biased_locker && diff --git a/src/hotspot/share/runtime/handshake.cpp b/src/hotspot/share/runtime/handshake.cpp index 89d278981861a..c3af69d78650d 100644 --- a/src/hotspot/share/runtime/handshake.cpp +++ b/src/hotspot/share/runtime/handshake.cpp @@ -30,37 +30,53 @@ #include "runtime/handshake.hpp" #include "runtime/interfaceSupport.inline.hpp" #include "runtime/osThread.hpp" -#include "runtime/semaphore.inline.hpp" #include "runtime/task.hpp" #include "runtime/thread.hpp" #include "runtime/vmThread.hpp" #include "utilities/formatBuffer.hpp" +#include "utilities/filterQueue.inline.hpp" #include "utilities/preserveException.hpp" - -class HandshakeOperation: public StackObj { - HandshakeClosure* _handshake_cl; - int32_t _pending_threads; - bool _executed; - bool _is_direct; -public: - HandshakeOperation(HandshakeClosure* cl, bool is_direct = false) : +class HandshakeOperation : public CHeapObj { + friend class HandshakeState; + protected: + HandshakeClosure* _handshake_cl; + // Keeps track of emitted and completed handshake operations. + // Once it reaches zero all handshake operations have been performed. + int32_t _pending_threads; + JavaThread* _target; + + // Must use AsyncHandshakeOperation when using AsyncHandshakeClosure. + HandshakeOperation(AsyncHandshakeClosure* cl, JavaThread* target) : _handshake_cl(cl), _pending_threads(1), - _executed(false), - _is_direct(is_direct) {} + _target(target) {} + public: + HandshakeOperation(HandshakeClosure* cl, JavaThread* target) : + _handshake_cl(cl), + _pending_threads(1), + _target(target) {} + virtual ~HandshakeOperation() {} void do_handshake(JavaThread* thread); bool is_completed() { int32_t val = Atomic::load(&_pending_threads); assert(val >= 0, "_pending_threads=%d cannot be negative", val); return val == 0; } - void add_target_count(int count) { Atomic::add(&_pending_threads, count, memory_order_relaxed); } - bool executed() const { return _executed; } - const char* name() { return _handshake_cl->name(); } + void add_target_count(int count) { Atomic::add(&_pending_threads, count); } + const char* name() { return _handshake_cl->name(); } + bool is_async() { return _handshake_cl->is_async(); } +}; - bool is_direct() { return _is_direct; } +class AsyncHandshakeOperation : public HandshakeOperation { + private: + jlong _start_time_ns; + public: + AsyncHandshakeOperation(AsyncHandshakeClosure* cl, JavaThread* target, jlong start_ns) + : HandshakeOperation(cl, target), _start_time_ns(start_ns) {} + virtual ~AsyncHandshakeOperation() { delete _handshake_cl; } + jlong start_time() const { return _start_time_ns; } }; // Performing handshakes requires a custom yielding strategy because without it @@ -79,7 +95,6 @@ class HandshakeSpinYield : public StackObj { int _result_count[2][HandshakeState::_number_states]; int _prev_result_pos; - int prev_result_pos() { return _prev_result_pos & 0x1; } int current_result_pos() { return (_prev_result_pos + 1) & 0x1; } void wait_raw(jlong now) { @@ -176,8 +191,8 @@ bool VM_Handshake::handshake_has_timed_out(jlong start_time) { void VM_Handshake::handle_timeout() { LogStreamHandle(Warning, handshake) log_stream; - for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { - if (thr->has_handshake()) { + for (JavaThreadIteratorWithHandle jtiwh; JavaThread* thr = jtiwh.next(); ) { + if (thr->handshake_state()->has_operation()) { log_stream.print("Thread " PTR_FORMAT " has not cleared its handshake op", p2i(thr)); thr->print_thread_state_on(&log_stream); } @@ -186,78 +201,34 @@ void VM_Handshake::handle_timeout() { fatal("Handshake operation timed out"); } -static void log_handshake_info(jlong start_time_ns, const char* name, int targets, int vmt_executed, const char* extra = NULL) { - if (start_time_ns != 0) { +static void log_handshake_info(jlong start_time_ns, const char* name, int targets, int emitted_handshakes_executed, const char* extra = NULL) { + if (log_is_enabled(Info, handshake)) { jlong completion_time = os::javaTimeNanos() - start_time_ns; - log_info(handshake)("Handshake \"%s\", Targeted threads: %d, Executed by targeted threads: %d, Total completion time: " JLONG_FORMAT " ns%s%s", + log_info(handshake)("Handshake \"%s\", Targeted threads: %d, Executed by requesting thread: %d, Total completion time: " JLONG_FORMAT " ns%s%s", name, targets, - targets - vmt_executed, + emitted_handshakes_executed, completion_time, extra != NULL ? ", " : "", extra != NULL ? extra : ""); } } -class VM_HandshakeOneThread: public VM_Handshake { - JavaThread* _target; - public: - VM_HandshakeOneThread(HandshakeOperation* op, JavaThread* target) : - VM_Handshake(op), _target(target) {} - - void doit() { - jlong start_time_ns = os::javaTimeNanos(); - - ThreadsListHandle tlh; - if (tlh.includes(_target)) { - _target->set_handshake_operation(_op); - } else { - log_handshake_info(start_time_ns, _op->name(), 0, 0, "(thread dead)"); - return; - } - - log_trace(handshake)("JavaThread " INTPTR_FORMAT " signaled, begin attempt to process by VMThtread", p2i(_target)); - HandshakeState::ProcessResult pr = HandshakeState::_no_operation; - HandshakeSpinYield hsy(start_time_ns); - do { - if (handshake_has_timed_out(start_time_ns)) { - handle_timeout(); - } - pr = _target->handshake_try_process(_op); - hsy.add_result(pr); - hsy.process(); - } while (!_op->is_completed()); - - // This pairs up with the release store in do_handshake(). It prevents future - // loads from floating above the load of _pending_threads in is_completed() - // and thus prevents reading stale data modified in the handshake closure - // by the Handshakee. - OrderAccess::acquire(); - - log_handshake_info(start_time_ns, _op->name(), 1, (pr == HandshakeState::_success) ? 1 : 0); - } - - VMOp_Type type() const { return VMOp_HandshakeOneThread; } - - bool executed() const { return _op->executed(); } -}; - class VM_HandshakeAllThreads: public VM_Handshake { public: VM_HandshakeAllThreads(HandshakeOperation* op) : VM_Handshake(op) {} void doit() { jlong start_time_ns = os::javaTimeNanos(); - int handshake_executed_by_vm_thread = 0; JavaThreadIteratorWithHandle jtiwh; int number_of_threads_issued = 0; - for (JavaThread *thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) { - thr->set_handshake_operation(_op); + for (JavaThread* thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) { + thr->handshake_state()->add_operation(_op); number_of_threads_issued++; } if (number_of_threads_issued < 1) { - log_handshake_info(start_time_ns, _op->name(), 0, 0); + log_handshake_info(start_time_ns, _op->name(), 0, 0, "no threads alive"); return; } // _op was created with a count == 1 so don't double count. @@ -265,6 +236,9 @@ class VM_HandshakeAllThreads: public VM_Handshake { log_trace(handshake)("Threads signaled, begin processing blocked threads by VMThread"); HandshakeSpinYield hsy(start_time_ns); + // Keeps count on how many of own emitted handshakes + // this thread execute. + int emitted_handshakes_executed = 0; do { // Check if handshake operation has timed out if (handshake_has_timed_out(start_time_ns)) { @@ -273,16 +247,16 @@ class VM_HandshakeAllThreads: public VM_Handshake { // Have VM thread perform the handshake operation for blocked threads. // Observing a blocked state may of course be transient but the processing is guarded - // by semaphores and we optimistically begin by working on the blocked threads + // by mutexes and we optimistically begin by working on the blocked threads jtiwh.rewind(); - for (JavaThread *thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) { + for (JavaThread* thr = jtiwh.next(); thr != NULL; thr = jtiwh.next()) { // A new thread on the ThreadsList will not have an operation, // hence it is skipped in handshake_try_process. - HandshakeState::ProcessResult pr = thr->handshake_try_process(_op); - if (pr == HandshakeState::_success) { - handshake_executed_by_vm_thread++; - } + HandshakeState::ProcessResult pr = thr->handshake_state()->try_process(_op); hsy.add_result(pr); + if (pr == HandshakeState::_succeeded) { + emitted_handshakes_executed++; + } } hsy.process(); } while (!_op->is_completed()); @@ -293,7 +267,7 @@ class VM_HandshakeAllThreads: public VM_Handshake { // by the Handshakee. OrderAccess::acquire(); - log_handshake_info(start_time_ns, _op->name(), number_of_threads_issued, handshake_executed_by_vm_thread); + log_handshake_info(start_time_ns, _op->name(), number_of_threads_issued, emitted_handshakes_executed); } VMOp_Type type() const { return VMOp_HandshakeAllThreads; } @@ -307,8 +281,8 @@ void HandshakeOperation::do_handshake(JavaThread* thread) { // Only actually execute the operation for non terminated threads. if (!thread->is_terminated()) { + NoSafepointVerifier nsv; _handshake_cl->do_thread(thread); - _executed = true; } if (start_time_ns != 0) { @@ -327,37 +301,40 @@ void HandshakeOperation::do_handshake(JavaThread* thread) { // It is no longer safe to refer to 'this' as the VMThread/Handshaker may have destroyed this operation } -void Handshake::execute(HandshakeClosure* thread_cl) { - HandshakeOperation cto(thread_cl); +void Handshake::execute(HandshakeClosure* hs_cl) { + HandshakeOperation cto(hs_cl, NULL); VM_HandshakeAllThreads handshake(&cto); VMThread::execute(&handshake); } -bool Handshake::execute(HandshakeClosure* thread_cl, JavaThread* target) { - HandshakeOperation cto(thread_cl); - VM_HandshakeOneThread handshake(&cto, target); - VMThread::execute(&handshake); - return handshake.executed(); -} - -bool Handshake::execute_direct(HandshakeClosure* thread_cl, JavaThread* target) { +void Handshake::execute(HandshakeClosure* hs_cl, JavaThread* target) { JavaThread* self = JavaThread::current(); - HandshakeOperation op(thread_cl, /*is_direct*/ true); + HandshakeOperation op(hs_cl, target); jlong start_time_ns = os::javaTimeNanos(); ThreadsListHandle tlh; if (tlh.includes(target)) { - target->set_handshake_operation(&op); + target->handshake_state()->add_operation(&op); } else { - log_handshake_info(start_time_ns, op.name(), 0, 0, "(thread dead)"); - return false; + char buf[128]; + jio_snprintf(buf, sizeof(buf), "(thread= " INTPTR_FORMAT " dead)", p2i(target)); + log_handshake_info(start_time_ns, op.name(), 0, 0, buf); + return; } - HandshakeState::ProcessResult pr = HandshakeState::_no_operation; + // Keeps count on how many of own emitted handshakes + // this thread execute. + int emitted_handshakes_executed = 0; HandshakeSpinYield hsy(start_time_ns); while (!op.is_completed()) { - HandshakeState::ProcessResult pr = target->handshake_try_process(&op); + HandshakeState::ProcessResult pr = target->handshake_state()->try_process(&op); + if (pr == HandshakeState::_succeeded) { + emitted_handshakes_executed++; + } + if (op.is_completed()) { + break; + } hsy.add_result(pr); // Check for pending handshakes to avoid possible deadlocks where our // target is trying to handshake us. @@ -373,39 +350,65 @@ bool Handshake::execute_direct(HandshakeClosure* thread_cl, JavaThread* target) // by the Handshakee. OrderAccess::acquire(); - log_handshake_info(start_time_ns, op.name(), 1, (pr == HandshakeState::_success) ? 1 : 0); + log_handshake_info(start_time_ns, op.name(), 1, emitted_handshakes_executed); +} + +void Handshake::execute(AsyncHandshakeClosure* hs_cl, JavaThread* target) { + jlong start_time_ns = os::javaTimeNanos(); + AsyncHandshakeOperation* op = new AsyncHandshakeOperation(hs_cl, target, start_time_ns); - return op.executed(); + ThreadsListHandle tlh; + if (tlh.includes(target)) { + target->handshake_state()->add_operation(op); + } else { + log_handshake_info(start_time_ns, op->name(), 0, 0, "(thread dead)"); + delete op; + } } -HandshakeState::HandshakeState() : - _operation(NULL), - _operation_direct(NULL), - _handshake_turn_sem(1), - _processing_sem(1), - _thread_in_process_handshake(false), - _active_handshaker(NULL) +HandshakeState::HandshakeState(JavaThread* target) : + _handshakee(target), + _queue(), + _lock(Monitor::leaf, "HandshakeState", Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never), + _active_handshaker() { } -void HandshakeState::set_operation(HandshakeOperation* op) { - if (!op->is_direct()) { - assert(Thread::current()->is_VM_thread(), "should be the VMThread"); - _operation = op; - } else { - // Serialize direct handshakes so that only one proceeds at a time for a given target - _handshake_turn_sem.wait_with_safepoint_check(JavaThread::current()); - _operation_direct = op; - } +void HandshakeState::add_operation(HandshakeOperation* op) { + // Adds are done lock free and so is arming. + // Calling this method with lock held is considered an error. + assert(!_lock.owned_by_self(), "Lock should not be held"); + _queue.push(op); SafepointMechanism::arm_local_poll_release(_handshakee); } -void HandshakeState::clear_handshake(bool is_direct) { - if (!is_direct) { - _operation = NULL; - } else { - _operation_direct = NULL; - _handshake_turn_sem.signal(); +HandshakeOperation* HandshakeState::pop_for_self() { + assert(_handshakee == Thread::current(), "Must be called by self"); + assert(_lock.owned_by_self(), "Lock must be held"); + return _queue.pop(); +}; + +static bool non_self_queue_filter(HandshakeOperation* op) { + return !op->is_async(); +} + +bool HandshakeState::have_non_self_executable_operation() { + assert(_handshakee != Thread::current(), "Must not be called by self"); + assert(_lock.owned_by_self(), "Lock must be held"); + return _queue.contains(non_self_queue_filter); +} + +HandshakeOperation* HandshakeState::pop() { + assert(_handshakee != Thread::current(), "Must not be called by self"); + assert(_lock.owned_by_self(), "Lock must be held"); + return _queue.pop(non_self_queue_filter); +}; + +void HandshakeState::process_by_self() { + ThreadInVMForHandshake tivm(_handshakee); + { + NoSafepointVerifier nsv; + process_self_inner(); } } @@ -414,31 +417,24 @@ void HandshakeState::process_self_inner() { assert(!_handshakee->is_terminated(), "should not be a terminated thread"); assert(_handshakee->thread_state() != _thread_blocked, "should not be in a blocked state"); assert(_handshakee->thread_state() != _thread_in_native, "should not be in native"); - JavaThread* self = _handshakee; - do { - ThreadInVMForHandshake tivm(self); - if (!_processing_sem.trywait()) { - _processing_sem.wait_with_safepoint_check(self); - } - if (has_operation()) { - HandleMark hm(self); - CautiouslyPreserveExceptionMark pem(self); - HandshakeOperation * op = _operation; - if (op != NULL) { - // Disarm before executing the operation - clear_handshake(/*is_direct*/ false); - op->do_handshake(self); - } - op = _operation_direct; - if (op != NULL) { - // Disarm before executing the operation - clear_handshake(/*is_direct*/ true); - op->do_handshake(self); + while (should_process()) { + HandleMark hm(_handshakee); + CautiouslyPreserveExceptionMark pem(_handshakee); + MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); + HandshakeOperation* op = pop_for_self(); + if (op != NULL) { + assert(op->_target == NULL || op->_target == Thread::current(), "Wrong thread"); + bool async = op->is_async(); + log_trace(handshake)("Proc handshake %s " INTPTR_FORMAT " on " INTPTR_FORMAT " by self", + async ? "asynchronous" : "synchronous", p2i(op), p2i(_handshakee)); + op->do_handshake(_handshakee); + if (async) { + log_handshake_info(((AsyncHandshakeOperation*)op)->start_time(), op->name(), 1, 0, "asynchronous"); + delete op; } } - _processing_sem.signal(); - } while (has_operation()); + } } bool HandshakeState::can_process_handshake() { @@ -465,60 +461,78 @@ bool HandshakeState::possibly_can_process_handshake() { } } -bool HandshakeState::claim_handshake(bool is_direct) { - if (!_processing_sem.trywait()) { +bool HandshakeState::claim_handshake() { + if (!_lock.try_lock()) { return false; } - if (has_specific_operation(is_direct)){ - return true; + // Operations are added lock free and then the poll is armed. + // If all handshake operations for the handshakee are finished and someone + // just adds an operation we may see it here. But if the handshakee is not + // armed yet it is not safe to proceed. + if (have_non_self_executable_operation()) { + if (SafepointMechanism::local_poll_armed(_handshakee)) { + return true; + } } - _processing_sem.signal(); + _lock.unlock(); return false; } -HandshakeState::ProcessResult HandshakeState::try_process(HandshakeOperation* op) { - bool is_direct = op->is_direct(); - - if (!has_specific_operation(is_direct)){ +HandshakeState::ProcessResult HandshakeState::try_process(HandshakeOperation* match_op) { + if (!has_operation()) { // JT has already cleared its handshake - return _no_operation; + return HandshakeState::_no_operation; } if (!possibly_can_process_handshake()) { // JT is observed in an unsafe state, it must notice the handshake itself - return _not_safe; + return HandshakeState::_not_safe; } - // Claim the semaphore if there still an operation to be executed. - if (!claim_handshake(is_direct)) { - return _state_busy; + // Claim the mutex if there still an operation to be executed. + if (!claim_handshake()) { + return HandshakeState::_claim_failed; } - // Check if the handshake operation is the same as the one we meant to execute. The - // handshake could have been already processed by the handshakee and a new handshake - // by another JavaThread might be in progress. - if (is_direct && op != _operation_direct) { - _processing_sem.signal(); - return _no_operation; - } - - // If we own the semaphore at this point and while owning the semaphore + // If we own the mutex at this point and while owning the mutex we // can observe a safe state the thread cannot possibly continue without - // getting caught by the semaphore. - ProcessResult pr = _not_safe; - if (can_process_handshake()) { - guarantee(!_processing_sem.trywait(), "we should already own the semaphore"); - log_trace(handshake)("Processing handshake by %s", Thread::current()->is_VM_thread() ? "VMThread" : "Handshaker"); - _active_handshaker = Thread::current(); - op->do_handshake(_handshakee); - _active_handshaker = NULL; - // Disarm after we have executed the operation. - clear_handshake(is_direct); - pr = _success; + // getting caught by the mutex. + if (!can_process_handshake()) { + _lock.unlock(); + return HandshakeState::_not_safe; } - // Release the thread - _processing_sem.signal(); + Thread* current_thread = Thread::current(); + + HandshakeState::ProcessResult pr_ret = HandshakeState::_processed; + int executed = 0; + + do { + HandshakeOperation* op = pop(); + if (op != NULL) { + assert(SafepointMechanism::local_poll_armed(_handshakee), "Must be"); + assert(op->_target == NULL || _handshakee == op->_target, "Wrong thread"); + log_trace(handshake)("Processing handshake " INTPTR_FORMAT " by %s(%s)", p2i(op), + op == match_op ? "handshaker" : "cooperative", + current_thread->is_VM_thread() ? "VM Thread" : "JavaThread"); + + if (op == match_op) { + pr_ret = HandshakeState::_succeeded; + } + + _active_handshaker = current_thread; + op->do_handshake(_handshakee); + _active_handshaker = NULL; + + executed++; + } + } while (have_non_self_executable_operation()); + + _lock.unlock(); - return pr; + log_trace(handshake)("%s(" INTPTR_FORMAT ") executed %d ops for JavaThread: " INTPTR_FORMAT " %s target op: " INTPTR_FORMAT, + current_thread->is_VM_thread() ? "VM Thread" : "JavaThread", + p2i(current_thread), executed, p2i(_handshakee), + pr_ret == HandshakeState::_succeeded ? "including" : "excluding", p2i(match_op)); + return pr_ret; } diff --git a/src/hotspot/share/runtime/handshake.hpp b/src/hotspot/share/runtime/handshake.hpp index bf3de1f375c9e..eb93b66516c0c 100644 --- a/src/hotspot/share/runtime/handshake.hpp +++ b/src/hotspot/share/runtime/handshake.hpp @@ -27,86 +27,99 @@ #include "memory/allocation.hpp" #include "memory/iterator.hpp" -#include "runtime/semaphore.hpp" -#include "utilities/autoRestore.hpp" +#include "runtime/flags/flagSetting.hpp" +#include "runtime/mutex.hpp" +#include "utilities/filterQueue.hpp" class HandshakeOperation; class JavaThread; -// A handshake closure is a callback that is executed for each JavaThread -// while that thread is in a safepoint safe state. The callback is executed -// either by the target JavaThread itself or by the VMThread while keeping -// the target thread in a blocked state. A handshake can be performed with a -// single JavaThread as well. In that case, the callback is executed either -// by the target JavaThread itself or, depending on whether the operation is -// a direct handshake or not, by the JavaThread that requested the handshake -// or the VMThread respectively. -class HandshakeClosure : public ThreadClosure { +// A handshake closure is a callback that is executed for a JavaThread +// while it is in a safepoint/handshake-safe state. Depending on the +// nature of the closure, the callback may be executed by the initiating +// thread, the target thread, or the VMThread. If the callback is not executed +// by the target thread it will remain in a blocked state until the callback completes. +class HandshakeClosure : public ThreadClosure, public CHeapObj { const char* const _name; public: HandshakeClosure(const char* name) : _name(name) {} - const char* name() const { - return _name; - } + virtual ~HandshakeClosure() {} + const char* name() const { return _name; } + virtual bool is_async() { return false; } virtual void do_thread(Thread* thread) = 0; }; +class AsyncHandshakeClosure : public HandshakeClosure { + public: + AsyncHandshakeClosure(const char* name) : HandshakeClosure(name) {} + virtual ~AsyncHandshakeClosure() {} + virtual bool is_async() { return true; } +}; + class Handshake : public AllStatic { public: // Execution of handshake operation - static void execute(HandshakeClosure* hs_cl); - static bool execute(HandshakeClosure* hs_cl, JavaThread* target); - static bool execute_direct(HandshakeClosure* hs_cl, JavaThread* target); + static void execute(HandshakeClosure* hs_cl); + static void execute(HandshakeClosure* hs_cl, JavaThread* target); + static void execute(AsyncHandshakeClosure* hs_cl, JavaThread* target); }; // The HandshakeState keeps track of an ongoing handshake for this JavaThread. -// VMThread/Handshaker and JavaThread are serialized with semaphore _processing_sem -// making sure the operation is only done by either VMThread/Handshaker on behalf -// of the JavaThread or by the target JavaThread itself. +// VMThread/Handshaker and JavaThread are serialized with _lock making sure the +// operation is only done by either VMThread/Handshaker on behalf of the +// JavaThread or by the target JavaThread itself. class HandshakeState { + // This a back reference to the JavaThread, + // the target for all operation in the queue. JavaThread* _handshakee; - HandshakeOperation* volatile _operation; - HandshakeOperation* volatile _operation_direct; - - Semaphore _handshake_turn_sem; // Used to serialize direct handshakes for this JavaThread. - Semaphore _processing_sem; - bool _thread_in_process_handshake; + // The queue containing handshake operations to be performed on _handshakee. + FilterQueue _queue; + // Provides mutual exclusion to this state and queue. + Mutex _lock; + // Set to the thread executing the handshake operation. + Thread* _active_handshaker; - bool claim_handshake(bool is_direct); + bool claim_handshake(); bool possibly_can_process_handshake(); bool can_process_handshake(); - void clear_handshake(bool is_direct); - void process_self_inner(); -public: - HandshakeState(); + bool have_non_self_executable_operation(); + HandshakeOperation* pop_for_self(); + HandshakeOperation* pop(); + + public: + HandshakeState(JavaThread* thread); - void set_handshakee(JavaThread* thread) { _handshakee = thread; } + void add_operation(HandshakeOperation* op); - void set_operation(HandshakeOperation* op); - bool has_operation() const { return _operation != NULL || _operation_direct != NULL; } - bool has_specific_operation(bool is_direct) const { - return is_direct ? _operation_direct != NULL : _operation != NULL; + bool has_operation() { + return !_queue.is_empty(); } - void process_by_self() { - if (!_thread_in_process_handshake) { - AutoModifyRestore temporarily(_thread_in_process_handshake, true); - process_self_inner(); - } + // Both _queue and _lock must be checked. If a thread has seen this _handshakee + // as safe it will execute all possible handshake operations in a loop while + // holding _lock. We use lock free addition to the queue, which means it is + // possible for the queue to be seen as empty by _handshakee but as non-empty + // by the thread executing in the loop. To avoid the _handshakee continuing + // while handshake operations are being executed, the _handshakee + // must take slow path, process_by_self(), if _lock is held. + bool should_process() { + return !_queue.is_empty() || _lock.is_locked(); } + void process_by_self(); + enum ProcessResult { _no_operation = 0, _not_safe, - _state_busy, - _success, + _claim_failed, + _processed, + _succeeded, _number_states }; - ProcessResult try_process(HandshakeOperation* op); + ProcessResult try_process(HandshakeOperation* match_op); - Thread* _active_handshaker; Thread* active_handshaker() const { return _active_handshaker; } }; diff --git a/src/hotspot/share/runtime/interfaceSupport.inline.hpp b/src/hotspot/share/runtime/interfaceSupport.inline.hpp index cb7154f7192fe..f1965a4e3804c 100644 --- a/src/hotspot/share/runtime/interfaceSupport.inline.hpp +++ b/src/hotspot/share/runtime/interfaceSupport.inline.hpp @@ -132,10 +132,6 @@ class ThreadInVMForHandshake : public ThreadStateTransition { void transition_back() { // This can be invoked from transition states and must return to the original state properly assert(_thread->thread_state() == _thread_in_vm, "should only call when leaving VM after handshake"); - // Change to transition state and ensure it is seen by the VM thread. - _thread->set_thread_state_fence(_thread_in_vm_trans); - - SafepointMechanism::process_if_requested(_thread); _thread->set_thread_state(_original_state); @@ -156,6 +152,9 @@ class ThreadInVMForHandshake : public ThreadStateTransition { } thread->set_thread_state(_thread_in_vm); + + // Threads shouldn't block if they are in the middle of printing, but... + ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id()); } ~ThreadInVMForHandshake() { diff --git a/src/hotspot/share/runtime/mutexLocker.cpp b/src/hotspot/share/runtime/mutexLocker.cpp index 00d6ad7721f56..3d2dcc2a54666 100644 --- a/src/hotspot/share/runtime/mutexLocker.cpp +++ b/src/hotspot/share/runtime/mutexLocker.cpp @@ -193,7 +193,7 @@ void assert_lock_strong(const Mutex* lock) { } void assert_locked_or_safepoint_or_handshake(const Mutex* lock, const JavaThread* thread) { - if (Thread::current() == thread->active_handshaker()) return; + if (thread->is_handshake_safe_for(Thread::current())) return; assert_locked_or_safepoint(lock); } #endif diff --git a/src/hotspot/share/runtime/safepointMechanism.cpp b/src/hotspot/share/runtime/safepointMechanism.cpp index 79a15ab1bb8c0..b0c4d12974ae4 100644 --- a/src/hotspot/share/runtime/safepointMechanism.cpp +++ b/src/hotspot/share/runtime/safepointMechanism.cpp @@ -78,8 +78,8 @@ void SafepointMechanism::process(JavaThread *thread) { OrderAccess::loadload(); SafepointSynchronize::block(thread); } - if (thread->has_handshake()) { - thread->handshake_process_by_self(); + if (thread->handshake_state()->should_process()) { + thread->handshake_state()->process_by_self(); // Recursive } } @@ -96,7 +96,7 @@ void SafepointMechanism::process_if_requested_slow(JavaThread *thread) { disarm_local_poll_release(thread); // We might have disarmed next safepoint/handshake OrderAccess::storeload(); - if (global_poll() || thread->has_handshake()) { + if (global_poll() || thread->handshake_state()->has_operation()) { arm_local_poll(thread); } } diff --git a/src/hotspot/share/runtime/safepointMechanism.hpp b/src/hotspot/share/runtime/safepointMechanism.hpp index ed86fc9db17e3..65b1b21e3a534 100644 --- a/src/hotspot/share/runtime/safepointMechanism.hpp +++ b/src/hotspot/share/runtime/safepointMechanism.hpp @@ -39,7 +39,6 @@ class SafepointMechanism : public AllStatic { static void* poll_armed_value() { return _poll_armed_value; } static void* poll_disarmed_value() { return _poll_disarmed_value; } - static inline bool local_poll_armed(JavaThread* thread); static inline void disarm_local_poll(JavaThread* thread); static inline void disarm_local_poll_release(JavaThread* thread); @@ -58,6 +57,7 @@ class SafepointMechanism : public AllStatic { // between the armed and disarmed value by masking out this bit. const static intptr_t _poll_bit = 8; public: + static inline bool local_poll_armed(JavaThread* thread); static intptr_t poll_bit() { return _poll_bit; } static address get_polling_page() { return _polling_page; } diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp index 689cfe9b972bb..fc1253335ee5a 100644 --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -467,12 +467,11 @@ Thread::~Thread() { } #ifdef ASSERT -// A JavaThread is considered "dangling" if it is not the current -// thread, has been added the Threads list, the system is not at a -// safepoint and the Thread is not "protected". -// +// A JavaThread is considered dangling if it not handshake-safe with respect to +// the current thread, it is not on a ThreadsList, or not at safepoint. void Thread::check_for_dangling_thread_pointer(Thread *thread) { - assert(!thread->is_Java_thread() || Thread::current() == thread || + assert(!thread->is_Java_thread() || + thread->as_Java_thread()->is_handshake_safe_for(Thread::current()) || !thread->as_Java_thread()->on_thread_list() || SafepointSynchronize::is_at_safepoint() || ThreadsSMRSupport::is_a_protected_JavaThread_with_lock(thread->as_Java_thread()), @@ -837,7 +836,7 @@ bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay, // bool JavaThread::is_thread_fully_suspended(bool wait_for_suspend, uint32_t *bits) { - if (this != JavaThread::current()) { + if (this != Thread::current()) { // "other" threads require special handling. if (wait_for_suspend) { // We are allowed to wait for the external suspend to complete @@ -1715,7 +1714,6 @@ void JavaThread::initialize() { _SleepEvent = ParkEvent::Allocate(this); // Setup safepoint state info for this thread ThreadSafepointState::create(this); - _handshake.set_handshakee(this); debug_only(_java_call_counter = 0); @@ -1733,7 +1731,7 @@ void JavaThread::initialize() { } JavaThread::JavaThread(bool is_attaching_via_jni) : - Thread() { + Thread(), _handshake(this) { initialize(); if (is_attaching_via_jni) { _jni_attach_state = _attaching_via_jni; @@ -1848,7 +1846,7 @@ static void compiler_thread_entry(JavaThread* thread, TRAPS); static void sweeper_thread_entry(JavaThread* thread, TRAPS); JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : - Thread() { + Thread(), _handshake(this) { initialize(); _jni_attach_state = _not_attaching_via_jni; set_entry_point(entry_point); @@ -2406,7 +2404,8 @@ void JavaThread::handle_special_runtime_exit_condition(bool check_asyncs) { void JavaThread::send_thread_stop(oop java_throwable) { ResourceMark rm; - assert(Thread::current()->is_VM_thread() || Thread::current() == this, "should be in the vm thread"); + assert(is_handshake_safe_for(Thread::current()), + "should be self or handshakee"); // Do not throw asynchronous exceptions against the compiler thread // (the compiler thread should not be a Java thread -- fix in 1.4.2) diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 980fb0e0fd61d..564239c6cad60 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -1354,24 +1354,12 @@ class JavaThread: public Thread { // Support for thread handshake operations HandshakeState _handshake; public: - void set_handshake_operation(HandshakeOperation* op) { - _handshake.set_operation(op); - } - - bool has_handshake() const { - return _handshake.has_operation(); - } - - void handshake_process_by_self() { - _handshake.process_by_self(); - } - - HandshakeState::ProcessResult handshake_try_process(HandshakeOperation* op) { - return _handshake.try_process(op); - } + HandshakeState* handshake_state() { return &_handshake; } - Thread* active_handshaker() const { - return _handshake.active_handshaker(); + // A JavaThread can always safely operate on it self and other threads + // can do it safely if they are the active handshaker. + bool is_handshake_safe_for(Thread* th) const { + return _handshake.active_handshaker() == th || this == th; } // Suspend/resume support for JavaThread diff --git a/src/hotspot/share/utilities/filterQueue.hpp b/src/hotspot/share/utilities/filterQueue.hpp new file mode 100644 index 0000000000000..8567b351246b2 --- /dev/null +++ b/src/hotspot/share/utilities/filterQueue.hpp @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020, 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. + * + */ + +#ifndef SHARE_UTILITIES_FILTERQUEUE_HPP +#define SHARE_UTILITIES_FILTERQUEUE_HPP + +#include "memory/allocation.hpp" +#include "runtime/atomic.hpp" + +// The FilterQueue is FIFO with the ability to skip over queued items. +// The skipping is controlled by using a filter when popping. +// It also supports lock free pushes, while popping (including contains()) +// needs to be externally serialized. +template +class FilterQueue { + private: + class Node : public CHeapObj { + public: + Node(const E& e): _next(NULL), _data(e) { } + Node* _next; + E _data; + }; + + Node* _first; + Node* load_first() { + return Atomic::load_acquire(&_first); + } + + static bool match_all(E d) { return true; } + + public: + FilterQueue() : _first(NULL) { } + + bool is_empty() { + return load_first() == NULL; + } + + // Adds an item to the queue in a MT safe way, re-entrant. + void push(E data); + + // Applies the match_func to the items in the queue until match_func returns + // true and then returns true, or there is no more items and then returns + // false. Items pushed after execution starts will not have match_func + // applied. The method is not re-entrant and must be executed mutually + // exclusive to other contains and pops calls. + template + bool contains(MATCH_FUNC& match_func); + + // Same as pop(MATCH_FUNC& match_func) but matches everything, thus returning + // the first inserted item. + E pop() { + return pop(match_all); + } + + // Applies the match_func to each item in the queue and returns the first + // inserted item for which match_func returns true. Returns false if there are + // no matches or the queue is empty. Any pushed item before execution is + // complete may or may not have match_func applied. The method is not + // re-entrant and must be executed mutual exclusive to other contains and pops + // calls. + template + E pop(MATCH_FUNC& match_func); +}; + +#endif diff --git a/src/hotspot/share/utilities/filterQueue.inline.hpp b/src/hotspot/share/utilities/filterQueue.inline.hpp new file mode 100644 index 0000000000000..f0f68b511dc8e --- /dev/null +++ b/src/hotspot/share/utilities/filterQueue.inline.hpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2020, 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. + * + */ + +#ifndef SHARE_UTILITIES_FILTERQUEUE_INLINE_HPP +#define SHARE_UTILITIES_FILTERQUEUE_INLINE_HPP + +#include "utilities/filterQueue.hpp" +#include "utilities/spinYield.hpp" + +template +void FilterQueue::push(E data) { + Node* head; + Node* insnode = new Node(data); + SpinYield yield(SpinYield::default_spin_limit * 10); // Very unlikely with multiple failed CAS. + while (true){ + head = load_first(); + insnode->_next = head; + if (Atomic::cmpxchg(&_first, head, insnode) == head) { + break; + } + yield.wait(); + } +} + +// MT-Unsafe, external serialization needed. +template +template +bool FilterQueue::contains(MATCH_FUNC& match_func) { + Node* cur = load_first(); + if (cur == NULL) { + return false; + } + do { + if (match_func(cur->_data)) { + return true; + } + cur = cur->_next; + } while (cur != NULL); + return false; +} + +// MT-Unsafe, external serialization needed. +template +template +E FilterQueue::pop(MATCH_FUNC& match_func) { + Node* first = load_first(); + Node* cur = first; + Node* prev = NULL; + Node* match = NULL; + Node* match_prev = NULL; + + if (cur == NULL) { + return (E)NULL; + } + SpinYield yield(SpinYield::default_spin_limit * 10); // Very unlikely with multiple failed CAS. + do { + do { + if (match_func(cur->_data)) { + match = cur; + match_prev = prev; + } + prev = cur; + cur = cur->_next; + } while (cur != NULL); + + if (match == NULL) { + return (E)NULL; + } + + if (match_prev == NULL) { + // Working on first + if (Atomic::cmpxchg(&_first, match, match->_next) == match) { + E ret = match->_data; + delete match; + return ret; + } + yield.wait(); + // Failed, we need to restart to know the Node prior to the match. + first = load_first(); + cur = first; + prev = NULL; + match = NULL; + match_prev = NULL; + } else { + match_prev->_next = match->_next; + E ret = match->_data; + delete match; + return ret; + } + } while (true); +} + +#endif // SHARE_UTILITIES_FILTERQUEUE_INLINE_HPP diff --git a/test/hotspot/gtest/utilities/test_filterQueue.cpp b/test/hotspot/gtest/utilities/test_filterQueue.cpp new file mode 100644 index 0000000000000..39b0a9dcd8b63 --- /dev/null +++ b/test/hotspot/gtest/utilities/test_filterQueue.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2020, 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. + */ + +#include "precompiled.hpp" +#include "runtime/mutex.hpp" +#include "utilities/filterQueue.inline.hpp" +#include "threadHelper.inline.hpp" +#include "unittest.hpp" + +// EXPECT_EQ(cht_get_copy(cht, thr, stl2), val2) << "Get did not find value."; + +static bool match_all(uintptr_t val) { + return true; +} + +static bool match_1(uintptr_t val) { + return 1 == val; +} + +static bool match_2(uintptr_t val) { + return 2 == val; +} + +static bool match_3(uintptr_t val) { + return 3 == val; +} + +static bool match_4(uintptr_t val) { + return 4 == val; +} + +static bool match_even(uintptr_t val) { + return (val & 0x1) == 0x0; +} + +static void is_empty(FilterQueue& queue) { + EXPECT_EQ(queue.is_empty(), true) << "Must be empty."; + EXPECT_EQ(queue.contains(match_1), false) << "Must be empty."; + EXPECT_EQ(queue.contains(match_all), false) << "Must be empty."; + EXPECT_EQ(queue.pop(match_all), (uintptr_t)0) << "Must be empty."; +} + +TEST_VM(FilterQueue, one) { + FilterQueue queue; + is_empty(queue); + queue.push(1); + EXPECT_EQ(queue.is_empty(), false) << "Must be not empty."; + EXPECT_EQ(queue.contains(match_1), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_all), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_even), false) << "Must not contain a value."; + EXPECT_EQ(queue.pop(match_all), (uintptr_t)1) << "Must not be empty."; + is_empty(queue); +} + +TEST_VM(FilterQueue, two) { + FilterQueue queue; + + queue.push(1); + queue.push(2); + + EXPECT_EQ(queue.is_empty(), false) << "Must be not empty."; + EXPECT_EQ(queue.contains(match_1), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_2), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_all), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_even), true) << "Must contain a value."; + + EXPECT_EQ(queue.pop(match_all), (uintptr_t)1) << "Must not be empty."; + + EXPECT_EQ(queue.is_empty(), false) << "Must be not empty."; + EXPECT_EQ(queue.contains(match_1), false) << "Must not contain a value."; + EXPECT_EQ(queue.contains(match_2), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_all), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_even), true) << "Must contain a value."; + + queue.push(3); + + EXPECT_EQ(queue.pop(match_even), (uintptr_t)2) << "Must not be empty."; + + queue.push(2); + + EXPECT_EQ(queue.pop(match_even), (uintptr_t)2) << "Must not be empty."; + + EXPECT_EQ(queue.is_empty(), false) << "Must be not empty."; + EXPECT_EQ(queue.contains(match_3), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_2), false) << "Must not contain a value."; + EXPECT_EQ(queue.contains(match_all), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_even), false) << "Must not contain a value."; + + EXPECT_EQ(queue.pop(match_even), (uintptr_t)0) << "Must be empty."; + EXPECT_EQ(queue.pop(match_all), (uintptr_t)3) << "Must not be empty."; + + is_empty(queue); +} + +TEST_VM(FilterQueue, three) { + FilterQueue queue; + + queue.push(1); + queue.push(2); + queue.push(3); + + EXPECT_EQ(queue.is_empty(), false) << "Must be not empty."; + EXPECT_EQ(queue.contains(match_1), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_2), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_3), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_4), false) << "Must not contain a value."; + + EXPECT_EQ(queue.contains(match_all), true) << "Must contain a value."; + EXPECT_EQ(queue.contains(match_even), true) << "Must contain a value."; + + EXPECT_EQ(queue.pop(match_even), (uintptr_t)2) << "Must not be empty."; + EXPECT_EQ(queue.pop(match_even), (uintptr_t)0) << "Must be empty."; + EXPECT_EQ(queue.pop(match_all), (uintptr_t)1) << "Must not be empty."; + EXPECT_EQ(queue.pop(match_all), (uintptr_t)3) << "Must not be empty."; + + is_empty(queue); +} + +class FilterQueueTestThread : public JavaTestThread { + FilterQueue* _fq; + Mutex* _lock; + uintptr_t _val; + uintptr_t _pop; +public: + FilterQueueTestThread(Semaphore* post, FilterQueue* fq, Mutex* lock, uintptr_t val, uintptr_t pop) + : JavaTestThread(post), _fq(fq), _lock(lock), _val(val), _pop(pop) { + } + virtual void main_run() { + for (int i = 0; i < 1000; i++) { + for (int j = 0; j < 10; j++) { + _fq->push(_val); + } + { + do { + MutexLocker ml(_lock, Mutex::_no_safepoint_check_flag); + if (_fq->contains(*this) != 0) { + break; + } + } while (true); + } + for (int j = 0; j < 10; j++) { + MutexLocker ml(_lock, Mutex::_no_safepoint_check_flag); + while (_fq->pop(*this) == 0) {} + } + } + } + bool operator()(uintptr_t val) { + return val == _pop; + } +}; + +TEST_VM(FilterQueue, stress) { + FilterQueue queue; + Mutex lock(Mutex::leaf, "Test Lock", true, Mutex::_safepoint_check_never); + static const int nthreads = 4; + Semaphore post; + FilterQueueTestThread* threads[nthreads] = {}; + for (int i = 0; i < nthreads; ++i) { + threads[i] = new FilterQueueTestThread(&post, &queue, &lock, i + 1, i + 2 > nthreads ? 1 : i + 2); + threads[i]->doit(); + } + for (uint i = 0; i < nthreads; ++i) { + post.wait(); + } + EXPECT_EQ(queue.is_empty(), true) << "Must be empty."; +} diff --git a/test/hotspot/jtreg/runtime/handshake/AsyncHandshakeWalkStackTest.java b/test/hotspot/jtreg/runtime/handshake/AsyncHandshakeWalkStackTest.java new file mode 100644 index 0000000000000..6e81edf9661be --- /dev/null +++ b/test/hotspot/jtreg/runtime/handshake/AsyncHandshakeWalkStackTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020, 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 AsyncHandshakeWalkStackTest + * @library /testlibrary /test/lib + * @build AsyncHandshakeWalkStackTest + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AsyncHandshakeWalkStackTest + */ + +import jdk.test.lib.Asserts; +import sun.hotspot.WhiteBox; + +public class AsyncHandshakeWalkStackTest { + + public static void main(String... args) throws Exception { + int iterations = 3; + if (args.length > 0) { + iterations = Integer.parseInt(args[0]); + } + test(iterations); + } + + private static void test(int iterations) throws Exception { + Thread loop_thread = new Thread(() -> run_loop(create_list())); + Thread alloc_thread = new Thread(() -> run_alloc()); + Thread wait_thread = new Thread(() -> run_wait(new Object() {})); + loop_thread.start(); + alloc_thread.start(); + wait_thread.start(); + + WhiteBox wb = WhiteBox.getWhiteBox(); + for (int i = 0; i < iterations; i++) { + System.out.println("Iteration " + i); + System.out.flush(); + Thread.sleep(200); + wb.asyncHandshakeWalkStack(loop_thread); + Thread.sleep(200); + wb.asyncHandshakeWalkStack(alloc_thread); + Thread.sleep(200); + wb.asyncHandshakeWalkStack(wait_thread); + Thread.sleep(200); + wb.asyncHandshakeWalkStack(Thread.currentThread()); + } + } + + static class List { + List next; + + List(List next) { + this.next = next; + } + } + + public static List create_list() { + List head = new List(null); + List elem = new List(head); + List elem2 = new List(elem); + List elem3 = new List(elem2); + List elem4 = new List(elem3); + head.next = elem4; + + return head; + } + + public static void run_loop(List loop) { + while (loop.next != null) { + loop = loop.next; + } + } + + public static byte[] array; + + public static void run_alloc() { + while (true) { + // Write to public static to ensure the byte array escapes. + array = new byte[4096]; + } + } + + public static void run_wait(Object lock) { + synchronized (lock) { + try { + lock.wait(); + } catch (InterruptedException ie) {} + } + } +} diff --git a/test/hotspot/jtreg/runtime/handshake/HandshakeDirectTest.java b/test/hotspot/jtreg/runtime/handshake/HandshakeDirectTest.java index e54cd40ffb384..9939bc5a6a698 100644 --- a/test/hotspot/jtreg/runtime/handshake/HandshakeDirectTest.java +++ b/test/hotspot/jtreg/runtime/handshake/HandshakeDirectTest.java @@ -39,7 +39,7 @@ public class HandshakeDirectTest implements Runnable { static final int WORKING_THREADS = 32; - static final int DIRECT_HANDSHAKES_MARK = 50000; + static final int DIRECT_HANDSHAKES_MARK = 500000; static Thread[] workingThreads = new Thread[WORKING_THREADS]; static Semaphore[] handshakeSem = new Semaphore[WORKING_THREADS]; static Object[] locks = new Object[WORKING_THREADS]; diff --git a/test/hotspot/jtreg/runtime/handshake/MixedHandshakeWalkStackTest.java b/test/hotspot/jtreg/runtime/handshake/MixedHandshakeWalkStackTest.java new file mode 100644 index 0000000000000..09c6affafede7 --- /dev/null +++ b/test/hotspot/jtreg/runtime/handshake/MixedHandshakeWalkStackTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020, 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 MixedHandshakeWalkStackTest + * @library /testlibrary /test/lib + * @build MixedHandshakeWalkStackTest + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI MixedHandshakeWalkStackTest + */ + +import jdk.test.lib.Asserts; +import sun.hotspot.WhiteBox; + +public class MixedHandshakeWalkStackTest { + public static Thread testThreads[]; + + public static void main(String... args) throws Exception { + testThreads = new Thread[Runtime.getRuntime().availableProcessors()]; + for (int i = 0; i < testThreads.length; i++) { + testThreads[i] = new Thread(() -> handshake()); + } + + for (Thread t : testThreads) { + t.start(); + } + + handshake(); + + for (Thread t : testThreads) { + t.join(); + } + } + + public static void handshake() { + WhiteBox wb = WhiteBox.getWhiteBox(); + java.util.concurrent.ThreadLocalRandom rand = java.util.concurrent.ThreadLocalRandom.current(); + long end = System.currentTimeMillis() + 20000; + while (end > System.currentTimeMillis()) { + wb.asyncHandshakeWalkStack(testThreads[rand.nextInt(testThreads.length)]); + wb.handshakeWalkStack(testThreads[rand.nextInt(testThreads.length)], false); + wb.handshakeWalkStack(testThreads[rand.nextInt(testThreads.length)], true); + } + } +} diff --git a/test/lib/sun/hotspot/WhiteBox.java b/test/lib/sun/hotspot/WhiteBox.java index 1e048c0d35830..7b0e980f62bcf 100644 --- a/test/lib/sun/hotspot/WhiteBox.java +++ b/test/lib/sun/hotspot/WhiteBox.java @@ -587,6 +587,7 @@ public Object getMethodOption(Executable method, String name) { // Handshakes public native int handshakeWalkStack(Thread t, boolean all_threads); + public native void asyncHandshakeWalkStack(Thread t); // Returns true on linux if library has the noexecstack flag set. public native boolean checkLibSpecifiesNoexecstack(String libfilename); From 431338bcb3c2979fff049f625da732955bdbeffe Mon Sep 17 00:00:00 2001 From: Robbin Ehn Date: Tue, 29 Sep 2020 09:37:15 +0000 Subject: [PATCH 56/79] 8212107: VMThread issues and cleanup Reviewed-by: shade, dcubed, coleenp, dholmes, redestad --- .../recorder/repository/jfrEmergencyDump.cpp | 8 +- src/hotspot/share/runtime/mutexLocker.cpp | 6 +- src/hotspot/share/runtime/mutexLocker.hpp | 3 +- src/hotspot/share/runtime/thread.cpp | 2 - src/hotspot/share/runtime/thread.hpp | 8 - src/hotspot/share/runtime/vmOperations.hpp | 10 +- src/hotspot/share/runtime/vmThread.cpp | 444 ++++++++---------- src/hotspot/share/runtime/vmThread.hpp | 74 +-- 8 files changed, 221 insertions(+), 334 deletions(-) diff --git a/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp b/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp index dd2ffefff8b39..dceccf2b3cd48 100644 --- a/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp +++ b/src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp @@ -454,12 +454,8 @@ static bool prepare_for_emergency_dump(Thread* thread) { Heap_lock->unlock(); } - if (VMOperationQueue_lock->owned_by_self()) { - VMOperationQueue_lock->unlock(); - } - - if (VMOperationRequest_lock->owned_by_self()) { - VMOperationRequest_lock->unlock(); + if (VMOperation_lock->owned_by_self()) { + VMOperation_lock->unlock(); } if (Service_lock->owned_by_self()) { diff --git a/src/hotspot/share/runtime/mutexLocker.cpp b/src/hotspot/share/runtime/mutexLocker.cpp index 3d2dcc2a54666..c5fb1c61268f7 100644 --- a/src/hotspot/share/runtime/mutexLocker.cpp +++ b/src/hotspot/share/runtime/mutexLocker.cpp @@ -65,8 +65,7 @@ Monitor* CodeSweeper_lock = NULL; Mutex* MethodData_lock = NULL; Mutex* TouchedMethodLog_lock = NULL; Mutex* RetData_lock = NULL; -Monitor* VMOperationQueue_lock = NULL; -Monitor* VMOperationRequest_lock = NULL; +Monitor* VMOperation_lock = NULL; Monitor* Threads_lock = NULL; Mutex* NonJavaThreadsList_lock = NULL; Mutex* NonJavaThreadsListSync_lock = NULL; @@ -280,8 +279,7 @@ void mutex_init() { def(NonJavaThreadsList_lock , PaddedMutex, barrier, true, _safepoint_check_never); def(NonJavaThreadsListSync_lock , PaddedMutex, leaf, true, _safepoint_check_never); - def(VMOperationQueue_lock , PaddedMonitor, nonleaf, true, _safepoint_check_never); // VM_thread allowed to block on these - def(VMOperationRequest_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always); + def(VMOperation_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always); // VM_thread allowed to block on these def(RetData_lock , PaddedMutex , nonleaf, false, _safepoint_check_always); def(Terminator_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always); def(InitCompleted_lock , PaddedMonitor, leaf, true, _safepoint_check_never); diff --git a/src/hotspot/share/runtime/mutexLocker.hpp b/src/hotspot/share/runtime/mutexLocker.hpp index 26103c8590438..7cbe6419ed714 100644 --- a/src/hotspot/share/runtime/mutexLocker.hpp +++ b/src/hotspot/share/runtime/mutexLocker.hpp @@ -58,8 +58,7 @@ extern Monitor* CodeSweeper_lock; // a lock used by the sweeper o extern Mutex* MethodData_lock; // a lock on installation of method data extern Mutex* TouchedMethodLog_lock; // a lock on allocation of LogExecutedMethods info extern Mutex* RetData_lock; // a lock on installation of RetData inside method data -extern Monitor* VMOperationQueue_lock; // a lock on queue of vm_operations waiting to execute -extern Monitor* VMOperationRequest_lock; // a lock on Threads waiting for a vm_operation to terminate +extern Monitor* VMOperation_lock; // a lock on queue of vm_operations waiting to execute extern Monitor* Threads_lock; // a lock on the Threads table of active Java threads // (also used by Safepoints too to block threads creation/destruction) extern Mutex* NonJavaThreadsList_lock; // a lock on the NonJavaThreads list diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp index fc1253335ee5a..a016d391f41b4 100644 --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -255,8 +255,6 @@ Thread::Thread() { NOT_PRODUCT(_skip_gcalot = false;) _jvmti_env_iteration_count = 0; set_allocated_bytes(0); - _vm_operation_started_count = 0; - _vm_operation_completed_count = 0; _current_pending_monitor = NULL; _current_pending_monitor_is_from_java = true; _current_waiting_monitor = NULL; diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 564239c6cad60..9f431e3400151 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -401,9 +401,6 @@ class Thread: public ThreadShadow { JFR_ONLY(DEFINE_THREAD_LOCAL_FIELD_JFR;) // Thread-local data for jfr - int _vm_operation_started_count; // VM_Operation support - int _vm_operation_completed_count; // VM_Operation support - ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread // is waiting to lock bool _current_pending_monitor_is_from_java; // locking is from Java code @@ -621,11 +618,6 @@ class Thread: public ThreadShadow { bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; } - // VM operation support - int vm_operation_ticket() { return ++_vm_operation_started_count; } - int vm_operation_completed_count() { return _vm_operation_completed_count; } - void increment_vm_operation_completed_count() { _vm_operation_completed_count++; } - // For tracking the heavyweight monitor the thread is pending on. ObjectMonitor* current_pending_monitor() { return _current_pending_monitor; diff --git a/src/hotspot/share/runtime/vmOperations.hpp b/src/hotspot/share/runtime/vmOperations.hpp index 2e55a5fa953a1..0e81a5ae00afe 100644 --- a/src/hotspot/share/runtime/vmOperations.hpp +++ b/src/hotspot/share/runtime/vmOperations.hpp @@ -121,14 +121,12 @@ class VM_Operation : public StackObj { private: Thread* _calling_thread; - VM_Operation* _next; - VM_Operation* _prev; // The VM operation name array static const char* _names[]; public: - VM_Operation() : _calling_thread(NULL), _next(NULL), _prev(NULL) {} + VM_Operation() : _calling_thread(NULL) {} // VM operation support (used by VM thread) Thread* calling_thread() const { return _calling_thread; } @@ -148,12 +146,6 @@ class VM_Operation : public StackObj { virtual bool doit_prologue() { return true; }; virtual void doit_epilogue() {}; - // Linking - VM_Operation *next() const { return _next; } - VM_Operation *prev() const { return _prev; } - void set_next(VM_Operation *next) { _next = next; } - void set_prev(VM_Operation *prev) { _prev = prev; } - // Configuration. Override these appropriately in subclasses. virtual VMOp_Type type() const = 0; virtual bool allow_nested_vm_operations() const { return false; } diff --git a/src/hotspot/share/runtime/vmThread.cpp b/src/hotspot/share/runtime/vmThread.cpp index f9eae673b3670..57d2f1d7c70c1 100644 --- a/src/hotspot/share/runtime/vmThread.cpp +++ b/src/hotspot/share/runtime/vmThread.cpp @@ -24,7 +24,6 @@ #include "precompiled.hpp" #include "compiler/compileBroker.hpp" -#include "gc/shared/collectedHeap.hpp" #include "jfr/jfrEvents.hpp" #include "jfr/support/jfrThreadId.hpp" #include "logging/log.hpp" @@ -32,7 +31,6 @@ #include "logging/logConfiguration.hpp" #include "memory/resourceArea.hpp" #include "memory/universe.hpp" -#include "oops/method.hpp" #include "oops/oop.inline.hpp" #include "oops/verifyOopClosure.hpp" #include "runtime/atomic.hpp" @@ -43,101 +41,13 @@ #include "runtime/safepoint.hpp" #include "runtime/synchronizer.hpp" #include "runtime/thread.inline.hpp" +#include "runtime/timerTrace.hpp" #include "runtime/vmThread.hpp" #include "runtime/vmOperations.hpp" -#include "services/runtimeService.hpp" #include "utilities/dtrace.hpp" #include "utilities/events.hpp" #include "utilities/vmError.hpp" -#include "utilities/xmlstream.hpp" - -VM_QueueHead VMOperationQueue::_queue_head[VMOperationQueue::nof_priorities]; - -VMOperationQueue::VMOperationQueue() { - // The queue is a circular doubled-linked list, which always contains - // one element (i.e., one element means empty). - for(int i = 0; i < nof_priorities; i++) { - _queue_length[i] = 0; - _queue_counter = 0; - _queue[i] = &_queue_head[i]; - _queue[i]->set_next(_queue[i]); - _queue[i]->set_prev(_queue[i]); - } -} - - -bool VMOperationQueue::queue_empty(int prio) { - // It is empty if there is exactly one element - bool empty = (_queue[prio] == _queue[prio]->next()); - assert( (_queue_length[prio] == 0 && empty) || - (_queue_length[prio] > 0 && !empty), "sanity check"); - return _queue_length[prio] == 0; -} - -// Inserts an element to the right of the q element -void VMOperationQueue::insert(VM_Operation* q, VM_Operation* n) { - assert(q->next()->prev() == q && q->prev()->next() == q, "sanity check"); - n->set_prev(q); - n->set_next(q->next()); - q->next()->set_prev(n); - q->set_next(n); -} - -void VMOperationQueue::queue_add(int prio, VM_Operation *op) { - _queue_length[prio]++; - insert(_queue[prio]->prev(), op); -} - - -void VMOperationQueue::unlink(VM_Operation* q) { - assert(q->next()->prev() == q && q->prev()->next() == q, "sanity check"); - q->prev()->set_next(q->next()); - q->next()->set_prev(q->prev()); -} - -VM_Operation* VMOperationQueue::queue_remove_front(int prio) { - if (queue_empty(prio)) return NULL; - assert(_queue_length[prio] >= 0, "sanity check"); - _queue_length[prio]--; - VM_Operation* r = _queue[prio]->next(); - assert(r != _queue[prio], "cannot remove base element"); - unlink(r); - return r; -} - -//----------------------------------------------------------------- -// High-level interface -void VMOperationQueue::add(VM_Operation *op) { - - HOTSPOT_VMOPS_REQUEST( - (char *) op->name(), strlen(op->name()), - op->evaluate_at_safepoint() ? 0 : 1); - - // Encapsulates VM queue policy. Currently, that - // only involves putting them on the right list - queue_add(op->evaluate_at_safepoint() ? SafepointPriority : MediumPriority, op); -} - -VM_Operation* VMOperationQueue::remove_next() { - // Assuming VMOperation queue is two-level priority queue. If there are - // more than two priorities, we need a different scheduling algorithm. - assert(SafepointPriority == 0 && MediumPriority == 1 && nof_priorities == 2, - "current algorithm does not work"); - - // simple counter based scheduling to prevent starvation of lower priority - // queue. -- see 4390175 - int high_prio, low_prio; - if (_queue_counter++ < 10) { - high_prio = SafepointPriority; - low_prio = MediumPriority; - } else { - _queue_counter = 0; - high_prio = MediumPriority; - low_prio = SafepointPriority; - } - return queue_remove_front(queue_empty(high_prio) ? low_prio : high_prio); -} //------------------------------------------------------------------------------------------------------------------ // Timeout machinery @@ -169,12 +79,15 @@ void VMOperationTimeoutTask::disarm() { //------------------------------------------------------------------------------------------------------------------ // Implementation of VMThread stuff +static VM_None safepointALot_op("SafepointALot"); +static VM_Cleanup cleanup_op; + bool VMThread::_should_terminate = false; bool VMThread::_terminated = false; Monitor* VMThread::_terminate_lock = NULL; VMThread* VMThread::_vm_thread = NULL; VM_Operation* VMThread::_cur_vm_operation = NULL; -VMOperationQueue* VMThread::_vm_queue = NULL; +VM_Operation* VMThread::_next_vm_operation = &cleanup_op; // Prevent any thread from setting an operation until VM thread is ready. PerfCounter* VMThread::_perf_accumulated_vm_operation_time = NULL; VMOperationTimeoutTask* VMThread::_timeout_task = NULL; @@ -198,10 +111,6 @@ void VMThread::create() { assert(_timeout_task == NULL, "sanity"); } - // Create VM operation queue - _vm_queue = new VMOperationQueue(); - guarantee(_vm_queue != NULL, "just checking"); - _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true, Monitor::_safepoint_check_never); @@ -310,9 +219,10 @@ void VMThread::run() { // and wait until operation is performed. void VMThread::wait_for_vm_thread_exit() { assert(JavaThread::current()->is_terminated(), "Should be terminated"); - { MonitorLocker mu(VMOperationQueue_lock, Mutex::_no_safepoint_check_flag); + { + MonitorLocker mu(VMOperation_lock); _should_terminate = true; - mu.notify(); + mu.notify_all(); } // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint @@ -324,8 +234,9 @@ void VMThread::wait_for_vm_thread_exit() { // Note: it should be OK to use Terminator_lock here. But this is called // at a very delicate time (VM shutdown) and we are operating in non- VM // thread at Safepoint. It's safer to not share lock with other threads. - { MonitorLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag); - while(!VMThread::is_terminated()) { + { + MonitorLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag); + while (!VMThread::is_terminated()) { ml.wait(); } } @@ -364,13 +275,8 @@ void VMThread::evaluate_operation(VM_Operation* op) { op->evaluate_at_safepoint() ? 0 : 1); } - // Mark as completed - op->calling_thread()->increment_vm_operation_completed_count(); } -static VM_None safepointALot_op("SafepointALot"); -static VM_Cleanup cleanup_op; - class HandshakeALotClosure : public HandshakeClosure { public: HandshakeALotClosure() : HandshakeClosure("HandshakeALot") {} @@ -381,119 +287,198 @@ class HandshakeALotClosure : public HandshakeClosure { } }; -VM_Operation* VMThread::no_op_safepoint() { - // Check for handshakes first since we may need to return a VMop. - if (HandshakeALot) { - HandshakeALotClosure hal_cl; - Handshake::execute(&hal_cl); +bool VMThread::handshake_alot() { + assert(_cur_vm_operation == NULL, "should not have an op yet"); + assert(_next_vm_operation == NULL, "should not have an op yet"); + if (!HandshakeALot) { + return false; } + static jlong last_halot_ms = 0; + jlong now_ms = nanos_to_millis(os::javaTimeNanos()); + // If only HandshakeALot is set, but GuaranteedSafepointInterval is 0, + // we emit a handshake if it's been more than a second since the last one. + jlong interval = GuaranteedSafepointInterval != 0 ? GuaranteedSafepointInterval : 1000; + jlong deadline_ms = interval + last_halot_ms; + if (now_ms > deadline_ms) { + last_halot_ms = now_ms; + return true; + } + return false; +} + +void VMThread::setup_periodic_safepoint_if_needed() { + assert(_cur_vm_operation == NULL, "Already have an op"); + assert(_next_vm_operation == NULL, "Already have an op"); // Check for a cleanup before SafepointALot to keep stats correct. long interval_ms = SafepointTracing::time_since_last_safepoint_ms(); bool max_time_exceeded = GuaranteedSafepointInterval != 0 && (interval_ms >= GuaranteedSafepointInterval); - if (max_time_exceeded && SafepointSynchronize::is_cleanup_needed()) { - return &cleanup_op; + if (!max_time_exceeded) { + return; } - if (SafepointALot) { - return &safepointALot_op; + if (SafepointSynchronize::is_cleanup_needed()) { + _next_vm_operation = &cleanup_op; + } else if (SafepointALot) { + _next_vm_operation = &safepointALot_op; } - // Nothing to be done. - return NULL; } -void VMThread::loop() { - assert(_cur_vm_operation == NULL, "no current one should be executing"); +bool VMThread::set_next_operation(VM_Operation *op) { + if (_next_vm_operation != NULL) { + return false; + } + log_debug(vmthread)("Adding VM operation: %s", op->name()); - SafepointSynchronize::init(_vm_thread); + _next_vm_operation = op; + + HOTSPOT_VMOPS_REQUEST( + (char *) op->name(), strlen(op->name()), + op->evaluate_at_safepoint() ? 0 : 1); + return true; +} - while(true) { - // - // Wait for VM operation - // - // use no_safepoint_check to get lock without attempting to "sneak" - { MonitorLocker mu_queue(VMOperationQueue_lock, - Mutex::_no_safepoint_check_flag); - - // Look for new operation - assert(_cur_vm_operation == NULL, "no current one should be executing"); - _cur_vm_operation = _vm_queue->remove_next(); - - while (!should_terminate() && _cur_vm_operation == NULL) { - // wait with a timeout to guarantee safepoints at regular intervals - // (if there is cleanup work to do) - (void)mu_queue.wait(GuaranteedSafepointInterval); - - // Support for self destruction - if ((SelfDestructTimer != 0) && !VMError::is_error_reported() && - (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) { - tty->print_cr("VM self-destructed"); - exit(-1); - } - - // If the queue contains a safepoint VM op, - // clean up will be done so we can skip this part. - if (!_vm_queue->peek_at_safepoint_priority()) { - - // Have to unlock VMOperationQueue_lock just in case no_op_safepoint() - // has to do a handshake when HandshakeALot is enabled. - MutexUnlocker mul(VMOperationQueue_lock, Mutex::_no_safepoint_check_flag); - if ((_cur_vm_operation = VMThread::no_op_safepoint()) != NULL) { - // Force a safepoint since we have not had one for at least - // 'GuaranteedSafepointInterval' milliseconds and we need to clean - // something. This will run all the clean-up processing that needs - // to be done at a safepoint. - SafepointSynchronize::begin(); - SafepointSynchronize::end(); - _cur_vm_operation = NULL; - } - } - _cur_vm_operation = _vm_queue->remove_next(); +void VMThread::wait_until_executed(VM_Operation* op) { + MonitorLocker ml(VMOperation_lock, + Thread::current()->is_Java_thread() ? + Mutex::_safepoint_check_flag : + Mutex::_no_safepoint_check_flag); + { + TraceTime timer("Installing VM operation", TRACETIME_LOG(Trace, vmthread)); + while (true) { + if (VMThread::vm_thread()->set_next_operation(op)) { + ml.notify_all(); + break; } + // Wait to install this operation as the next operation in the VM Thread + log_trace(vmthread)("A VM operation already set, waiting"); + ml.wait(); + } + } + { + // Wait until the operation has been processed + TraceTime timer("Waiting for VM operation to be completed", TRACETIME_LOG(Trace, vmthread)); + // _next_vm_operation is cleared holding VMOperation_lock after it has been + // executed. We wait until _next_vm_operation is not our op. + while (_next_vm_operation == op) { + // VM Thread can process it once we unlock the mutex on wait. + ml.wait(); + } + } +} - if (should_terminate()) break; - } // Release mu_queue_lock +static void self_destruct_if_needed() { + // Support for self destruction + if ((SelfDestructTimer != 0) && !VMError::is_error_reported() && + (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) { + tty->print_cr("VM self-destructed"); + exit(-1); + } +} - // - // Execute VM operation - // - { HandleMark hm(VMThread::vm_thread()); +void VMThread::inner_execute(VM_Operation* op) { + assert(Thread::current()->is_VM_thread(), "Must be the VM thread"); + + VM_Operation* prev_vm_operation = NULL; + if (_cur_vm_operation != NULL) { + // Check that the VM operation allows nested VM operation. + // This is normally not the case, e.g., the compiler + // does not allow nested scavenges or compiles. + if (!_cur_vm_operation->allow_nested_vm_operations()) { + fatal("Unexpected nested VM operation %s requested by operation %s", + op->name(), _cur_vm_operation->name()); + } + op->set_calling_thread(_cur_vm_operation->calling_thread()); + prev_vm_operation = _cur_vm_operation; + } - EventMark em("Executing VM operation: %s", vm_operation()->name()); - assert(_cur_vm_operation != NULL, "we should have found an operation to execute"); + _cur_vm_operation = op; - // If we are at a safepoint we will evaluate all the operations that - // follow that also require a safepoint - if (_cur_vm_operation->evaluate_at_safepoint()) { - log_debug(vmthread)("Evaluating safepoint VM operation: %s", _cur_vm_operation->name()); + HandleMark hm(VMThread::vm_thread()); + EventMark em("Executing %s VM operation: %s", prev_vm_operation != NULL ? "nested" : "", op->name()); - SafepointSynchronize::begin(); + log_debug(vmthread)("Evaluating %s %s VM operation: %s", + prev_vm_operation != NULL ? "nested" : "", + _cur_vm_operation->evaluate_at_safepoint() ? "safepoint" : "non-safepoint", + _cur_vm_operation->name()); - if (_timeout_task != NULL) { - _timeout_task->arm(); - } + bool end_safepoint = false; + if (_cur_vm_operation->evaluate_at_safepoint() && + !SafepointSynchronize::is_at_safepoint()) { + SafepointSynchronize::begin(); + if (_timeout_task != NULL) { + _timeout_task->arm(); + } + end_safepoint = true; + } - evaluate_operation(_cur_vm_operation); - _cur_vm_operation = NULL; + evaluate_operation(_cur_vm_operation); - if (_timeout_task != NULL) { - _timeout_task->disarm(); - } + if (end_safepoint) { + if (_timeout_task != NULL) { + _timeout_task->disarm(); + } + SafepointSynchronize::end(); + } - // Complete safepoint synchronization - SafepointSynchronize::end(); + _cur_vm_operation = prev_vm_operation; +} + +void VMThread::wait_for_operation() { + assert(Thread::current()->is_VM_thread(), "Must be the VM thread"); + MonitorLocker ml_op_lock(VMOperation_lock, Mutex::_no_safepoint_check_flag); + + // Clear previous operation. + // On first call this clears a dummy place-holder. + _next_vm_operation = NULL; + // Notify operation is done and notify a next operation can be installed. + ml_op_lock.notify_all(); - } else { // not a safepoint operation - log_debug(vmthread)("Evaluating non-safepoint VM operation: %s", _cur_vm_operation->name()); - evaluate_operation(_cur_vm_operation); - _cur_vm_operation = NULL; + while (!should_terminate()) { + self_destruct_if_needed(); + if (_next_vm_operation != NULL) { + return; + } + if (handshake_alot()) { + { + MutexUnlocker mul(VMOperation_lock); + HandshakeALotClosure hal_cl; + Handshake::execute(&hal_cl); + } + // When we unlocked above someone might have setup a new op. + if (_next_vm_operation != NULL) { + return; } } + assert(_next_vm_operation == NULL, "Must be"); + assert(_cur_vm_operation == NULL, "Must be"); - // - // Notify (potential) waiting Java thread(s) - { MonitorLocker mu(VMOperationRequest_lock, Mutex::_no_safepoint_check_flag); - mu.notify_all(); + setup_periodic_safepoint_if_needed(); + if (_next_vm_operation != NULL) { + return; } + + // We didn't find anything to execute, notify any waiter so they can install an op. + ml_op_lock.notify_all(); + ml_op_lock.wait(GuaranteedSafepointInterval); + } +} + +void VMThread::loop() { + assert(_cur_vm_operation == NULL, "no current one should be executing"); + + SafepointSynchronize::init(_vm_thread); + + // Need to set a calling thread for ops not passed + // via the normal way. + cleanup_op.set_calling_thread(_vm_thread); + safepointALot_op.set_calling_thread(_vm_thread); + + while (true) { + if (should_terminate()) break; + wait_for_operation(); + if (should_terminate()) break; + assert(_next_vm_operation != NULL, "Must have one"); + inner_execute(_next_vm_operation); } } @@ -525,71 +510,28 @@ class SkipGCALot : public StackObj { void VMThread::execute(VM_Operation* op) { Thread* t = Thread::current(); - if (!t->is_VM_thread()) { - SkipGCALot sgcalot(t); // avoid re-entrant attempts to gc-a-lot - // JavaThread or WatcherThread - t->check_for_valid_safepoint_state(); - - // New request from Java thread, evaluate prologue - if (!op->doit_prologue()) { - return; // op was cancelled - } - - // Setup VM_operations for execution + if (t->is_VM_thread()) { op->set_calling_thread(t); + ((VMThread*)t)->inner_execute(op); + return; + } - // Get ticket number for the VM operation - int ticket = t->vm_operation_ticket(); - - // Add VM operation to list of waiting threads. We are guaranteed not to block while holding the - // VMOperationQueue_lock, so we can block without a safepoint check. This allows vm operation requests - // to be queued up during a safepoint synchronization. - { - MonitorLocker ml(VMOperationQueue_lock, Mutex::_no_safepoint_check_flag); - log_debug(vmthread)("Adding VM operation: %s", op->name()); - _vm_queue->add(op); - ml.notify(); - } - { - // Wait for completion of request - // Note: only a JavaThread triggers the safepoint check when locking - MonitorLocker ml(VMOperationRequest_lock, - t->is_Java_thread() ? Mutex::_safepoint_check_flag : Mutex::_no_safepoint_check_flag); - while(t->vm_operation_completed_count() < ticket) { - ml.wait(); - } - } - op->doit_epilogue(); - } else { - // invoked by VM thread; usually nested VM operation - assert(t->is_VM_thread(), "must be a VM thread"); - VM_Operation* prev_vm_operation = vm_operation(); - if (prev_vm_operation != NULL) { - // Check the VM operation allows nested VM operation. This normally not the case, e.g., the compiler - // does not allow nested scavenges or compiles. - if (!prev_vm_operation->allow_nested_vm_operations()) { - fatal("Nested VM operation %s requested by operation %s", - op->name(), vm_operation()->name()); - } - op->set_calling_thread(prev_vm_operation->calling_thread()); - } + // Avoid re-entrant attempts to gc-a-lot + SkipGCALot sgcalot(t); - EventMark em("Executing %s VM operation: %s", prev_vm_operation ? "nested" : "", op->name()); + // JavaThread or WatcherThread + t->check_for_valid_safepoint_state(); - // Release all internal handles after operation is evaluated - HandleMark hm(t); - _cur_vm_operation = op; + // New request from Java thread, evaluate prologue + if (!op->doit_prologue()) { + return; // op was cancelled + } - if (op->evaluate_at_safepoint() && !SafepointSynchronize::is_at_safepoint()) { - SafepointSynchronize::begin(); - op->evaluate(); - SafepointSynchronize::end(); - } else { - op->evaluate(); - } + op->set_calling_thread(t); - _cur_vm_operation = prev_vm_operation; - } + wait_until_executed(op); + + op->doit_epilogue(); } void VMThread::verify() { diff --git a/src/hotspot/share/runtime/vmThread.hpp b/src/hotspot/share/runtime/vmThread.hpp index 0f14ae30ea3db..c6188fd3ac112 100644 --- a/src/hotspot/share/runtime/vmThread.hpp +++ b/src/hotspot/share/runtime/vmThread.hpp @@ -30,53 +30,6 @@ #include "runtime/task.hpp" #include "runtime/vmOperations.hpp" -class VM_QueueHead : public VM_None { - public: - VM_QueueHead() : VM_None("QueueHead") {} -}; - -// -// Prioritized queue of VM operations. -// -// Encapsulates both queue management and -// and priority policy -// -class VMOperationQueue : public CHeapObj { - private: - enum Priorities { - SafepointPriority, // Highest priority (operation executed at a safepoint) - MediumPriority, // Medium priority - nof_priorities - }; - - // We maintain a doubled linked list, with explicit count. - int _queue_length[nof_priorities]; - int _queue_counter; - VM_Operation* _queue [nof_priorities]; - - static VM_QueueHead _queue_head[nof_priorities]; - - // Double-linked non-empty list insert. - void insert(VM_Operation* q,VM_Operation* n); - void unlink(VM_Operation* q); - - // Basic queue manipulation - bool queue_empty (int prio); - void queue_add (int prio, VM_Operation *op); - VM_Operation* queue_remove_front(int prio); - // lock-free query: may return the wrong answer but must not break - bool queue_peek(int prio) { return _queue_length[prio] > 0; } - - public: - VMOperationQueue(); - - // Highlevel operations. Encapsulates policy - void add(VM_Operation *op); - VM_Operation* remove_next(); // Returns next or null - bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); } -}; - - // VM operation timeout handling: warn or abort the VM when VM operation takes // too long. Periodic tasks do not participate in safepoint protocol, and therefore // can fire when application threads are stopped. @@ -114,9 +67,12 @@ class VMThread: public NamedThread { static VMOperationTimeoutTask* _timeout_task; - static VM_Operation* no_op_safepoint(); + static bool handshake_alot(); + static void setup_periodic_safepoint_if_needed(); void evaluate_operation(VM_Operation* op); + void inner_execute(VM_Operation* op); + void wait_for_operation(); public: // Constructor @@ -143,8 +99,16 @@ class VMThread: public NamedThread { static void execute(VM_Operation* op); // Returns the current vm operation if any. - static VM_Operation* vm_operation() { return _cur_vm_operation; } - static VM_Operation::VMOp_Type vm_op_type() { return _cur_vm_operation->type(); } + static VM_Operation* vm_operation() { + assert(Thread::current()->is_VM_thread(), "Must be"); + return _cur_vm_operation; + } + + static VM_Operation::VMOp_Type vm_op_type() { + VM_Operation* op = vm_operation(); + assert(op != NULL, "sanity"); + return op->type(); + } // Returns the single instance of VMThread. static VMThread* vm_thread() { return _vm_thread; } @@ -152,7 +116,9 @@ class VMThread: public NamedThread { void verify(); // Performance measurement - static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; } + static PerfCounter* perf_accumulated_vm_operation_time() { + return _perf_accumulated_vm_operation_time; + } // Entry for starting vm thread virtual void run(); @@ -161,10 +127,14 @@ class VMThread: public NamedThread { static void create(); static void destroy(); + static void wait_until_executed(VM_Operation* op); + private: // VM_Operation support static VM_Operation* _cur_vm_operation; // Current VM operation - static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations + static VM_Operation* _next_vm_operation; // Next VM operation + + bool set_next_operation(VM_Operation *op); // Set the _next_vm_operation if possible. // Pointer to single-instance of VM thread static VMThread* _vm_thread; From ebf443a16fb71486037e39996cd0439576927d8a Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Tue, 29 Sep 2020 09:40:21 +0000 Subject: [PATCH 57/79] 8253590: java/foreign tests are still failing on x86_32 after foreign-memaccess integration Reviewed-by: psandoz --- test/jdk/java/foreign/TestArrays.java | 9 +++++---- test/jdk/java/foreign/TestByteBuffer.java | 7 +++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/jdk/java/foreign/TestArrays.java b/test/jdk/java/foreign/TestArrays.java index 96397bd041b19..2a5d597b858a5 100644 --- a/test/jdk/java/foreign/TestArrays.java +++ b/test/jdk/java/foreign/TestArrays.java @@ -24,7 +24,7 @@ /* * @test - * @run testng TestArrays + * @run testng/othervm -Dforeign.restricted=permit TestArrays */ import jdk.incubator.foreign.MemoryAddress; @@ -105,10 +105,11 @@ public void testArrays(Consumer init, SequenceLayout layout) { } } - @Test(expectedExceptions = { UnsupportedOperationException.class, - IllegalArgumentException.class }) + @Test(expectedExceptions = UnsupportedOperationException.class) public void testTooBigForArray() { - MemorySegment.allocateNative((long) Integer.MAX_VALUE * 2).toByteArray(); + try (MemorySegment segment = MemorySegment.ofNativeRestricted(MemoryAddress.NULL, (long)Integer.MAX_VALUE + 10L, null, null, null)) { + segment.toByteArray(); + } } @Test(expectedExceptions = IllegalStateException.class) diff --git a/test/jdk/java/foreign/TestByteBuffer.java b/test/jdk/java/foreign/TestByteBuffer.java index 984763907a672..5960d95a5d409 100644 --- a/test/jdk/java/foreign/TestByteBuffer.java +++ b/test/jdk/java/foreign/TestByteBuffer.java @@ -27,7 +27,7 @@ * @test * @modules java.base/sun.nio.ch * jdk.incubator.foreign/jdk.internal.foreign - * @run testng TestByteBuffer + * @run testng/othervm -Dforeign.restricted=permit TestByteBuffer */ @@ -458,10 +458,9 @@ public void testBufferOnClosedScope() { byteBuffer.get(); // should throw } - @Test(expectedExceptions = { UnsupportedOperationException.class, - IllegalArgumentException.class }) + @Test(expectedExceptions = UnsupportedOperationException.class) public void testTooBigForByteBuffer() { - try (MemorySegment segment = MemorySegment.allocateNative((long)Integer.MAX_VALUE + 10L)) { + try (MemorySegment segment = MemorySegment.ofNativeRestricted(MemoryAddress.NULL, (long)Integer.MAX_VALUE + 10L, null, null, null)) { segment.asByteBuffer(); } } From 86491a5f6b2958480a73183b9a4a29ef55d3a569 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 29 Sep 2020 10:11:08 +0000 Subject: [PATCH 58/79] 8253584: Redunant errors for partial member selects Reviewed-by: vromero --- .../sun/tools/javac/parser/JavacParser.java | 5 +- .../tools/javac/parser/JavacParserTest.java | 49 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 4ffef19e08158..3f9fa813071f2 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -567,7 +567,7 @@ public Name ident() { return ident(false); } - protected Name ident(boolean advanceOnErrors) { + protected Name ident(boolean allowClass) { if (token.kind == IDENTIFIER) { Name name = token.name(); nextToken(); @@ -603,8 +603,9 @@ protected Name ident(boolean advanceOnErrors) { return name; } else { accept(IDENTIFIER); - if (advanceOnErrors) { + if (allowClass && token.kind == CLASS) { nextToken(); + return names._class; } return names.error; } diff --git a/test/langtools/tools/javac/parser/JavacParserTest.java b/test/langtools/tools/javac/parser/JavacParserTest.java index d50e2eb40da5e..b58a7cb0361c6 100644 --- a/test/langtools/tools/javac/parser/JavacParserTest.java +++ b/test/langtools/tools/javac/parser/JavacParserTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 + * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 * @summary tests error and diagnostics positions * @author Jan Lahoda * @modules jdk.compiler/com.sun.tools.javac.api @@ -1564,6 +1564,53 @@ public class B { assertEquals("Unexpected AST, got:\n" + ast, expected, ast); } + @Test //JDK-8253584 + void testElseRecovery() throws IOException { + //verify the errors and AST form produced for member selects which are + //missing the selected member name: + String code = """ + package t; + class Test { + void t() { + if (true) { + s(). + } else { + } + } + String s() { + return null; + } + } + """; + StringWriter out = new StringWriter(); + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(out, fm, null, List.of("-XDrawDiagnostics"), + null, Arrays.asList(new MyFileObject(code))); + String ast = ct.parse().iterator().next().toString().replaceAll("\\R", "\n"); + String expected = """ + package t; + \n\ + class Test { + \n\ + void t() { + if (true) { + (ERROR); + } else { + } + } + \n\ + String s() { + return null; + } + } """; + assertEquals("Unexpected AST, got:\n" + ast, expected, ast); + assertEquals("Unexpected errors, got:\n" + out.toString(), + out.toString(), + """ + Test.java:5:17: compiler.err.expected: token.identifier + Test.java:5:16: compiler.err.not.stmt + """); + } + void run(String[] args) throws Exception { int passed = 0, failed = 0; final Pattern p = (args != null && args.length > 0) From 3ed960ec77f3f2d9df3244806ae0fe635052dbd6 Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Tue, 29 Sep 2020 12:03:00 +0000 Subject: [PATCH 59/79] 8253640: Make MEMFLAGS an enum class Reviewed-by: stuefe, tschatzl --- .../share/gc/g1/g1RegionToSpaceMapper.cpp | 12 +++++------ .../share/gc/g1/g1RegionToSpaceMapper.hpp | 12 +++++------ src/hotspot/share/memory/allocation.hpp | 10 ++++++++-- src/hotspot/share/services/mallocTracker.hpp | 8 +------- src/hotspot/share/services/memBaseline.cpp | 2 +- src/hotspot/share/services/memReporter.cpp | 2 +- src/hotspot/share/services/nmtCommon.hpp | 20 ++++++++++++++----- .../share/services/virtualMemoryTracker.hpp | 6 ------ 8 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp index d0cc97424d7fa..88907a6f87fc1 100644 --- a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp +++ b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp @@ -42,7 +42,7 @@ G1RegionToSpaceMapper::G1RegionToSpaceMapper(ReservedSpace rs, size_t page_size, size_t region_granularity, size_t commit_factor, - MemoryType type) : + MEMFLAGS type) : _listener(NULL), _storage(rs, used_size, page_size), _region_granularity(region_granularity), @@ -67,7 +67,7 @@ class G1RegionsLargerThanCommitSizeMapper : public G1RegionToSpaceMapper { size_t page_size, size_t alloc_granularity, size_t commit_factor, - MemoryType type) : + MEMFLAGS type) : G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type), _pages_per_region(alloc_granularity / (page_size * commit_factor)) { @@ -130,7 +130,7 @@ class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper { size_t page_size, size_t alloc_granularity, size_t commit_factor, - MemoryType type) : + MEMFLAGS type) : G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type), _regions_per_page((page_size * commit_factor) / alloc_granularity) { @@ -240,7 +240,7 @@ G1RegionToHeteroSpaceMapper::G1RegionToHeteroSpaceMapper(ReservedSpace rs, size_t page_size, size_t alloc_granularity, size_t commit_factor, - MemoryType type) : + MEMFLAGS type) : G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type), _rs(rs), _dram_mapper(NULL), @@ -337,7 +337,7 @@ G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_heap_mapper(ReservedSpace r size_t page_size, size_t region_granularity, size_t commit_factor, - MemoryType type) { + MEMFLAGS type) { if (AllocateOldGenAt != NULL) { G1RegionToHeteroSpaceMapper* mapper = new G1RegionToHeteroSpaceMapper(rs, actual_size, page_size, region_granularity, commit_factor, type); if (!mapper->initialize()) { @@ -355,7 +355,7 @@ G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_mapper(ReservedSpace rs, size_t page_size, size_t region_granularity, size_t commit_factor, - MemoryType type) { + MEMFLAGS type) { if (region_granularity >= (page_size * commit_factor)) { return new G1RegionsLargerThanCommitSizeMapper(rs, actual_size, page_size, region_granularity, commit_factor, type); } else { diff --git a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.hpp b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.hpp index 87ffae6172b14..7a76d4eea9385 100644 --- a/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.hpp +++ b/src/hotspot/share/gc/g1/g1RegionToSpaceMapper.hpp @@ -53,9 +53,9 @@ class G1RegionToSpaceMapper : public CHeapObj { // Mapping management CHeapBitMap _region_commit_map; - MemoryType _memory_type; + MEMFLAGS _memory_type; - G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MemoryType type); + G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MEMFLAGS type); void fire_on_commit(uint start_idx, size_t num_regions, bool zero_filled); public: @@ -85,14 +85,14 @@ class G1RegionToSpaceMapper : public CHeapObj { size_t page_size, size_t region_granularity, size_t byte_translation_factor, - MemoryType type); + MEMFLAGS type); static G1RegionToSpaceMapper* create_heap_mapper(ReservedSpace rs, size_t actual_size, size_t page_size, size_t region_granularity, size_t byte_translation_factor, - MemoryType type); + MEMFLAGS type); }; // G1RegionToSpaceMapper implementation where @@ -106,10 +106,10 @@ class G1RegionToHeteroSpaceMapper : public G1RegionToSpaceMapper { uint _start_index_of_dram; size_t _page_size; size_t _commit_factor; - MemoryType _type; + MEMFLAGS _type; public: - G1RegionToHeteroSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MemoryType type); + G1RegionToHeteroSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MEMFLAGS type); bool initialize(); uint num_committed_dram() const; uint num_committed_nvdimm() const; diff --git a/src/hotspot/share/memory/allocation.hpp b/src/hotspot/share/memory/allocation.hpp index 617c47c4c9e6b..9ba938f948d5e 100644 --- a/src/hotspot/share/memory/allocation.hpp +++ b/src/hotspot/share/memory/allocation.hpp @@ -151,14 +151,20 @@ class AllocatedObj { /* * Memory types */ -enum MemoryType { +enum class MEMFLAGS { MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_ENUM) mt_number_of_types // number of memory types (mtDontTrack // is not included as validate type) }; -typedef MemoryType MEMFLAGS; +#define MEMORY_TYPE_SHORTNAME(type, human_readable) \ + constexpr MEMFLAGS type = MEMFLAGS::type; +// Generate short aliases for the enum values. E.g. mtGC instead of MEMFLAGS::mtGC. +MEMORY_TYPES_DO(MEMORY_TYPE_SHORTNAME) + +// Make an int version of the sentinel end value. +constexpr int mt_number_of_types = static_cast(MEMFLAGS::mt_number_of_types); #if INCLUDE_NMT diff --git a/src/hotspot/share/services/mallocTracker.hpp b/src/hotspot/share/services/mallocTracker.hpp index bd3063e940782..acfaa3a880d1a 100644 --- a/src/hotspot/share/services/mallocTracker.hpp +++ b/src/hotspot/share/services/mallocTracker.hpp @@ -145,12 +145,6 @@ class MallocMemorySnapshot : public ResourceObj { return &_malloc[index]; } - inline MallocMemory* by_index(int index) { - assert(index >= 0, "Index out of bound"); - assert(index < mt_number_of_types, "Index out of bound"); - return &_malloc[index]; - } - inline MemoryCounter* malloc_overhead() { return &_tracking_header; } @@ -269,7 +263,7 @@ class MallocHeader { return; } - _flags = flags; + _flags = NMTUtil::flag_to_index(flags); set_size(size); if (level == NMT_detail) { size_t bucket_idx; diff --git a/src/hotspot/share/services/memBaseline.cpp b/src/hotspot/share/services/memBaseline.cpp index 8fc191822d2ba..b390eaca4b840 100644 --- a/src/hotspot/share/services/memBaseline.cpp +++ b/src/hotspot/share/services/memBaseline.cpp @@ -64,7 +64,7 @@ int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) { int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) { int res = compare_malloc_site(s1, s2); if (res == 0) { - res = (int)(s1.flag() - s2.flag()); + res = (int)(NMTUtil::flag_to_index(s1.flag()) - NMTUtil::flag_to_index(s2.flag())); } return res; diff --git a/src/hotspot/share/services/memReporter.cpp b/src/hotspot/share/services/memReporter.cpp index 5bd5f7b0117c3..d0a8caa8ae841 100644 --- a/src/hotspot/share/services/memReporter.cpp +++ b/src/hotspot/share/services/memReporter.cpp @@ -261,7 +261,7 @@ void MemDetailReporter::report_malloc_sites() { stack->print_on(out); out->print("%29s", " "); MEMFLAGS flag = malloc_site->flag(); - assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone, + assert(NMTUtil::flag_is_valid(flag) && flag != mtNone, "Must have a valid memory type"); print_malloc(malloc_site->size(), malloc_site->count(),flag); out->print_cr("\n"); diff --git a/src/hotspot/share/services/nmtCommon.hpp b/src/hotspot/share/services/nmtCommon.hpp index ea2f396fa8bb0..7d4f02f1217ab 100644 --- a/src/hotspot/share/services/nmtCommon.hpp +++ b/src/hotspot/share/services/nmtCommon.hpp @@ -47,11 +47,21 @@ const int NMT_TrackingStackDepth = 4; // A few common utilities for native memory tracking class NMTUtil : AllStatic { public: + // Check if index is a valid MEMFLAGS enum value (including mtNone) + static inline bool flag_index_is_valid(int index) { + return index >= 0 && index < mt_number_of_types; + } + + // Check if flag value is a valid MEMFLAGS enum value (including mtNone) + static inline bool flag_is_valid(MEMFLAGS flag) { + const int index = static_cast(flag); + return flag_index_is_valid(index); + } + // Map memory type to index static inline int flag_to_index(MEMFLAGS flag) { - const int index = flag & 0xff; - assert(index >= 0 && index < (int)mt_number_of_types, "Index out of bounds"); - return index; + assert(flag_is_valid(flag), "Invalid flag"); + return static_cast(flag); } // Map memory type to human readable name @@ -61,8 +71,8 @@ class NMTUtil : AllStatic { // Map an index to memory type static MEMFLAGS index_to_flag(int index) { - assert(index >= 0 && index < (int) mt_number_of_types, "Index out of bounds"); - return (MEMFLAGS)index; + assert(flag_index_is_valid(index), "Invalid flag"); + return static_cast(index); } // Memory size scale diff --git a/src/hotspot/share/services/virtualMemoryTracker.hpp b/src/hotspot/share/services/virtualMemoryTracker.hpp index f6eaf15ba72c2..a81a99a60ae5d 100644 --- a/src/hotspot/share/services/virtualMemoryTracker.hpp +++ b/src/hotspot/share/services/virtualMemoryTracker.hpp @@ -97,12 +97,6 @@ class VirtualMemorySnapshot : public ResourceObj { return &_virtual_memory[index]; } - inline VirtualMemory* by_index(int index) { - assert(index >= 0, "Index out of bound"); - assert(index < mt_number_of_types, "Index out of bound"); - return &_virtual_memory[index]; - } - inline size_t total_reserved() const { size_t amount = 0; for (int index = 0; index < mt_number_of_types; index ++) { From 6e5d4f33c5c6a93d91ac1df9ad5f60e6cc7ac39e Mon Sep 17 00:00:00 2001 From: Evgeny Nikitin Date: Tue, 29 Sep 2020 12:42:20 +0000 Subject: [PATCH 60/79] 8253607: [mlvm] meth/func/jdi/breakpointOtherStratum: un-problemlist and add randomness keyword Reviewed-by: iignatyev --- test/hotspot/jtreg/ProblemList.txt | 1 - .../vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index d8efdafc8d8e8..30d38dc7dcf4d 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -146,7 +146,6 @@ vmTestbase/jit/escape/LockCoarsening/LockCoarsening002.java 8208259 generic-all vmTestbase/vm/mlvm/indy/func/jvmti/redefineClassInBootstrap/TestDescription.java 8013267 generic-all vmTestbase/vm/mlvm/meth/func/java/throwException/Test.java 8058176 generic-all -vmTestbase/vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java 8208257,8058176 generic-all vmTestbase/vm/mlvm/meth/stress/compiler/deoptimize/Test.java#id1 8058176 generic-all vmTestbase/vm/mlvm/meth/stress/compiler/i2c_c2i/Test.java 8058176 generic-all vmTestbase/vm/mlvm/meth/stress/compiler/sequences/Test.java 8058176 generic-all diff --git a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java index 4f9d8c578fce4..b5c4665685894 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java +++ b/test/hotspot/jtreg/vmTestbase/vm/mlvm/meth/func/jdi/breakpointOtherStratum/Test.java @@ -23,6 +23,7 @@ /* * @test + * @key randomness * * @summary converted from VM Testbase vm/mlvm/meth/func/jdi/breakpointOtherStratum. * VM Testbase keywords: [feature_mlvm, nonconcurrent, fds, jdk, quarantine] From d5be82948b588d6eb0543d72d94abcd4ddfb9ae5 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 29 Sep 2020 14:29:28 +0000 Subject: [PATCH 61/79] 8253770: Test tools/javac/parser/JavacParserTest.java fails on Windows after JDK-8253584 Reviewed-by: vromero --- test/langtools/tools/javac/parser/JavacParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/langtools/tools/javac/parser/JavacParserTest.java b/test/langtools/tools/javac/parser/JavacParserTest.java index b58a7cb0361c6..cb7b8d0138282 100644 --- a/test/langtools/tools/javac/parser/JavacParserTest.java +++ b/test/langtools/tools/javac/parser/JavacParserTest.java @@ -1604,7 +1604,7 @@ String s() { } """; assertEquals("Unexpected AST, got:\n" + ast, expected, ast); assertEquals("Unexpected errors, got:\n" + out.toString(), - out.toString(), + out.toString().replaceAll("\\R", "\n"), """ Test.java:5:17: compiler.err.expected: token.identifier Test.java:5:16: compiler.err.not.stmt From ff6843ca4842498791061f924c545fa9469cc1dc Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Tue, 29 Sep 2020 15:15:50 +0000 Subject: [PATCH 62/79] 8253714: [cgroups v2] Soft memory limit incorrectly using memory.high The early implementation of cgroups v2 support was done with crun 0.8 and it contained a bug which set memory.high over memory.low when --memory-reservation was being used as a CLI option. This bug has been fixed in later crun versions, starting with crun 0.11. Use memory.low in OpenJDK as well. Reviewed-by: bobv, adinn --- src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp | 2 +- .../jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java | 2 +- .../jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp b/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp index c51ef9d6dc3af..74b013ba7844d 100644 --- a/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp +++ b/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp @@ -149,7 +149,7 @@ jlong CgroupV2Subsystem::memory_max_usage_in_bytes() { } char* CgroupV2Subsystem::mem_soft_limit_val() { - GET_CONTAINER_INFO_CPTR(cptr, _unified, "/memory.high", + GET_CONTAINER_INFO_CPTR(cptr, _unified, "/memory.low", "Memory Soft Limit is: %s", "%s", mem_soft_limit_str, 1024); if (mem_soft_limit_str == NULL) { return NULL; diff --git a/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java b/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java index 15d5869794e7e..06d1a31c2762e 100644 --- a/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java +++ b/src/java.base/linux/classes/jdk/internal/platform/cgroupv2/CgroupV2Subsystem.java @@ -287,7 +287,7 @@ public long getMemoryAndSwapUsage() { @Override public long getMemorySoftLimit() { - String softLimitStr = CgroupSubsystemController.getStringValue(unified, "memory.high"); + String softLimitStr = CgroupSubsystemController.getStringValue(unified, "memory.low"); return limitFromString(softLimitStr); } diff --git a/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java b/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java index e67ead0ef4123..030c1cffb556a 100644 --- a/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java +++ b/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java @@ -252,9 +252,9 @@ public void testMemorySubsystem() { } oldVal = metrics.getMemorySoftLimit(); - newVal = getLongLimitValueFromFile("memory.high"); + newVal = getLongLimitValueFromFile("memory.low"); if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) { - fail("memory.high", oldVal, newVal); + fail("memory.low", oldVal, newVal); } } From b1ce6bdba9ce9a9dcdeb63bca1b2a502bc61bd63 Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Tue, 29 Sep 2020 15:17:34 +0000 Subject: [PATCH 63/79] 8253548: jvmFlagAccess.cpp: clang 9.0.0 format specifier error Reviewed-by: lfoltan --- src/hotspot/share/runtime/flags/jvmFlagAccess.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/runtime/flags/jvmFlagAccess.cpp b/src/hotspot/share/runtime/flags/jvmFlagAccess.cpp index 56d752d337d33..07ff6b1546e08 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagAccess.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagAccess.cpp @@ -247,7 +247,7 @@ class FlagAccessImpl_size_t : public RangedFlagAccessImplprint("[ " SIZE_FORMAT_W(-25) " ... " SIZE_FORMAT_W(25) " ]", min, max); } void print_default_range(outputStream* st) const { - st->print("[ " SIZE_FORMAT_W(-25) " ... " SIZE_FORMAT_W(25) " ]", size_t(0), SIZE_MAX); + st->print("[ " SIZE_FORMAT_W(-25) " ... " SIZE_FORMAT_W(25) " ]", size_t(0), size_t(SIZE_MAX)); } }; From fb206908b431f3691a64d3e58fda86da5636c99a Mon Sep 17 00:00:00 2001 From: Anthony Scarpino Date: Tue, 29 Sep 2020 18:05:20 +0000 Subject: [PATCH 64/79] 8253637: Update EC removal Reviewed-by: mullan --- .../share/classes/sun/security/ec/ECDHKeyAgreement.java | 3 ++- test/jdk/ProblemList.txt | 1 - test/jdk/sun/security/ec/TestEC.java | 5 +++-- test/jdk/sun/security/pkcs11/PKCS11Test.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java index cb5b90cdd5176..6c79228ef22c1 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECDHKeyAgreement.java @@ -170,9 +170,10 @@ protected byte[] engineGenerateSecret() throws IllegalStateException { byte[] result; Optional resultOpt = deriveKeyImpl(privateKey, publicKey); if (resultOpt.isEmpty()) { + NamedCurve nc = CurveDB.lookup(publicKey.getParams()); throw new IllegalStateException( new InvalidAlgorithmParameterException("Curve not supported: " + - publicKey.getParams().toString())); + (nc != null ? nc.toString() : "unknown"))); } result = resultOpt.get(); publicKey = null; diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index aeac8f61fe037..59acda983d8e6 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -704,7 +704,6 @@ javax/security/auth/kerberos/KerberosTixDateTest.java 8039280 generic- sun/security/provider/PolicyFile/GrantAllPermToExtWhenNoPolicy.java 8039280 generic-all sun/security/provider/PolicyParser/ExtDirsChange.java 8039280 generic-all sun/security/provider/PolicyParser/PrincipalExpansionError.java 8039280 generic-all -sun/security/ec/TestEC.java 8253637 linux-aarch64 ############################################################################ diff --git a/test/jdk/sun/security/ec/TestEC.java b/test/jdk/sun/security/ec/TestEC.java index 36b5608b3e28d..de4f47ca5edb5 100644 --- a/test/jdk/sun/security/ec/TestEC.java +++ b/test/jdk/sun/security/ec/TestEC.java @@ -37,8 +37,9 @@ * @library ../../../java/security/testlibrary * @library ../../../javax/net/ssl/TLSCommon * @modules jdk.crypto.cryptoki/sun.security.pkcs11.wrapper - * @run main/othervm -Djdk.tls.namedGroups="secp256r1,sect193r1" -Djdk.sunec.disableNative=false TestEC - * @run main/othervm -Djava.security.policy=TestEC.policy -Djdk.tls.namedGroups="secp256r1,sect193r1" -Djdk.sunec.disableNative=false TestEC + * @run main/othervm -Djdk.tls.namedGroups="secp256r1" TestEC + * @run main/othervm -Djava.security.policy=TestEC.policy + * -Djdk.tls.namedGroups="secp256r1" TestEC */ import java.security.NoSuchProviderException; diff --git a/test/jdk/sun/security/pkcs11/PKCS11Test.java b/test/jdk/sun/security/pkcs11/PKCS11Test.java index ee71c7ace3f94..9a38fff1ee3ed 100644 --- a/test/jdk/sun/security/pkcs11/PKCS11Test.java +++ b/test/jdk/sun/security/pkcs11/PKCS11Test.java @@ -96,7 +96,7 @@ public abstract class PKCS11Test { // NSS version info public static enum ECCState { None, Basic, Extended }; static double nss_version = -1; - static ECCState nss_ecc_status = ECCState.Extended; + static ECCState nss_ecc_status = ECCState.Basic; // The NSS library we need to search for in getNSSLibDir() // Default is "libsoftokn3.so", listed as "softokn3" From 2fe0a5d75ee9434017b3df5cfa713ef895a19866 Mon Sep 17 00:00:00 2001 From: Harold Seigel Date: Tue, 29 Sep 2020 19:59:26 +0000 Subject: [PATCH 65/79] 8253476: TestUseContainerSupport.java fails on some Linux kernels w/o swap limit capabilities Reviewed-by: bobv, coleenp --- .../jdk/internal/platform/docker/TestUseContainerSupport.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/jdk/jdk/internal/platform/docker/TestUseContainerSupport.java b/test/jdk/jdk/internal/platform/docker/TestUseContainerSupport.java index 2b087d2cc8ad2..a2719ebccc1ae 100644 --- a/test/jdk/jdk/internal/platform/docker/TestUseContainerSupport.java +++ b/test/jdk/jdk/internal/platform/docker/TestUseContainerSupport.java @@ -60,8 +60,7 @@ private static void testUseContainerSupport(boolean useContainerSupport) throws DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "CheckUseContainerSupport"); opts.addClassOptions(Boolean.valueOf(useContainerSupport).toString()); - opts.addDockerOpts("--memory", "200m") - .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); + opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); if (useContainerSupport) { opts.addJavaOpts("-XX:+UseContainerSupport"); } else { From 8df3e72cea9217a7a10e2ac4bf4d1501a7fad43c Mon Sep 17 00:00:00 2001 From: Ian Graves Date: Tue, 29 Sep 2020 21:16:35 +0000 Subject: [PATCH 66/79] 8218685: jlink --list-plugins needs to be readable and tidy Reviewed-by: mchung, alanb --- .../StripNativeDebugSymbolsPlugin.java | 61 +++------ ...rip_native_debug_symbols_plugin.properties | 18 +++ .../jdk/tools/jlink/internal/TaskHelper.java | 94 ++++++++------ .../internal/plugins/AbstractPlugin.java | 87 +++++++++++++ .../internal/plugins/AddResourcePlugin.java | 24 +--- .../plugins/DefaultCompressPlugin.java | 21 +-- .../plugins/DefaultStripDebugPlugin.java | 14 +- .../internal/plugins/ExcludeFilesPlugin.java | 22 +--- .../plugins/ExcludeJmodSectionPlugin.java | 20 +-- .../jlink/internal/plugins/ExcludePlugin.java | 23 +--- .../internal/plugins/ExcludeVMPlugin.java | 21 +-- .../plugins/GenerateJLIClassesPlugin.java | 24 +--- .../plugins/IncludeLocalesPlugin.java | 29 ++--- .../plugins/LegalNoticeFilePlugin.java | 23 +--- .../plugins/OrderResourcesPlugin.java | 22 +--- .../plugins/PluginsResourceBundle.java | 5 + .../internal/plugins/ReleaseInfoPlugin.java | 27 +--- .../internal/plugins/StringSharingPlugin.java | 23 +--- .../StripJavaDebugAttributesPlugin.java | 15 +-- .../plugins/StripNativeCommandsPlugin.java | 15 +-- .../internal/plugins/SystemModulesPlugin.java | 28 +--- .../internal/plugins/VersionPropsPlugin.java | 23 +--- .../jlink/internal/plugins/ZipPlugin.java | 24 +--- .../jdk/tools/jlink/plugin/Plugin.java | 8 ++ .../tools/jlink/resources/plugins.properties | 122 ++++++++++++++++++ test/jdk/tools/jlink/IntegrationTest.java | 10 +- test/jdk/tools/jlink/JLinkTest.java | 17 ++- .../jlink/plugins/ExcludeFilesPluginTest.java | 2 +- .../jlink/plugins/ExcludeModuleInfoTest.java | 2 +- .../jlink/plugins/ExcludePluginTest.java | 2 +- .../jlink/plugins/ExcludeVMPluginTest.java | 2 +- .../plugins/OrderResourcesPluginTest.java | 4 +- 32 files changed, 412 insertions(+), 420 deletions(-) create mode 100644 src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AbstractPlugin.java diff --git a/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java b/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java index 58a32b43857df..d2f2307768d67 100644 --- a/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java +++ b/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java @@ -45,7 +45,6 @@ import java.util.Optional; import java.util.ResourceBundle; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -56,7 +55,7 @@ * libraries and binaries. * */ -public final class StripNativeDebugSymbolsPlugin implements Plugin { +public final class StripNativeDebugSymbolsPlugin extends AbstractPlugin { public static final String NAME = "strip-native-debug-symbols"; private static final boolean DEBUG = Boolean.getBoolean("jlink.debug"); @@ -92,14 +91,10 @@ public StripNativeDebugSymbolsPlugin() { } public StripNativeDebugSymbolsPlugin(ObjCopyCmdBuilder cmdBuilder) { + super(NAME, resourceBundle); this.cmdBuilder = cmdBuilder; } - @Override - public String getName() { - return NAME; - } - @Override public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { StrippedDebugInfoBinaryBuilder builder = new StrippedDebugInfoBinaryBuilder( @@ -137,10 +132,9 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { } private void logError(ResourcePoolEntry resource, String msgKey) { - String msg = PluginsResourceBundle.getMessage(resourceBundle, - msgKey, - NAME, - resource.path()); + String msg = getMessage(msgKey, + NAME, + resource.path()); System.err.println(msg); } @@ -149,23 +143,11 @@ public Category getType() { return Category.TRANSFORMER; } - @Override - public String getDescription() { - String key = NAME + ".description"; - return PluginsResourceBundle.getMessage(resourceBundle, key); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - String key = NAME + ".argument"; - return PluginsResourceBundle.getMessage(resourceBundle, key); - } - @Override public void configure(Map config) { doConfigure(true, config); @@ -196,8 +178,7 @@ public void doConfigure(boolean withChecks, Map orig) { String[] tokens = arg.split("="); if (tokens.length != 2 || !KEEP_DEBUG_INFO_ARG.equals(tokens[0])) { throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".iae", NAME, arg)); + getMessage(NAME + ".iae", NAME, arg)); } hasKeepDebugInfo = true; debuginfoExt = tokens[1]; @@ -211,8 +192,7 @@ public void doConfigure(boolean withChecks, Map orig) { String[] tokens = arg.split("="); if (tokens.length != 2 || !STRIP_CMD_ARG.equals(tokens[0])) { throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".iae", NAME, arg)); + getMessage(NAME + ".iae", NAME, arg)); } if (withChecks) { validateStripArg(tokens[1]); @@ -246,26 +226,23 @@ public void doConfigure(boolean withChecks, Map orig) { // on the same plugin instance multiple times. Plugin option can // repeat. throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".iae.conflict", - NAME, - EXCLUDE_DEBUG_INFO_ARG, - KEEP_DEBUG_INFO_ARG)); + getMessage(NAME + ".iae.conflict", + NAME, + EXCLUDE_DEBUG_INFO_ARG, + KEEP_DEBUG_INFO_ARG)); } if (!arg.startsWith(STRIP_CMD_ARG) && !arg.startsWith(KEEP_DEBUG_INFO_ARG) && !arg.startsWith(EXCLUDE_DEBUG_INFO_ARG)) { // unknown arg value; case --strip-native-debug-symbols foobar throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".iae", NAME, arg)); + getMessage(NAME + ".iae", NAME, arg)); } if (!config.isEmpty()) { // extraneous values; --strip-native-debug-symbols keep-debuginfo-files:foo=bar throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".iae", NAME, - config.toString())); + getMessage(NAME + ".iae", NAME, + config.toString())); } includeDebugSymbols = hasKeepDebugInfo; } @@ -275,15 +252,13 @@ private void validateStripArg(String stripArg) throws IllegalArgumentException { Path strip = Paths.get(stripArg); // verify it's a resonable path if (!Files.isExecutable(strip)) { throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".invalidstrip", - stripArg)); + getMessage(NAME + ".invalidstrip", + stripArg)); } } catch (InvalidPathException e) { throw new IllegalArgumentException( - PluginsResourceBundle.getMessage(resourceBundle, - NAME + ".invalidstrip", - e.getInput())); + getMessage(NAME + ".invalidstrip", + e.getInput())); } } diff --git a/src/jdk.jlink/linux/classes/jdk/tools/jlink/resources/strip_native_debug_symbols_plugin.properties b/src/jdk.jlink/linux/classes/jdk/tools/jlink/resources/strip_native_debug_symbols_plugin.properties index ccc3205421ea6..a3784b63d0abd 100644 --- a/src/jdk.jlink/linux/classes/jdk/tools/jlink/resources/strip_native_debug_symbols_plugin.properties +++ b/src/jdk.jlink/linux/classes/jdk/tools/jlink/resources/strip_native_debug_symbols_plugin.properties @@ -35,6 +35,24 @@ Strip debug symbols from native libraries (if any). \n\ strip-native-debug-symbols.argument=\ + +strip-native-debug-symbols.usage=\ +\ --strip-native-debug-symbols \ +\ \n\ +\ Strip debug symbols from native libraries (if any). \n\ +\ This plugin requires at least one option:\n\ +\ objcopy: The path to the 'objcopy' binary.\n\ +\ Defaults to 'objcopy' in PATH.\n\ +\ exclude-debuginfo-files: Exclude debug info \n\ +\ files. Defaults to true.\n\ +\ keep-debuginfo-files[=]: Keep debug info\n\ +\ files in ..\n\ +\ Defaults to .debuginfo \n\ +\ Examples: --strip-native-debug-symbols \n\ +\ keep-debuginfo-files:objcopy=OBJPATH\n\ +\ --strip-native-debug-symbols\n\ +\ exclude-debuginfo-files + strip-native-debug-symbols.invalidstrip=Invalid objcopy command: {0} strip-native-debug-symbols.iae={0}: Unrecognized argument ''{1}'' diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java index 72694f7184d3b..0e8dc45b933e6 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/TaskHelper.java @@ -30,20 +30,22 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; import java.util.Map; +import java.util.HashMap; import java.util.Map.Entry; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.Collections; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.MissingResourceException; +import java.util.Comparator; + import jdk.tools.jlink.builder.DefaultImageBuilder; import jdk.tools.jlink.builder.ImageBuilder; @@ -373,7 +375,7 @@ private void addOrderedPluginOptions(Plugin plugin, = new PluginOption(false, (task, opt, arg) -> { Map m = addArgumentMap(plugin); - m.put(DefaultCompressPlugin.NAME, DefaultCompressPlugin.LEVEL_2); + m.put(plugin.getName(), DefaultCompressPlugin.LEVEL_2); }, false, "--compress", "-c"); mainOptions.add(plugOption); } else if (plugin instanceof DefaultStripDebugPlugin) { @@ -386,14 +388,14 @@ private void addOrderedPluginOptions(Plugin plugin, } else if (plugin instanceof ExcludeJmodSectionPlugin) { plugOption = new PluginOption(false, (task, opt, arg) -> { Map m = addArgumentMap(plugin); - m.put(ExcludeJmodSectionPlugin.NAME, + m.put(plugin.getName(), ExcludeJmodSectionPlugin.MAN_PAGES); }, false, "--no-man-pages"); mainOptions.add(plugOption); plugOption = new PluginOption(false, (task, opt, arg) -> { Map m = addArgumentMap(plugin); - m.put(ExcludeJmodSectionPlugin.NAME, + m.put(plugin.getName(), ExcludeJmodSectionPlugin.INCLUDE_HEADER_FILES); }, false, "--no-header-files"); mainOptions.add(plugOption); @@ -450,8 +452,8 @@ private PluginsConfiguration getPluginsConfig(Path output, Map l // aren't being used at the same time. --strip-debug invokes --strip-native-debug-symbols on // platforms that support it, so it makes little sense to allow both at the same time. if ((plugin instanceof DefaultStripDebugPlugin && seenPlugins.contains(STRIP_NATIVE_DEBUG_SYMBOLS_NAME)) || - (STRIP_NATIVE_DEBUG_SYMBOLS_NAME.equals(plugin.getName()) && seenPlugins.contains(DefaultStripDebugPlugin.NAME))) { - throw new BadArgs("err.plugin.conflicts", "--" + DefaultStripDebugPlugin.NAME, + (STRIP_NATIVE_DEBUG_SYMBOLS_NAME.equals(plugin.getName()) && seenPlugins.contains(plugin.getName()))) { + throw new BadArgs("err.plugin.conflicts", "--" + plugin.getName(), "-G", "--" + STRIP_NATIVE_DEBUG_SYMBOLS_NAME); } @@ -606,42 +608,50 @@ public void listPlugins() { List pluginList = PluginRepository. getPlugins(pluginOptions.pluginsLayer); - for (Plugin plugin : Utils.getSortedPlugins(pluginList)) { - showPlugin(plugin, log); - } + pluginList.stream() + .sorted(Comparator.comparing((Plugin plugin) -> plugin.getUsage().isEmpty(), + (Boolean res1, Boolean res2) -> Boolean.compare(res2,res1)) + .thenComparing(Plugin::getName) + ) + .forEach((plugin) -> showPlugin(plugin, log)); log.println("\n" + bundleHelper.getMessage("main.extended.help.footer")); } private void showPlugin(Plugin plugin, PrintWriter log) { if (showsPlugin(plugin)) { - log.println("\n" + bundleHelper.getMessage("main.plugin.name") - + ": " + plugin.getName()); - - // print verbose details for non-builtin plugins - if (!Utils.isBuiltin(plugin)) { - log.println(bundleHelper.getMessage("main.plugin.class") - + ": " + plugin.getClass().getName()); - log.println(bundleHelper.getMessage("main.plugin.module") - + ": " + plugin.getClass().getModule().getName()); - Category category = plugin.getType(); - log.println(bundleHelper.getMessage("main.plugin.category") - + ": " + category.getName()); - log.println(bundleHelper.getMessage("main.plugin.state") - + ": " + plugin.getStateDescription()); - } + if(!plugin.getUsage().isEmpty()) { + log.println(plugin.getUsage()); + } else { + log.println("\n" + bundleHelper.getMessage("main.plugin.name") + + ": " + plugin.getName()); + + // print verbose details for non-builtin plugins + if (!Utils.isBuiltin(plugin)) { + log.println(bundleHelper.getMessage("main.plugin.class") + + ": " + plugin.getClass().getName()); + log.println(bundleHelper.getMessage("main.plugin.module") + + ": " + plugin.getClass().getModule().getName()); + Category category = plugin.getType(); + log.println(bundleHelper.getMessage("main.plugin.category") + + ": " + category.getName()); + log.println(bundleHelper.getMessage("main.plugin.state") + + ": " + plugin.getStateDescription()); + } + + String option = plugin.getOption(); + if (option != null) { + log.println(bundleHelper.getMessage("main.plugin.option") + + ": --" + plugin.getOption() + + (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : "")); + } - String option = plugin.getOption(); - if (option != null) { - log.println(bundleHelper.getMessage("main.plugin.option") - + ": --" + plugin.getOption() - + (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : "")); + // description can be long spanning more than one line and so + // print a newline after description label. + log.println(bundleHelper.getMessage("main.plugin.description") + + ": " + plugin.getDescription()); } - // description can be long spanning more than one line and so - // print a newline after description label. - log.println(bundleHelper.getMessage("main.plugin.description") - + ": " + plugin.getDescription()); } } @@ -725,6 +735,6 @@ public String version(String key) { // Display all plugins private static boolean showsPlugin(Plugin plugin) { - return (!Utils.isDisabled(plugin) && plugin.getOption() != null); + return (!Utils.isDisabled(plugin) && (plugin.getOption() != null) || !(plugin.getUsage().isEmpty())); } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AbstractPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AbstractPlugin.java new file mode 100644 index 0000000000000..fd4fdcd39dda9 --- /dev/null +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AbstractPlugin.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.tools.jlink.internal.plugins; + +import jdk.tools.jlink.plugin.Plugin; + +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public abstract class AbstractPlugin implements Plugin { + + static final String DESCRIPTION = "description"; + static final String USAGE = "usage"; + + private static final ResourceBundle standardPluginsBundle; + + static { + Locale locale = Locale.getDefault(); + try { + standardPluginsBundle = ResourceBundle.getBundle("jdk.tools.jlink." + + "resources.plugins", locale); + } catch (MissingResourceException e) { + throw new InternalError("Cannot find jlink resource bundle for " + + "locale " + locale); + } + } + + private final ResourceBundle pluginsBundle; + private final String name; + + protected AbstractPlugin(String name) { + this.name = name; + this.pluginsBundle = standardPluginsBundle; + } + + protected AbstractPlugin(String name, ResourceBundle bundle) { + this.name = name; + this.pluginsBundle = bundle; + } + @Override + public String getName() { + return name; + } + + @Override + public String getDescription() { + return getMessage(getName() + "." + DESCRIPTION, getName()); + } + + @Override + public String getUsage() { + return getMessage(getName() + "." + USAGE, getName()); + } + + @Override + public String getArgumentsDescription() { + return PluginsResourceBundle.getArgument(getName()); + } + + protected String getMessage(String key, Object...args) { + return PluginsResourceBundle.getMessage(this.pluginsBundle, key, args); + } +} diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddResourcePlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddResourcePlugin.java index fd9ad8176ce28..f7de6151826a0 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddResourcePlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/AddResourcePlugin.java @@ -29,7 +29,6 @@ import java.util.Map; import java.util.function.Function; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; @@ -37,27 +36,16 @@ /** * Base plugin to add a resource */ -abstract class AddResourcePlugin implements Plugin { +abstract class AddResourcePlugin extends AbstractPlugin { - private final String name; private final String path; private String value; - protected AddResourcePlugin(String n, String p) { - name = n; + protected AddResourcePlugin(String name, String p) { + super(name); path = p; } - @Override - public String getName() { - return name; - } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(name); - } - @Override public Category getType() { return Category.ADDER; @@ -73,14 +61,10 @@ public boolean hasRawArgument() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(name); - } @Override public void configure(Map config) { - var v = config.get(name); + var v = config.get(getName()); if (v == null) throw new AssertionError(); value = v; diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java index 69add478c1812..ff263aca56ee6 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultCompressPlugin.java @@ -30,7 +30,6 @@ import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.internal.ImagePluginStack; import jdk.tools.jlink.internal.ResourcePoolManager; import jdk.tools.jlink.internal.ResourcePrevisitor; @@ -40,8 +39,7 @@ * * ZIP and String Sharing compression plugin */ -public final class DefaultCompressPlugin implements Plugin, ResourcePrevisitor { - public static final String NAME = "compress"; +public final class DefaultCompressPlugin extends AbstractPlugin implements ResourcePrevisitor { public static final String FILTER = "filter"; public static final String LEVEL_0 = "0"; public static final String LEVEL_1 = "1"; @@ -50,9 +48,8 @@ public final class DefaultCompressPlugin implements Plugin, ResourcePrevisitor { private StringSharingPlugin ss; private ZipPlugin zip; - @Override - public String getName() { - return NAME; + public DefaultCompressPlugin() { + super("compress"); } @Override @@ -83,25 +80,15 @@ public Category getType() { return Category.COMPRESSOR; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { ResourceFilter resFilter = ResourceFilter.includeFilter(config.get(FILTER)); - String level = config.get(NAME); + String level = config.get(getName()); if (level != null) { switch (level) { case LEVEL_0: diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultStripDebugPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultStripDebugPlugin.java index a2ffc14dec04b..e497083cc949a 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultStripDebugPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/DefaultStripDebugPlugin.java @@ -39,9 +39,8 @@ * symbols. * */ -public final class DefaultStripDebugPlugin implements Plugin { +public final class DefaultStripDebugPlugin extends AbstractPlugin { - public static final String NAME = "strip-debug"; private static final String STRIP_NATIVE_DEBUG_PLUGIN = "strip-native-debug-symbols"; private static final String EXCLUDE_DEBUGINFO = "exclude-debuginfo-files"; @@ -55,20 +54,11 @@ public DefaultStripDebugPlugin() { public DefaultStripDebugPlugin(Plugin javaStripPlugin, NativePluginFactory nativeStripPluginFact) { + super("strip-debug"); this.javaStripPlugin = javaStripPlugin; this.stripNativePluginFactory = nativeStripPluginFact; } - @Override - public String getName() { - return NAME; - } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { Plugin stripNativePlugin = stripNativePluginFactory.create(); diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java index d263d1b8bf3ef..d9f2fc9744e9c 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeFilesPlugin.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.function.Predicate; -import jdk.tools.jlink.plugin.Plugin; + import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; @@ -35,14 +35,12 @@ * * Exclude files plugin */ -public final class ExcludeFilesPlugin implements Plugin { +public final class ExcludeFilesPlugin extends AbstractPlugin { - public static final String NAME = "exclude-files"; private Predicate predicate; - @Override - public String getName() { - return NAME; + public ExcludeFilesPlugin () { + super("exclude-files"); } @Override @@ -61,23 +59,13 @@ public Category getType() { return Category.FILTER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - predicate = ResourceFilter.excludeFilter(config.get(NAME)); + predicate = ResourceFilter.excludeFilter(config.get(getName())); } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java index e38032a0745e0..d86e1d1267e97 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeJmodSectionPlugin.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Set; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry.Type; @@ -37,22 +36,20 @@ * * A plugin to exclude a JMOD section such as man pages or header files */ -public final class ExcludeJmodSectionPlugin implements Plugin { +public final class ExcludeJmodSectionPlugin extends AbstractPlugin { - public static final String NAME = "exclude-jmod-section"; public static final String MAN_PAGES = "man"; public static final String INCLUDE_HEADER_FILES = "headers"; private final Set filters = new HashSet<>(); - @Override - public String getName() { - return NAME; + public ExcludeJmodSectionPlugin() { + super("exclude-jmod-section"); } @Override public void configure(Map config) { - String arg = config.get(NAME); + String arg = config.get(getName()); if (arg.isEmpty()) { throw new IllegalArgumentException("Section name must be specified"); } @@ -86,18 +83,9 @@ public Category getType() { return Category.FILTER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java index 0e6ef944cc8db..c41bb9b6a5d9f 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludePlugin.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.function.Predicate; -import jdk.tools.jlink.plugin.Plugin; + import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -36,14 +36,13 @@ * * Exclude resources plugin */ -public final class ExcludePlugin implements Plugin { +public final class ExcludePlugin extends AbstractPlugin { - public static final String NAME = "exclude-resources"; private Predicate predicate; - @Override - public String getName() { - return NAME; + + public ExcludePlugin() { + super("exclude-resources"); } @Override @@ -63,21 +62,11 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { return out.build(); } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public Category getType() { return Category.FILTER; @@ -85,6 +74,6 @@ public Category getType() { @Override public void configure(Map config) { - predicate = ResourceFilter.excludeFilter(config.get(NAME)); + predicate = ResourceFilter.excludeFilter(config.get(getName())); } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java index 9526f8144a5b4..b2a759a0ad475 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ExcludeVMPlugin.java @@ -37,7 +37,6 @@ import java.util.stream.Collectors; import jdk.tools.jlink.internal.Platform; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -48,7 +47,7 @@ * * Exclude VM plugin */ -public final class ExcludeVMPlugin implements Plugin { +public final class ExcludeVMPlugin extends AbstractPlugin { private static final class JvmComparator implements Comparator { @@ -80,7 +79,6 @@ private int getEfficience() { private static final String JVM_CFG = "jvm.cfg"; - public static final String NAME = "vm"; private static final String ALL = "all"; private static final String CLIENT = "client"; private static final String SERVER = "server"; @@ -90,9 +88,8 @@ private int getEfficience() { private Jvm target; private boolean keepAll; - @Override - public String getName() { - return NAME; + public ExcludeVMPlugin() { + super("vm"); } /** @@ -172,24 +169,14 @@ public Category getType() { return Category.FILTER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - String value = config.get(NAME); + String value = config.get(getName()); String exclude = ""; switch (value) { case ALL: { diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java index 41a3ecac99f63..dcc9c3acdea41 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/GenerateJLIClassesPlugin.java @@ -37,7 +37,6 @@ import jdk.internal.access.JavaLangInvokeAccess; import jdk.internal.access.SharedSecrets; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -61,11 +60,8 @@ * feeding that into jlink using {@code --generate-jli-classes=@trace_file} can * help improve startup time. */ -public final class GenerateJLIClassesPlugin implements Plugin { +public final class GenerateJLIClassesPlugin extends AbstractPlugin { - private static final String NAME = "generate-jli-classes"; - - private static final String DESCRIPTION = PluginsResourceBundle.getDescription(NAME); private static final String DEFAULT_TRACE_FILE = "default_jli_trace.txt"; @@ -76,16 +72,7 @@ public final class GenerateJLIClassesPlugin implements Plugin { private Stream traceFileStream; public GenerateJLIClassesPlugin() { - } - - @Override - public String getName() { - return NAME; - } - - @Override - public String getDescription() { - return DESCRIPTION; + super("generate-jli-classes"); } @Override @@ -98,14 +85,9 @@ public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - mainArgument = config.get(NAME); + mainArgument = config.get(getName()); } public void initialize(ResourcePool in) { diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java index 99635d988d4da..8d327530d9112 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/IncludeLocalesPlugin.java @@ -48,7 +48,6 @@ import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; -import jdk.tools.jlink.plugin.Plugin; import sun.util.cldr.CLDRBaseLocaleDataMetaInfo; import sun.util.locale.provider.LocaleProviderAdapter; import sun.util.locale.provider.LocaleProviderAdapter.Type; @@ -76,9 +75,8 @@ * start with at least one white space character, e.g., " ar ar-EG ..." * ^ */ -public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor { +public final class IncludeLocalesPlugin extends AbstractPlugin implements ResourcePrevisitor { - public static final String NAME = "include-locales"; private static final String MODULENAME = "jdk.localedata"; private static final Set LOCALEDATA_PACKAGES = Set.of( "sun.text.resources.cldr.ext", @@ -147,9 +145,8 @@ public final class IncludeLocalesPlugin implements Plugin, ResourcePrevisitor { private static final Locale noNONY = new Locale("no", "NO", "NY"); private static final Locale thTHTH = new Locale("th", "TH", "TH"); - @Override - public String getName() { - return NAME; + public IncludeLocalesPlugin() { + super("include-locales"); } @Override @@ -180,30 +177,20 @@ public Category getType() { return Category.FILTER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - userParam = config.get(NAME); + userParam = config.get(getName()); try { priorityList = Locale.LanguageRange.parse(userParam, EQUIV_MAP); } catch (IllegalArgumentException iae) { throw new IllegalArgumentException(String.format( - PluginsResourceBundle.getMessage(NAME + ".invalidtag"), + PluginsResourceBundle.getMessage(getName() + ".invalidtag"), iae.getMessage().replaceFirst("^range=", ""))); } } @@ -218,7 +205,7 @@ public void previsit(ResourcePool resources, StringTable strings) { ResourcePoolModule module = optMod.get(); Set packages = module.packages(); if (!packages.containsAll(LOCALEDATA_PACKAGES)) { - throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".missingpackages") + + throw new PluginException(PluginsResourceBundle.getMessage(getName()+ ".missingpackages") + LOCALEDATA_PACKAGES.stream() .filter(pn -> !packages.contains(pn)) .collect(Collectors.joining(",\n\t"))); @@ -235,14 +222,14 @@ public void previsit(ResourcePool resources, StringTable strings) { .collect(Collectors.toList()); } else { // jdk.localedata is not added. - throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".localedatanotfound")); + throw new PluginException(PluginsResourceBundle.getMessage(getName() + ".localedatanotfound")); } filtered = filterLocales(available); if (filtered.isEmpty()) { throw new PluginException( - String.format(PluginsResourceBundle.getMessage(NAME + ".nomatchinglocales"), userParam)); + String.format(PluginsResourceBundle.getMessage(getName() + ".nomatchinglocales"), userParam)); } List value = Stream.concat( diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java index 4cf5b0c6186f3..5b6c23a6563cd 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java @@ -36,7 +36,6 @@ import jdk.tools.jlink.internal.ModuleSorter; import jdk.tools.jlink.internal.Utils; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -52,18 +51,16 @@ * On platform that does not support symbolic links, a file * will be created to contain the path to the linked target. */ -public final class LegalNoticeFilePlugin implements Plugin { +public final class LegalNoticeFilePlugin extends AbstractPlugin { - private static final String NAME = "dedup-legal-notices"; private static final String ERROR_IF_NOT_SAME_CONTENT = "error-if-not-same-content"; private final Map> licenseOrNotice = new HashMap<>(); private boolean errorIfNotSameContent = false; - @Override - public String getName() { - return NAME; + public LegalNoticeFilePlugin() { + super("dedup-legal-notices"); } @Override @@ -73,12 +70,12 @@ public Set getState() { @Override public void configure(Map config) { - String arg = config.get(NAME); + String arg = config.get(getName()); if (arg != null) { if (arg.equals(ERROR_IF_NOT_SAME_CONTENT)) { errorIfNotSameContent = true; } else { - throw new IllegalArgumentException(NAME + ": " + arg); + throw new IllegalArgumentException(getName() + ": " + arg); } } } @@ -140,18 +137,8 @@ public Category getType() { return Category.TRANSFORMER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java index 7cbc15818fb39..81d06f3e57658 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/OrderResourcesPlugin.java @@ -37,7 +37,6 @@ import java.util.function.ToIntFunction; import jdk.tools.jlink.internal.Utils; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; @@ -46,23 +45,18 @@ * * Order Resources plugin */ -public final class OrderResourcesPlugin implements Plugin { - public static final String NAME = "order-resources"; +public final class OrderResourcesPlugin extends AbstractPlugin { private static final FileSystem JRT_FILE_SYSTEM = Utils.jrtFileSystem(); private final List> filters; private final Map orderedPaths; public OrderResourcesPlugin() { + super("order-resources"); this.filters = new ArrayList<>(); this.orderedPaths = new HashMap<>(); } - @Override - public String getName() { - return NAME; - } - static class SortWrapper { private final ResourcePoolEntry resource; private final int ordinal; @@ -148,24 +142,14 @@ public Category getType() { return Category.SORTER; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - List patterns = Utils.parseList(config.get(NAME)); + List patterns = Utils.parseList(config.get(getName())); int ordinal = 0; for (String pattern : patterns) { diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/PluginsResourceBundle.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/PluginsResourceBundle.java index 09ed153061257..4d1eb46b4ffcd 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/PluginsResourceBundle.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/PluginsResourceBundle.java @@ -33,6 +33,7 @@ public final class PluginsResourceBundle { static final String DESCRIPTION = "description"; static final String ARGUMENT = "argument"; + static final String USAGE = "usage"; private static final ResourceBundle pluginsBundle; static { @@ -57,6 +58,10 @@ public static String getDescription(String name) { return getMessage(name + "." + DESCRIPTION, name); } + public static String getUsage(String name) { + return getMessage(name + "." + USAGE, name); + } + public static String getOption(String name, String option) { return getMessage(name + "." + option); } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java index b0be07116fc50..30edf916a2ccd 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ReleaseInfoPlugin.java @@ -44,30 +44,22 @@ import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; import jdk.tools.jlink.plugin.ResourcePoolModule; -import jdk.tools.jlink.plugin.Plugin; /** * This plugin adds/deletes information for 'release' file. */ -public final class ReleaseInfoPlugin implements Plugin { +public final class ReleaseInfoPlugin extends AbstractPlugin { // option name - public static final String NAME = "release-info"; public static final String KEYS = "keys"; private final Map release = new HashMap<>(); - @Override - public Category getType() { - return Category.METAINFO_ADDER; - } - - @Override - public String getName() { - return NAME; + public ReleaseInfoPlugin() { + super("release-info"); } @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); + public Category getType() { + return Category.METAINFO_ADDER; } @Override @@ -80,14 +72,9 @@ public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - String operation = config.get(NAME); + String operation = config.get(getName()); if (operation == null) { return; } @@ -101,7 +88,7 @@ public void configure(Map config) { // and put whatever value that was passed in command line. config.keySet().stream() - .filter(s -> !NAME.equals(s)) + .filter(s -> !getName().equals(s)) .forEach(s -> release.put(s, config.get(s))); } break; diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java index d2967fe21e094..737e85cfa68be 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StringSharingPlugin.java @@ -56,7 +56,6 @@ import jdk.internal.jimage.decompressor.SignatureParser; import jdk.internal.jimage.decompressor.StringSharingDecompressor; import jdk.tools.jlink.internal.ResourcePoolManager.ResourcePoolImpl; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -70,9 +69,7 @@ * A Plugin that stores the image classes constant pool UTF_8 entries into the * Image StringsTable. */ -public class StringSharingPlugin implements Plugin, ResourcePrevisitor { - - public static final String NAME = "compact-cp"; +public class StringSharingPlugin extends AbstractPlugin implements ResourcePrevisitor { private static final int[] SIZES; @@ -340,6 +337,7 @@ public StringSharingPlugin() { } StringSharingPlugin(Predicate predicate) { + super("compact-cp"); this.predicate = predicate; } @@ -370,29 +368,14 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder result) { return result.build(); } - @Override - public String getName() { - return NAME; - } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - predicate = ResourceFilter.includeFilter(config.get(NAME)); + predicate = ResourceFilter.includeFilter(config.get(getName())); } @Override diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripJavaDebugAttributesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripJavaDebugAttributesPlugin.java index 4ed09aedbbe67..c7c3979992122 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripJavaDebugAttributesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripJavaDebugAttributesPlugin.java @@ -28,7 +28,6 @@ import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.ClassWriter; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; @@ -37,8 +36,7 @@ * * Strip java debug attributes plugin */ -public final class StripJavaDebugAttributesPlugin implements Plugin { - public static final String NAME = "strip-java-debug-attributes"; +public final class StripJavaDebugAttributesPlugin extends AbstractPlugin { private final Predicate predicate; public StripJavaDebugAttributesPlugin() { @@ -46,19 +44,10 @@ public StripJavaDebugAttributesPlugin() { } StripJavaDebugAttributesPlugin(Predicate predicate) { + super("strip-java-debug-attributes"); this.predicate = predicate; } - @Override - public String getName() { - return NAME; - } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { //remove *.diz files as well as debug attributes. diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java index 143b36d4859b8..4bcb7d1ff04a4 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/StripNativeCommandsPlugin.java @@ -27,19 +27,15 @@ import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; -import jdk.tools.jlink.plugin.Plugin; /** * * Strip Native Commands plugin */ -public final class StripNativeCommandsPlugin implements Plugin { +public final class StripNativeCommandsPlugin extends AbstractPlugin { - public static final String NAME = "strip-native-commands"; - - @Override - public String getName() { - return NAME; + public StripNativeCommandsPlugin() { + super("strip-native-commands"); } @Override @@ -55,9 +51,4 @@ public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { return out.build(); } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } } diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java index 784851cac6a85..a1a1836f87f42 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModulesPlugin.java @@ -78,7 +78,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; import jdk.tools.jlink.internal.ModuleSorter; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.PluginException; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; @@ -97,10 +96,7 @@ * @see jdk.internal.module.SystemModules */ -public final class SystemModulesPlugin implements Plugin { - private static final String NAME = "system-modules"; - private static final String DESCRIPTION = - PluginsResourceBundle.getDescription(NAME); +public final class SystemModulesPlugin extends AbstractPlugin { private static final String SYSTEM_MODULES_MAP_CLASS = "jdk/internal/module/SystemModulesMap"; private static final String SYSTEM_MODULES_CLASS_PREFIX = @@ -113,19 +109,10 @@ public final class SystemModulesPlugin implements Plugin { private boolean enabled; public SystemModulesPlugin() { + super("system-modules"); this.enabled = true; } - @Override - public String getName() { - return NAME; - } - - @Override - public String getDescription() { - return DESCRIPTION; - } - @Override public Set getState() { return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL) @@ -137,23 +124,18 @@ public boolean hasArguments() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - String arg = config.get(NAME); + String arg = config.get(getName()); if (arg != null) { - throw new IllegalArgumentException(NAME + ": " + arg); + throw new IllegalArgumentException(getName() + ": " + arg); } } @Override public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { if (!enabled) { - throw new PluginException(NAME + " was set"); + throw new PluginException(getName() + " was set"); } // validate, transform (if needed), and add the module-info.class files diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java index cafaafc5001dd..8c1c8374faf03 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/VersionPropsPlugin.java @@ -32,7 +32,6 @@ import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.MethodVisitor; import jdk.internal.org.objectweb.asm.Opcodes; -import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; @@ -45,12 +44,11 @@ * We assume that the initialization code only has ldcs, method calls and * field instructions. */ -abstract class VersionPropsPlugin implements Plugin { +abstract class VersionPropsPlugin extends AbstractPlugin { private static final String VERSION_PROPS_CLASS = "/java.base/java/lang/VersionProps.class"; - private final String name; private final String field; private String value; @@ -59,8 +57,8 @@ abstract class VersionPropsPlugin implements Plugin { * @param option The option name */ protected VersionPropsPlugin(String field, String option) { + super(option); this.field = field; - this.name = option; } /** @@ -73,16 +71,6 @@ protected VersionPropsPlugin(String field) { this(field, field.toLowerCase().replace('_', '-')); } - @Override - public String getName() { - return name; - } - - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(name); - } - @Override public Category getType() { return Category.TRANSFORMER; @@ -98,14 +86,9 @@ public boolean hasRawArgument() { return true; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(name); - } - @Override public void configure(Map config) { - var v = config.get(name); + var v = config.get(getName()); if (v == null) throw new AssertionError(); value = v; diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java index 5f8598fdc0557..c733392690ba5 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/ZipPlugin.java @@ -36,19 +36,17 @@ import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; -import jdk.tools.jlink.plugin.Plugin; /** * * ZIP Compression plugin */ -public final class ZipPlugin implements Plugin { +public final class ZipPlugin extends AbstractPlugin { - public static final String NAME = "zip"; private Predicate predicate; public ZipPlugin() { - + this((Predicate) null); } ZipPlugin(String[] patterns) { @@ -56,37 +54,23 @@ public ZipPlugin() { } ZipPlugin(Predicate predicate) { + super("zip"); this.predicate = predicate; } - @Override - public String getName() { - return NAME; - } - @Override public Category getType() { return Category.COMPRESSOR; } - @Override - public String getDescription() { - return PluginsResourceBundle.getDescription(NAME); - } - @Override public boolean hasArguments() { return false; } - @Override - public String getArgumentsDescription() { - return PluginsResourceBundle.getArgument(NAME); - } - @Override public void configure(Map config) { - predicate = ResourceFilter.includeFilter(config.get(NAME)); + predicate = ResourceFilter.includeFilter(config.get(getName())); } static byte[] compress(byte[] bytesIn) { diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java b/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java index 0c46c030b04a3..5abedddffaa5e 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java @@ -124,6 +124,14 @@ public default String getDescription() { return ""; } + /** + * The plugin usage for printing to console. + * @return The usage. + */ + public default String getUsage() { + return ""; + } + /** * The option that identifies this plugin. This may be null. * "--" is prefixed to the String (when non-null) when invoking diff --git a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties index e993657e3308f..d49dd1d38bdf8 100644 --- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties +++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/plugins.properties @@ -30,6 +30,11 @@ Prepend the specified string, which may include\n\ whitespace, before any other options when invoking the virtual machine\n\ in the resulting image. +add-options.usage=\ +\ --add-options Prepend the specified string, which may\n\ +\ include whitespace, before any other options when\n\ +\ invoking the virtual machine in the resulting image. + release-info.argument=|add:=:=:...|del: release-info.description=\ @@ -38,11 +43,22 @@ add: is to add properties to the 'release' file.\n\ Any number of = pairs can be passed.\n\ del: is to delete the list of keys in release file. +release-info.usage=\ +\ --release-info |add:=:=:...|del:\n\ +\ option is to load release properties from\n\ +\ the supplied file.\n\ +\ add: is to add properties to the 'release' file.\n\ +\ Any number of = pairs can be passed.\n\ +\ del: is to delete the list of keys in release file. + class-for-name.argument= class-for-name.description=\ Class optimization: convert Class.forName calls to constant loads. +class-for-name.usage=\ +\ --class-for-name Class optimization: convert Class.forName calls to constant loads. + compress.argument=<0|1|2>[:filter=] compress.description=\ @@ -53,12 +69,29 @@ Level 2: ZIP.\n\ An optional filter can be specified to list the pattern of\n\ files to be included. +compress.usage=\ +\ --compress <0|1|2>[:filter=]\n\ +\ Compress all resources in the output image.\n\ +\ Level 0: No compression\n\ +\ Level 1: Constant string sharing\n\ +\ Level 2: ZIP.\n\ +\ An optional filter can be\n\ +\ specified to list the pattern of \n\ +\ files to be included. + compact-cp.argument= compact-cp.description=Constant Pool strings sharing.\n\ By default, all resources are compressed. You can express the set \n\ of resources to compress or not compress (use ^ for negation). +compact-cp.usage=\ +\ --compact-cp \n\ +\ Constant Pool strings sharing.\n\ +\ By default, all resources are compressed.\n\ +\ You can express the set of resources to\n\ +\ compress or not compress (use ^ for negation). + dedup-legal-notices.argument=[error-if-not-same-content] dedup-legal-notices.description=\ @@ -66,22 +99,44 @@ De-duplicate all legal notices. If error-if-not-same-content is\n\ specified then it will be an error if two files of the same filename\n\ are different. +dedup-legal-notices.usage=\ +\ --dedup-legal-notices [error-if-not-same-content]\n\ +\ De-duplicate all legal notices.\n\ +\ If error-if-not-same-content is specified then\n\ +\ it will be an error if two files of the same\n\ +\ filename are different. + exclude-files.argument= of files to exclude exclude-files.description=\ Specify files to exclude. e.g.: **.java,glob:/java.base/lib/client/** +exclude-files.usage=\ +\ --exclude-files \n\ +\ Specify files to exclude.\n\ +\ e.g.: **.java,glob:/java.base/lib/client/** + exclude-resources.argument= resources to exclude exclude-resources.description=\ Specify resources to exclude. e.g.: **.jcov,glob:**/META-INF/** +exclude-resources.usage=\ +\ --exclude-resources \n\ +\ Specify resources to exclude.\n\ +\ e.g.: **.jcov,glob:**/META-INF/** + exclude-jmod-section.argument=\n\ where is \"man\" or \"headers". exclude-jmod-section.description=\ Specify a JMOD section to exclude +exclude-jmod-section.usage=\ +\ --exclude-jmod-section \n\ +\ Specify a JMOD section to exclude.\n\ +\ Where is \"man\" or \"headers\". + generate-jli-classes.argument=@filename generate-jli-classes.description=\ @@ -91,10 +146,25 @@ If this plugin runs on a different runtime version than the image being \n\ created then code generation will be disabled by default to guarantee \n\ correctness - add ignore-version=true to override this. +generate-jli-classes.usage=\ +\ --generate-jli-classes @filename\n\ +\ Specify a file listing the java.lang.invoke\n\ +\ classes to pre-generate. By default, this plugin\n\ +\ may use a builtin list of classes to pre-generate.\n\ +\ If this plugin runs on a different runtime version\n\ +\ than the image being created then code generation\n\ +\ will be disabled by default to guarantee \n\ +\ correctness add ignore-version=true\n\ +\ to override this. + system-modules.argument=retainModuleTarget system-modules.description=Fast loading of module descriptors (always enabled) +system-modules.usage=\ +\ --system-modules retainModuleTarget\n\ +\ Fast loading of module descriptors (always enabled) + onoff.argument= order-resources.argument= of paths in priority order. If a @file\n\ @@ -103,42 +173,87 @@ is specified, then each line should be an exact match for the path to be ordered order-resources.description=\ Order resources. e.g.: **/module-info.class,@classlist,/java.base/java/lang/** +order-resources.usage=\ +\ --order-resources \n\ +\ Order resources. \n\ +\ e.g.: **/module-info.class,@classlist,\n\ +\ /java.base/java/lang/** + strip-debug.description=\ Strip debug information from the output image +strip-debug.usage=\ +\ --strip-debug Strip debug information from the output image + strip-java-debug-attributes.description=\ Strip Java debug attributes from classes in the output image +strip-java-debug-attributes.usage=\ +\ --strip-java-debug-attributes \n\ +\ Strip Java debug attributes from\n\ +\ classes in the output image + strip-native-commands.description=\ Exclude native commands (such as java/java.exe) from the image +strip-native-commands.usage=\ +\ --strip-native-commands Exclude native commands (such as java/java.exe)\n\ +\ from the image. + vendor-version.argument= vendor-version.description=\ Override the vendor version string baked into the build, if any.\n\ The value of the system property "java.vendor.version" will be . +vendor-version.usage=\ +\ --vendor-version \n\ +\ Override the vendor version string baked into the\n\ +\ build,if any. The value of the system property\n\ +\ "java.vendor.version" will be . + vendor-bug-url.argument= vendor-bug-url.description=\ Override the vendor bug URL baked into the build. The value\n\ of the system property "java.vendor.url.bug" will be . +vendor-bug-url.usage=\ +\ --vendor-bug-url \n\ +\ Override the vendor bug URL baked into the build.\n\ +\ The value of the system property\n\ +\ "java.vendor.url.bug" will be . + vendor-vm-bug-url.argument= vendor-vm-bug-url.description=\ Override the vendor VM bug URL baked into the build. The URL\n\ displayed in VM error logs will be . +vendor-vm-bug-url.usage=\ +\ --vendor-vm-bug-url \n\ +\ Override the vendor VM bug URL baked \n\ +\ into the build. The URL displayed in VM error\n\ +\ logs will be . + vm.argument= vm.description=\ Select the HotSpot VM in the output image. Default is all +vm.usage=\ +\ --vm \n\ +\ Select the HotSpot VM in the output image.\n\ +\ Default is all + zip.argument=[comma separated list of resource paths] zip.description=ZIP Compression +zip.usage=\ +\ --zip [comma separated list of resource paths]\n\ +\ ZIP Compression + include-locales.argument=\ [,]* @@ -146,6 +261,13 @@ include-locales.description=\ BCP 47 language tags separated by a comma, allowing locale matching\n\ defined in RFC 4647. e.g.: en,ja,*-IN +include-locales.usage=\ +\ --include-locales [,]*\n\ +\ BCP 47 language tags separated by a comma,\n\ +\ allowing\n\ +\ locale matching defined in RFC 4647.\n\ +\ e.g.: en,ja,*-IN + include-locales.missingpackages=\ Missing locale data packages in jdk.localedata:\n\t diff --git a/test/jdk/tools/jlink/IntegrationTest.java b/test/jdk/tools/jlink/IntegrationTest.java index c9df229a44887..dce03bea6d034 100644 --- a/test/jdk/tools/jlink/IntegrationTest.java +++ b/test/jdk/tools/jlink/IntegrationTest.java @@ -168,16 +168,20 @@ private static void test() throws Exception { //Strip debug { Map config1 = new HashMap<>(); - config1.put(DefaultStripDebugPlugin.NAME, ""); Plugin strip = Jlink.newPlugin("strip-debug", config1, null); + config1.put(strip.getName(), ""); lst.add(strip); } // compress { Map config1 = new HashMap<>(); - config1.put(DefaultCompressPlugin.NAME, "2"); + String pluginName = "compress"; + config1.put(pluginName, "2"); Plugin compress - = Jlink.newPlugin("compress", config1, null); + = Jlink.newPlugin(pluginName, config1, null); + if(!pluginName.equals(compress.getName())) { + throw new AssertionError("compress plugin name doesn't match test constant"); + } lst.add(compress); } // Post processor diff --git a/test/jdk/tools/jlink/JLinkTest.java b/test/jdk/tools/jlink/JLinkTest.java index cf6077fef4bcc..bfea2789b9202 100644 --- a/test/jdk/tools/jlink/JLinkTest.java +++ b/test/jdk/tools/jlink/JLinkTest.java @@ -32,6 +32,8 @@ import java.util.Collections; import java.util.List; import java.util.spi.ToolProvider; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import java.util.stream.Stream; import jdk.tools.jlink.plugin.Plugin; @@ -243,13 +245,22 @@ public static void main(String[] args) throws Exception { JLINK_TOOL.run(pw, pw, "--list-plugins"); String output = writer.toString(); - long number = Stream.of(output.split("\\R")) - .filter((s) -> s.matches("Plugin Name:.*")) - .count(); + List commands = Stream.of(output.split("\\R")) + .filter((s) -> s.matches(" --.*")) + .collect(Collectors.toList()); + int number = commands.size(); if (number != totalPlugins) { System.err.println(output); throw new AssertionError("Found: " + number + " expected " + totalPlugins); } + + boolean isSorted = IntStream.range(1, number) + .allMatch((int index) -> commands.get(index).compareTo(commands.get(index - 1)) >= 0); + + if(!isSorted) { + throw new AssertionError("--list-plugins not presented in alphabetical order"); + } + } // filter out files and resources + Skip debug + compress diff --git a/test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.java b/test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.java index 29ee71ff522c4..5550d22777828 100644 --- a/test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.java +++ b/test/jdk/tools/jlink/plugins/ExcludeFilesPluginTest.java @@ -69,8 +69,8 @@ public void test() throws Exception { public void checkFiles(String s, String sample, String module, boolean exclude) throws Exception { Map prop = new HashMap<>(); - prop.put(ExcludeFilesPlugin.NAME, s); ExcludeFilesPlugin fplug = new ExcludeFilesPlugin(); + prop.put(fplug.getName(), s); fplug.configure(prop); ResourcePoolManager files = new ResourcePoolManager(); ResourcePoolManager fresult = new ResourcePoolManager(); diff --git a/test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java b/test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java index 77a8cb0c770cc..11e15df814233 100644 --- a/test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java +++ b/test/jdk/tools/jlink/plugins/ExcludeModuleInfoTest.java @@ -56,8 +56,8 @@ public void test() throws Exception { public void check(String s, String sample) throws Exception { Map prop = new HashMap<>(); - prop.put(ExcludePlugin.NAME, s); ExcludePlugin excludePlugin = new ExcludePlugin(); + prop.put(excludePlugin.getName(), s); excludePlugin.configure(prop); ResourcePoolManager resourcesMgr = new ResourcePoolManager(); ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]); diff --git a/test/jdk/tools/jlink/plugins/ExcludePluginTest.java b/test/jdk/tools/jlink/plugins/ExcludePluginTest.java index fee21c97e4314..badbf951cc9d6 100644 --- a/test/jdk/tools/jlink/plugins/ExcludePluginTest.java +++ b/test/jdk/tools/jlink/plugins/ExcludePluginTest.java @@ -74,8 +74,8 @@ public void test() throws Exception { public void check(String s, String sample, boolean exclude) throws Exception { Map prop = new HashMap<>(); - prop.put(ExcludePlugin.NAME, s); ExcludePlugin excludePlugin = new ExcludePlugin(); + prop.put(excludePlugin.getName(), s); excludePlugin.configure(prop); ResourcePoolManager resourcesMgr = new ResourcePoolManager(); ResourcePoolEntry resource = ResourcePoolEntry.create(sample, new byte[0]); diff --git a/test/jdk/tools/jlink/plugins/ExcludeVMPluginTest.java b/test/jdk/tools/jlink/plugins/ExcludeVMPluginTest.java index 44ded75a6d79e..2326244f50411 100644 --- a/test/jdk/tools/jlink/plugins/ExcludeVMPluginTest.java +++ b/test/jdk/tools/jlink/plugins/ExcludeVMPluginTest.java @@ -187,7 +187,7 @@ private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expect Plugin p = new ExcludeVMPlugin(); Map config = new HashMap<>(); if (vm != null) { - config.put(ExcludeVMPlugin.NAME, vm); + config.put(p.getName(), vm); } p.configure(config); ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder()); diff --git a/test/jdk/tools/jlink/plugins/OrderResourcesPluginTest.java b/test/jdk/tools/jlink/plugins/OrderResourcesPluginTest.java index fe9d2272d8457..b384db3b984a4 100644 --- a/test/jdk/tools/jlink/plugins/OrderResourcesPluginTest.java +++ b/test/jdk/tools/jlink/plugins/OrderResourcesPluginTest.java @@ -93,7 +93,7 @@ public void test() throws Exception { { ResourcePoolManager out = new ResourcePoolManager(); Map config = new HashMap<>(); - config.put(OrderResourcesPlugin.NAME, "/zazou/**,**/module-info.class"); + config.put("order-resources", "/zazou/**,**/module-info.class"); Plugin p = new OrderResourcesPlugin(); p.configure(config); ResourcePool resPool = p.transform(resources.resourcePool(), out.resourcePoolBuilder()); @@ -116,7 +116,7 @@ public void test() throws Exception { ResourcePoolManager out = new ResourcePoolManager(); Map config = new HashMap<>(); - config.put(OrderResourcesPlugin.NAME, "@" + order.getAbsolutePath()); + config.put("order-resources", "@" + order.getAbsolutePath()); Plugin p = new OrderResourcesPlugin(); p.configure(config); ResourcePool resPool = p.transform(resources.resourcePool(), out.resourcePoolBuilder()); From 5310d85809d6b8677aa9b689fc2e21a74ceaccc8 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Tue, 29 Sep 2020 22:46:16 +0000 Subject: [PATCH 67/79] 8252937: Correct "no comment" warnings from javadoc in java.math package Reviewed-by: darcy --- src/java.base/share/classes/java/math/BigDecimal.java | 7 +++++-- src/java.base/share/classes/java/math/BigInteger.java | 7 +++++++ src/java.base/share/classes/java/math/MathContext.java | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/math/BigDecimal.java b/src/java.base/share/classes/java/math/BigDecimal.java index dd9a7c1f97cb0..bb698a555b676 100644 --- a/src/java.base/share/classes/java/math/BigDecimal.java +++ b/src/java.base/share/classes/java/math/BigDecimal.java @@ -4208,7 +4208,9 @@ static void setIntValVolatile(BigDecimal bd, BigInteger val) { * Reconstitute the {@code BigDecimal} instance from a stream (that is, * deserialize it). * - * @param s the stream being read. + * @param s the stream being read. + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if a serialized class cannot be loaded */ @java.io.Serial private void readObject(java.io.ObjectInputStream s) @@ -4227,7 +4229,8 @@ private void readObject(java.io.ObjectInputStream s) /** * Serialize this {@code BigDecimal} to the stream in question * - * @param s the stream to serialize to. + * @param s the stream to serialize to. + * @throws IOException if an I/O error occurs */ @java.io.Serial private void writeObject(java.io.ObjectOutputStream s) diff --git a/src/java.base/share/classes/java/math/BigInteger.java b/src/java.base/share/classes/java/math/BigInteger.java index 1a73abcf1b7d6..febe1fac99a59 100644 --- a/src/java.base/share/classes/java/math/BigInteger.java +++ b/src/java.base/share/classes/java/math/BigInteger.java @@ -4657,6 +4657,10 @@ private int firstNonzeroIntNum() { * marker value. Therefore, no explicit action to set these fields needs to * be taken in readObject because those fields already have a 0 value by * default since defaultReadObject is not being used. + * + * @param s the stream being read. + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if a serialized class cannot be loaded */ @java.io.Serial private void readObject(java.io.ObjectInputStream s) @@ -4724,6 +4728,9 @@ static void putMag(BigInteger bi, int[] magnitude) { * {@code firstNonzeroByteNum}, respectively. These values are compatible * with older implementations, but will be ignored by current * implementations. + * + * @param s the stream to serialize to. + * @throws IOException if an I/O error occurs */ @java.io.Serial private void writeObject(ObjectOutputStream s) throws IOException { diff --git a/src/java.base/share/classes/java/math/MathContext.java b/src/java.base/share/classes/java/math/MathContext.java index 9d40482ee4998..028ede34de6db 100644 --- a/src/java.base/share/classes/java/math/MathContext.java +++ b/src/java.base/share/classes/java/math/MathContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, 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 @@ -308,7 +308,9 @@ public java.lang.String toString() { * Reconstitute the {@code MathContext} instance from a stream (that is, * deserialize it). * - * @param s the stream being read. + * @param s the stream being read. + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if a serialized class cannot be loaded */ @java.io.Serial private void readObject(java.io.ObjectInputStream s) From ffc97ba585b3750a0fe0d29d39a1201d91954d0f Mon Sep 17 00:00:00 2001 From: Alexandre Iline Date: Wed, 30 Sep 2020 01:27:30 +0000 Subject: [PATCH 68/79] 8253543: sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java failed with "AssertionError: All pixels are not black" Reviewed-by: serb --- .../src/ButtonDemoScreenshotTest.java | 51 +++++---- .../SwingSet/src/EditorPaneDemoTest.java | 9 +- .../src/org/jemmy2ext/JemmyExt.java | 102 ++++++++++++++---- .../swingset3/demos/button/ButtonDemo.java | 3 +- 4 files changed, 121 insertions(+), 44 deletions(-) diff --git a/test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java b/test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java index 4c9d52995f18f..a440abcb1ff39 100644 --- a/test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java +++ b/test/jdk/sanity/client/SwingSet/src/ButtonDemoScreenshotTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, 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 @@ -22,6 +22,7 @@ */ import com.sun.swingset3.demos.button.ButtonDemo; +import org.jemmy2ext.JemmyExt; import org.jtregext.GuiTestListener; import org.netbeans.jemmy.ClassReference; import org.netbeans.jemmy.ComponentChooser; @@ -33,7 +34,11 @@ import org.testng.annotations.Test; import java.awt.Component; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.Robot; +import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.swing.UIManager; @@ -72,10 +77,24 @@ public void test(String lookAndFeel) throws Exception { UIManager.setLookAndFeel(lookAndFeel); Robot rob = new Robot(); + //capture some of the background + Dimension screeSize = Toolkit.getDefaultToolkit().getScreenSize(); + Point screenCenter = new Point(screeSize.width / 2, screeSize.height / 2); + Rectangle center = new Rectangle( + screenCenter.x - 50, screenCenter.y - 50, + screenCenter.x + 50, screenCenter.y + 50); + BufferedImage background = rob.createScreenCapture(center); + new ClassReference(ButtonDemo.class.getCanonicalName()).startApplication(); JFrameOperator mainFrame = new JFrameOperator(DEMO_TITLE); - waitImageIsStill(rob, mainFrame); + mainFrame.waitComponentShowing(true); + + //make sure the frame is already painted + waitChangedImage(rob, () -> rob.createScreenCapture(center), + background, mainFrame.getTimeouts(), "background.png"); + //make sure the frame is painted completely + waitStillImage(rob, mainFrame, "frame.png"); // Check all the buttons for (int i : BUTTONS) { @@ -83,7 +102,7 @@ public void test(String lookAndFeel) throws Exception { } } - private void checkButton(JFrameOperator jfo, int i, Robot rob) { + private void checkButton(JFrameOperator jfo, int i, Robot rob) throws InterruptedException { JButtonOperator button = new JButtonOperator(jfo, i); //additional instrumentation for JDK-8198920. To be removed after the bug is fixed @@ -93,9 +112,8 @@ private void checkButton(JFrameOperator jfo, int i, Robot rob) { button.moveMouse(button.getCenterX(), button.getCenterY()); - BufferedImage initialButtonImage = capture(rob, button); - assertNotBlack(initialButtonImage); - save(initialButtonImage, "button" + i + ".png"); + BufferedImage notPressed, pressed = null; + notPressed = waitStillImage(rob, button, "not-pressed-" + i + ".png"); BufferedImage[] pressedImage = new BufferedImage[1]; @@ -108,22 +126,15 @@ private void checkButton(JFrameOperator jfo, int i, Robot rob) { //additional instrumentation for JDK-8198920. To be removed after the bug is fixed button.getOutput().printTrace("JDK-8198920: Button press confirmed by " + System.currentTimeMillis()); //end of instrumentation for JDK-8198920 - button.waitState(new ComponentChooser() { - public boolean checkComponent(Component c) { - pressedImage[0] = capture(rob, button); - assertNotBlack(pressedImage[0]); - return !sComparator.compare(initialButtonImage, pressedImage[0]); - } - - public String getDescription() { - return "Button with new image"; - } - }); + waitChangedImage(rob, () -> capture(rob, button), notPressed, + button.getTimeouts(), "pressed-" + i + ".png"); + pressed = waitStillImage(rob, button, "pressed.png"); } finally { - if (pressedImage[0] != null) { - save(pressedImage[0], "button" + i + "_pressed.png"); - } button.releaseMouse(); + if(pressed != null) { + waitChangedImage(rob, () -> capture(rob, button), pressed, + button.getTimeouts(), "released-" + i + ".png"); + } //additional instrumentation for JDK-8198920. To be removed after the bug is fixed button.getOutput().printTrace("JDK-8198920: Button released at " + System.currentTimeMillis()); try { diff --git a/test/jdk/sanity/client/SwingSet/src/EditorPaneDemoTest.java b/test/jdk/sanity/client/SwingSet/src/EditorPaneDemoTest.java index 325c087f133fe..268ea254eb35a 100644 --- a/test/jdk/sanity/client/SwingSet/src/EditorPaneDemoTest.java +++ b/test/jdk/sanity/client/SwingSet/src/EditorPaneDemoTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, 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,8 +23,8 @@ import static com.sun.swingset3.demos.editorpane.EditorPaneDemo.DEMO_TITLE; import static com.sun.swingset3.demos.editorpane.EditorPaneDemo.SOURCE_FILES; -import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR; -import static org.jemmy2ext.JemmyExt.assertNotBlack; +import static org.jemmy2ext.JemmyExt.*; +import static org.testng.Assert.assertFalse; import java.awt.Color; import java.awt.Dimension; @@ -149,7 +149,8 @@ private void checkImage(JEditorPaneOperator editorPaneOperator, final int xGap = 100, yGap = 40, columns = 2, rows = 5; editorPaneOperator.waitState(comp -> { BufferedImage capturedImage = ImageTool.getImage(imageRect); - assertNotBlack(capturedImage); + save(capturedImage, "editor.png"); + assertFalse(isBlack(capturedImage), "image blackness"); int x = 0, y = 0, i = 0, j; for (; i < columns; i++) { x += xGap; diff --git a/test/jdk/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java b/test/jdk/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java index 8063c60c9861f..948e1541fcad4 100644 --- a/test/jdk/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java +++ b/test/jdk/sanity/client/lib/Extensions/src/org/jemmy2ext/JemmyExt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,6 +40,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.IntStream; @@ -56,9 +57,11 @@ import org.netbeans.jemmy.DefaultCharBindingMap; import org.netbeans.jemmy.QueueTool; import org.netbeans.jemmy.TimeoutExpiredException; +import org.netbeans.jemmy.Timeouts; import org.netbeans.jemmy.Waitable; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.drivers.scrolling.JSpinnerDriver; +import org.netbeans.jemmy.image.ImageComparator; import org.netbeans.jemmy.image.StrictImageComparator; import org.netbeans.jemmy.operators.ComponentOperator; import org.netbeans.jemmy.operators.ContainerOperator; @@ -89,17 +92,13 @@ public class JemmyExt { DefaultCharBindingMap.class }; - public static void assertNotBlack(BufferedImage image) { - int w = image.getWidth(); - int h = image.getHeight(); - try { - assertFalse("All pixels are not black", IntStream.range(0, w).parallel().allMatch(x - -> IntStream.range(0, h).allMatch(y -> (image.getRGB(x, y) & 0xffffff) == 0) - )); - } catch (Throwable t) { - save(image, "allPixelsAreBlack.png"); - throw t; - } + /** + * Checks if the image is complitely black. + */ + public static boolean isBlack(BufferedImage image) { + return IntStream.range(0, image.getWidth()).parallel() + .allMatch(x-> IntStream.range(0, image.getHeight()) + .allMatch(y -> (image.getRGB(x, y) & 0xffffff) == 0)); } public static void waitArmed(JButtonOperator button) { @@ -184,18 +183,46 @@ public static void save(BufferedImage image, String filename) { } } - public static void waitImageIsStill(Robot rob, ComponentOperator operator) { - operator.waitState(new ComponentChooser() { + /** + * Waits for a screen area taken by a component to not be completely black rectangle. + * @return last (non-black) image + * @throws TimeoutExpiredException if the waiting is unsuccessful + */ + public static BufferedImage waitNotBlack(Robot rob, ComponentOperator operator, String imageName) { + class NonBlackImageChooser implements ComponentChooser { + private BufferedImage image = null; + @Override + public boolean checkComponent(Component comp) { + image = capture(rob, operator); + save(image, imageName); + return !isBlack(image); + } + + @Override + public String getDescription() { + return "A non-black Image of " + operator; + } + } + NonBlackImageChooser chooser = new NonBlackImageChooser(); + operator.waitState(chooser); + return chooser.image; + } + /** + * Waits for the displayed image to be still. + * @return last still image + * @throws TimeoutExpiredException if the waiting is unsuccessful + */ + public static BufferedImage waitStillImage(Robot rob, ComponentOperator operator, String imageName) { + operator.getTimeouts().setTimeout("Waiter.TimeDelta", 1000); + class StillImageChooser implements ComponentChooser { private BufferedImage previousImage = null; - private int index = 0; private final StrictImageComparator sComparator = new StrictImageComparator(); @Override public boolean checkComponent(Component comp) { BufferedImage currentImage = capture(rob, operator); - save(currentImage, "waitImageIsStill" + index + ".png"); - index++; + save(currentImage, imageName); boolean compareResult = previousImage == null ? false : sComparator.compare(currentImage, previousImage); previousImage = currentImage; return compareResult; @@ -203,9 +230,46 @@ public boolean checkComponent(Component comp) { @Override public String getDescription() { - return "Image of " + operator + " is still"; + return "A still image of " + operator; } - }); + } + StillImageChooser chooser = new StillImageChooser(); + operator.waitState(chooser); + return chooser.previousImage; + } + + /** + * Waits for the displayed image to change. + * @param reference image to compare to + * @return last (changed) image + * @throws TimeoutExpiredException if the waiting is unsuccessful + */ + public static BufferedImage waitChangedImage(Robot rob, + Supplier supplier, + BufferedImage reference, + Timeouts timeouts, + String imageName) throws InterruptedException { + ImageComparator comparator = new StrictImageComparator(); + class ImageWaitable implements Waitable { + BufferedImage image; + + @Override + public Object actionProduced(Object obj) { + image = supplier.get(); + save(image, imageName); + return comparator.compare(reference, image) ? null : image; + } + + @Override + public String getDescription() { + return "Waiting screen image to change"; + } + } + ImageWaitable waitable = new ImageWaitable(); + Waiter waiter = new Waiter(waitable); + waiter.setTimeouts(timeouts); + waiter.waitAction(null); + return waitable.image; } private static class ThrowableHolder { diff --git a/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/button/ButtonDemo.java b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/button/ButtonDemo.java index 358ae49d64b78..f9bcd0a5ef9cd 100644 --- a/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/button/ButtonDemo.java +++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/button/ButtonDemo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2020, 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 @@ -218,6 +218,7 @@ public static void main(String args[]) throws InterruptedException, InvocationTa JFrame frame = new JFrame(DEMO_TITLE); frame.add(buttonDemo); frame.pack(); + frame.setLocationRelativeTo(null); frame.setVisible(true); }); } From a55cde4d6bf189dc709c652bf487481729875b02 Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 30 Sep 2020 02:43:10 +0000 Subject: [PATCH 69/79] 8252002: remove usage of PropertyResolvingWrapper in vmTestbase/nsk/jdwp Reviewed-by: cjplummer, sspitsyn --- .../getvalues001/TestDescription.java | 5 +- .../getvalues002/TestDescription.java | 5 +- .../Length/length001/TestDescription.java | 5 +- .../setvalues001/TestDescription.java | 5 +- .../newinstance001/TestDescription.java | 5 +- .../visibclasses001/TestDescription.java | 5 +- .../reflectype001/TestDescription.java | 5 +- .../invokemeth001/TestDescription.java | 5 +- .../newinst001/TestDescription.java | 5 +- .../setvalues001/TestDescription.java | 5 +- .../superclass001/TestDescription.java | 5 +- .../breakpoint001/TestDescription.java | 5 +- .../clsprepare001/TestDescription.java | 5 +- .../clsunload001/TestDescription.java | 5 +- .../composite001/TestDescription.java | 5 +- .../exception001/TestDescription.java | 5 +- .../fldaccess001/TestDescription.java | 5 +- .../fldmodification001/TestDescription.java | 5 +- .../methentry001/TestDescription.java | 5 +- .../methexit001/TestDescription.java | 5 +- .../singlestep001/TestDescription.java | 5 +- .../singlestep002/TestDescription.java | 5 +- .../singlestep003/TestDescription.java | 5 +- .../thrdeath001/TestDescription.java | 5 +- .../thrstart001/TestDescription.java | 5 +- .../VM_DEATH/vmdeath001/TestDescription.java | 5 +- .../VM_DEATH/vmdeath002/TestDescription.java | 5 +- .../VM_START/vmstart001/TestDescription.java | 5 +- .../Clear/clear001/TestDescription.java | 5 +- .../clrallbreakp001/TestDescription.java | 5 +- .../clrallbreakp002/TestDescription.java | 5 +- .../clrallbreakp003/TestDescription.java | 5 +- .../Set/set001/TestDescription.java | 5 +- .../Set/set002/TestDescription.java | 5 +- .../bytecodes001/TestDescription.java | 5 +- .../isobsolete001/TestDescription.java | 5 +- .../isobsolete002/TestDescription.java | 5 +- .../linetable001/TestDescription.java | 5 +- .../vartable001/TestDescription.java | 5 +- .../vartblwithgen001/TestDescription.java | 5 +- .../disablecol001/TestDescription.java | 5 +- .../enablecol001/TestDescription.java | 5 +- .../getvalues001/TestDescription.java | 5 +- .../invokemeth001/TestDescription.java | 5 +- .../iscollected001/TestDescription.java | 5 +- .../monitorinfo001/TestDescription.java | 5 +- .../referencetype001/TestDescription.java | 5 +- .../referringObjects001.java | 16 ++-- .../referringObjects002.java | 30 ++++--- .../setvalues001/TestDescription.java | 5 +- .../classloader001/TestDescription.java | 5 +- .../classobj001/TestDescription.java | 5 +- .../Fields/fields001/TestDescription.java | 5 +- .../fldwithgeneric001/TestDescription.java | 5 +- .../getvalues001/TestDescription.java | 5 +- .../Instances/instances001/instances001.java | 16 ++-- .../Instances/instances002/instances002.java | 30 ++++--- .../interfaces001/TestDescription.java | 5 +- .../Methods/methods001/TestDescription.java | 5 +- .../methwithgeneric001/TestDescription.java | 5 +- .../modifiers001/TestDescription.java | 5 +- .../nestedtypes001/TestDescription.java | 5 +- .../signature001/TestDescription.java | 5 +- .../sigwithgeneric001/TestDescription.java | 5 +- .../srcdebugext001/TestDescription.java | 5 +- .../srcfile001/TestDescription.java | 5 +- .../Status/status001/TestDescription.java | 5 +- .../getvalues001/TestDescription.java | 5 +- .../popframes001/TestDescription.java | 5 +- .../setvalues001/TestDescription.java | 5 +- .../thisobject001/TestDescription.java | 5 +- .../Value/value001/TestDescription.java | 5 +- .../jtreg/vmTestbase/nsk/jdwp/TEST.properties | 2 - .../Children/children001/TestDescription.java | 5 +- .../Name/name001/TestDescription.java | 5 +- .../Parent/parent001/TestDescription.java | 5 +- .../curcontmonitor001/TestDescription.java | 5 +- .../forceEarlyReturn001.java | 85 ++++++++----------- .../forceEarlyReturn002.java | 17 ++-- .../framecnt001/TestDescription.java | 5 +- .../Frames/frames001/TestDescription.java | 5 +- .../interrupt001/TestDescription.java | 5 +- .../Name/name001/TestDescription.java | 5 +- .../ownmonitors001/TestDescription.java | 5 +- .../ownedMonitorsStackDepthInfo001.java | 35 ++++---- .../ownedMonitorsStackDepthInfo002.java | 17 ++-- .../Resume/resume001/TestDescription.java | 5 +- .../Status/status001/TestDescription.java | 5 +- .../Stop/stop001/TestDescription.java | 5 +- .../Suspend/suspend001/TestDescription.java | 5 +- .../suspendcnt001/TestDescription.java | 5 +- .../threadgroup001/TestDescription.java | 5 +- .../allclasses001/TestDescription.java | 5 +- .../allclswithgeneric001/TestDescription.java | 5 +- .../allthreads001/TestDescription.java | 5 +- .../capabilities001/TestDescription.java | 5 +- .../capabilitiesnew001/TestDescription.java | 5 +- .../classpaths001/TestDescription.java | 5 +- .../classbysig001/TestDescription.java | 5 +- .../createstr001/TestDescription.java | 5 +- .../Dispose/dispose001/TestDescription.java | 5 +- .../disposeobj001/TestDescription.java | 5 +- .../Exit/exit001/TestDescription.java | 5 +- .../holdevents001/TestDescription.java | 5 +- .../holdevents002/TestDescription.java | 5 +- .../IDSizes/idsizes001/TestDescription.java | 5 +- .../instanceCounts001/instanceCounts001.java | 37 ++++---- .../redefinecls001/TestDescription.java | 5 +- .../releaseevents001/TestDescription.java | 5 +- .../releaseevents002/TestDescription.java | 5 +- .../Resume/resume001/TestDescription.java | 5 +- .../setdefstrat001/TestDescription.java | 5 +- .../threadgroups001/TestDescription.java | 5 +- .../Version/version001/TestDescription.java | 5 +- .../Version/version002/TestDescription.java | 5 +- 115 files changed, 355 insertions(+), 455 deletions(-) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jdwp/TEST.properties diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java index 55234a5763364..4fc9630df3c87 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ArrayReference.GetValues.getvalues001 - * nsk.jdwp.ArrayReference.GetValues.getvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ArrayReference.GetValues.getvalues001a + * @run main/othervm * nsk.jdwp.ArrayReference.GetValues.getvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java index 9ef8cb8060d4d..92b567dccf276 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/GetValues/getvalues002/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ArrayReference.GetValues.getvalues002 - * nsk.jdwp.ArrayReference.GetValues.getvalues002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ArrayReference.GetValues.getvalues002a + * @run main/othervm * nsk.jdwp.ArrayReference.GetValues.getvalues002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java index 824363c9a6e65..164d8c8ecab8d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/Length/length001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ArrayReference.Length.length001 - * nsk.jdwp.ArrayReference.Length.length001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ArrayReference.Length.length001a + * @run main/othervm * nsk.jdwp.ArrayReference.Length.length001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java index 32f77a3d53e07..380ba4549ef48 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayReference/SetValues/setvalues001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ArrayReference.SetValues.setvalues001 - * nsk.jdwp.ArrayReference.SetValues.setvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ArrayReference.SetValues.setvalues001a + * @run main/othervm * nsk.jdwp.ArrayReference.SetValues.setvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java index aaddac40f10c1..7376e32c3cc3b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ArrayType/NewInstance/newinstance001/TestDescription.java @@ -54,9 +54,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ArrayType.NewInstance.newinstance001 - * nsk.jdwp.ArrayType.NewInstance.newinstance001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ArrayType.NewInstance.newinstance001a + * @run main/othervm * nsk.jdwp.ArrayType.NewInstance.newinstance001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java index ec0da5f5be340..b298e05d72175 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassLoaderReference/VisibleClasses/visibclasses001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001 - * nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001a + * @run main/othervm * nsk.jdwp.ClassLoaderReference.VisibleClasses.visibclasses001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java index 1f652117bc13d..f476b8df0c807 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassObjectReference/ReflectedType/reflectype001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001 - * nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001a + * @run main/othervm * nsk.jdwp.ClassObjectReference.ReflectedType.reflectype001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java index 30175113456c3..9b97c95b32f1d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/InvokeMethod/invokemeth001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassType.InvokeMethod.invokemeth001 - * nsk.jdwp.ClassType.InvokeMethod.invokemeth001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassType.InvokeMethod.invokemeth001a + * @run main/othervm * nsk.jdwp.ClassType.InvokeMethod.invokemeth001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java index e476b7c035a9a..6132dbc6a4d32 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/NewInstance/newinst001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassType.NewInstance.newinst001 - * nsk.jdwp.ClassType.NewInstance.newinst001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassType.NewInstance.newinst001a + * @run main/othervm * nsk.jdwp.ClassType.NewInstance.newinst001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java index dee634f9a8c89..0f5a71aefda4b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001/TestDescription.java @@ -65,9 +65,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassType.SetValues.setvalues001 - * nsk.jdwp.ClassType.SetValues.setvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassType.SetValues.setvalues001a + * @run main/othervm * nsk.jdwp.ClassType.SetValues.setvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java index 200f97d81097b..02082032398f5 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/Superclass/superclass001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ClassType.Superclass.superclass001 - * nsk.jdwp.ClassType.Superclass.superclass001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ClassType.Superclass.superclass001a + * @run main/othervm * nsk.jdwp.ClassType.Superclass.superclass001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java index fdc86606fc589..f4583fc101552 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/BREAKPOINT/breakpoint001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.BREAKPOINT.breakpoint001 - * nsk.jdwp.Event.BREAKPOINT.breakpoint001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.BREAKPOINT.breakpoint001a + * @run main/othervm * nsk.jdwp.Event.BREAKPOINT.breakpoint001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001/TestDescription.java index a505c7dc7f685..8690a9d6125f4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_PREPARE/clsprepare001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.CLASS_PREPARE.clsprepare001 - * nsk.jdwp.Event.CLASS_PREPARE.clsprepare001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.CLASS_PREPARE.clsprepare001a + * @run main/othervm * nsk.jdwp.Event.CLASS_PREPARE.clsprepare001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_UNLOAD/clsunload001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_UNLOAD/clsunload001/TestDescription.java index c4677500fca86..2d323c7193143 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_UNLOAD/clsunload001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/CLASS_UNLOAD/clsunload001/TestDescription.java @@ -61,9 +61,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.CLASS_UNLOAD.clsunload001 - * nsk.jdwp.Event.CLASS_UNLOAD.clsunload001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.CLASS_UNLOAD.clsunload001a + * @run main/othervm * nsk.jdwp.Event.CLASS_UNLOAD.clsunload001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/Composite/composite001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/Composite/composite001/TestDescription.java index 1ecdfed05a2ef..5cf8976cb8806 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/Composite/composite001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/Composite/composite001/TestDescription.java @@ -48,9 +48,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.Composite.composite001 - * nsk.jdwp.Event.Composite.composite001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.Composite.composite001a + * @run main/othervm * nsk.jdwp.Event.Composite.composite001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001/TestDescription.java index 55a9cb3f674a6..9524d171c4bc2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001/TestDescription.java @@ -63,9 +63,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.EXCEPTION.exception001 - * nsk.jdwp.Event.EXCEPTION.exception001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.EXCEPTION.exception001a + * @run main/othervm * nsk.jdwp.Event.EXCEPTION.exception001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_ACCESS/fldaccess001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_ACCESS/fldaccess001/TestDescription.java index 2d8a56521f0cb..d0c835009d60c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_ACCESS/fldaccess001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_ACCESS/fldaccess001/TestDescription.java @@ -62,9 +62,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.FIELD_ACCESS.fldaccess001 - * nsk.jdwp.Event.FIELD_ACCESS.fldaccess001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.FIELD_ACCESS.fldaccess001a + * @run main/othervm * nsk.jdwp.Event.FIELD_ACCESS.fldaccess001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_MODIFICATION/fldmodification001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_MODIFICATION/fldmodification001/TestDescription.java index e8c74137fe8ba..5055936173d11 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_MODIFICATION/fldmodification001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/FIELD_MODIFICATION/fldmodification001/TestDescription.java @@ -63,9 +63,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.FIELD_MODIFICATION.fldmodification001 - * nsk.jdwp.Event.FIELD_MODIFICATION.fldmodification001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.FIELD_MODIFICATION.fldmodification001a + * @run main/othervm * nsk.jdwp.Event.FIELD_MODIFICATION.fldmodification001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_ENTRY/methentry001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_ENTRY/methentry001/TestDescription.java index 2aebd7772e60f..e41084de6281f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_ENTRY/methentry001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_ENTRY/methentry001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.METHOD_ENTRY.methentry001 - * nsk.jdwp.Event.METHOD_ENTRY.methentry001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.METHOD_ENTRY.methentry001a + * @run main/othervm * nsk.jdwp.Event.METHOD_ENTRY.methentry001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_EXIT/methexit001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_EXIT/methexit001/TestDescription.java index 62c9c2e460a94..bd765e2ea8846 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_EXIT/methexit001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/METHOD_EXIT/methexit001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.METHOD_EXIT.methexit001 - * nsk.jdwp.Event.METHOD_EXIT.methexit001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.METHOD_EXIT.methexit001a + * @run main/othervm * nsk.jdwp.Event.METHOD_EXIT.methexit001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep001/TestDescription.java index 37b06e72a4211..7d7afefd44603 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep001/TestDescription.java @@ -62,9 +62,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.SINGLE_STEP.singlestep001 - * nsk.jdwp.Event.SINGLE_STEP.singlestep001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.SINGLE_STEP.singlestep001a + * @run main/othervm * nsk.jdwp.Event.SINGLE_STEP.singlestep001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep002/TestDescription.java index ca480a52c67f6..ac11ead1f0925 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep002/TestDescription.java @@ -62,9 +62,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.SINGLE_STEP.singlestep002 - * nsk.jdwp.Event.SINGLE_STEP.singlestep002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.SINGLE_STEP.singlestep002a + * @run main/othervm * nsk.jdwp.Event.SINGLE_STEP.singlestep002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep003/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep003/TestDescription.java index 35408ce6dd5bc..00cf70a223d8f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep003/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/SINGLE_STEP/singlestep003/TestDescription.java @@ -62,9 +62,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.SINGLE_STEP.singlestep003 - * nsk.jdwp.Event.SINGLE_STEP.singlestep003a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.SINGLE_STEP.singlestep003a + * @run main/othervm * nsk.jdwp.Event.SINGLE_STEP.singlestep003 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_DEATH/thrdeath001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_DEATH/thrdeath001/TestDescription.java index 15f473e83b5f5..85dd77be7e9ca 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_DEATH/thrdeath001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_DEATH/thrdeath001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.THREAD_DEATH.thrdeath001 - * nsk.jdwp.Event.THREAD_DEATH.thrdeath001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.THREAD_DEATH.thrdeath001a + * @run main/othervm * nsk.jdwp.Event.THREAD_DEATH.thrdeath001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_START/thrstart001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_START/thrstart001/TestDescription.java index 97239d0b35876..a43503248490b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_START/thrstart001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/THREAD_START/thrstart001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.THREAD_START.thrstart001 - * nsk.jdwp.Event.THREAD_START.thrstart001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.THREAD_START.thrstart001a + * @run main/othervm * nsk.jdwp.Event.THREAD_START.thrstart001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath001/TestDescription.java index f2e58a04c9d2f..e1f3b1053b489 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath001/TestDescription.java @@ -52,9 +52,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.VM_DEATH.vmdeath001 - * nsk.jdwp.Event.VM_DEATH.vmdeath001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.VM_DEATH.vmdeath001a + * @run main/othervm * nsk.jdwp.Event.VM_DEATH.vmdeath001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath002/TestDescription.java index 96b202b566d76..f0dbd749a3271 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_DEATH/vmdeath002/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.VM_DEATH.vmdeath002 - * nsk.jdwp.Event.VM_DEATH.vmdeath002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.VM_DEATH.vmdeath002a + * @run main/othervm * nsk.jdwp.Event.VM_DEATH.vmdeath002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_START/vmstart001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_START/vmstart001/TestDescription.java index 0fd0cdcefeac0..139db45bef5b5 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_START/vmstart001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/VM_START/vmstart001/TestDescription.java @@ -50,9 +50,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Event.VM_START.vmstart001 - * nsk.jdwp.Event.VM_START.vmstart001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Event.VM_START.vmstart001a + * @run main/othervm * nsk.jdwp.Event.VM_START.vmstart001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Clear/clear001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Clear/clear001/TestDescription.java index 5369f839ace6d..acc4090eb10e6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Clear/clear001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Clear/clear001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.Clear.clear001 - * nsk.jdwp.EventRequest.Clear.clear001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.Clear.clear001a + * @run main/othervm * nsk.jdwp.EventRequest.Clear.clear001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp001/TestDescription.java index c0a76b1b97719..49c6d12afa525 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp001 - * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp001a + * @run main/othervm * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002/TestDescription.java index dd80c745d4ace..981b8fccb5efc 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp002/TestDescription.java @@ -49,9 +49,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp002 - * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp002a + * @run main/othervm * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003/TestDescription.java index 82c3f12addeff..15acb91350c34 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/ClearAllBreakpoints/clrallbreakp003/TestDescription.java @@ -52,9 +52,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp003 - * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp003a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp003a + * @run main/othervm * nsk.jdwp.EventRequest.ClearAllBreakpoints.clrallbreakp003 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set001/TestDescription.java index 6caca4e0bcce6..d04dc2f9328d8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set001/TestDescription.java @@ -58,9 +58,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.Set.set001 - * nsk.jdwp.EventRequest.Set.set001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.Set.set001a + * @run main/othervm * nsk.jdwp.EventRequest.Set.set001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set002/TestDescription.java index 70f02792c2950..efd3b66692425 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/EventRequest/Set/set002/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.EventRequest.Set.set002 - * nsk.jdwp.EventRequest.Set.set002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.EventRequest.Set.set002a + * @run main/othervm * nsk.jdwp.EventRequest.Set.set002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001/TestDescription.java index 492f2ba2a9171..b522bbedaa4bb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/Bytecodes/bytecodes001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Method.Bytecodes.bytecodes001 - * nsk.jdwp.Method.Bytecodes.bytecodes001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Method.Bytecodes.bytecodes001a + * @run main/othervm * nsk.jdwp.Method.Bytecodes.bytecodes001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001/TestDescription.java index a362bf7951d6c..c3b3b3c049d11 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Method.IsObsolete.isobsolete001 - * nsk.jdwp.Method.IsObsolete.isobsolete001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Method.IsObsolete.isobsolete001a + * @run main/othervm * nsk.jdwp.Method.IsObsolete.isobsolete001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete002/TestDescription.java index ad262e025db0a..ce9fc223daefe 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/IsObsolete/isobsolete002/TestDescription.java @@ -68,12 +68,11 @@ * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib * @build ExecDriver - * @build nsk.jdwp.Method.IsObsolete.isobsolete002 - * nsk.jdwp.Method.IsObsolete.isobsolete002a + * @build nsk.jdwp.Method.IsObsolete.isobsolete002a * nsk.jdwp.Method.IsObsolete.isobsolete002b * @run driver nsk.share.ExtraClassesBuilder * newclass - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.Method.IsObsolete.isobsolete002 * . * -arch=${os.family}-${os.simpleArch} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/LineTable/linetable001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/LineTable/linetable001/TestDescription.java index b289d282321d5..d5dad5cc97926 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/LineTable/linetable001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/LineTable/linetable001/TestDescription.java @@ -67,9 +67,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Method.LineTable.linetable001 - * nsk.jdwp.Method.LineTable.linetable001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.Method.LineTable.linetable001a + * @run main/othervm * nsk.jdwp.Method.LineTable.linetable001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTable/vartable001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTable/vartable001/TestDescription.java index c0bdce8fa815b..f5633b360f332 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTable/vartable001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTable/vartable001/TestDescription.java @@ -56,12 +56,11 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Method.VariableTable.vartable001 - * nsk.jdwp.Method.VariableTable.vartable001a + * @build nsk.jdwp.Method.VariableTable.vartable001a * @comment debuggee should be compiled w/ debug info * @clean nsk.jdwp.Method.VariableTable.vartable001a * @compile -g:lines,source,vars ../vartable001a.java - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.Method.VariableTable.vartable001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001/TestDescription.java index 1244e69172d2a..7741b0226187b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001/TestDescription.java @@ -56,12 +56,11 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.Method.VariableTableWithGeneric.vartblwithgen001 - * nsk.jdwp.Method.VariableTableWithGeneric.vartblwithgen001a + * @build nsk.jdwp.Method.VariableTableWithGeneric.vartblwithgen001a * @comment debuggee should be compiled w/ debug info * @clean nsk.jdwp.Method.VariableTableWithGeneric.vartblwithgen001a * @compile -g:lines,source,vars ../vartblwithgen001a.java - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.Method.VariableTableWithGeneric.vartblwithgen001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001/TestDescription.java index b2a9546d86b4f..9e50200593e7e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/DisableCollection/disablecol001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.DisableCollection.disablecol001 - * nsk.jdwp.ObjectReference.DisableCollection.disablecol001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.DisableCollection.disablecol001a + * @run main/othervm * nsk.jdwp.ObjectReference.DisableCollection.disablecol001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001/TestDescription.java index 860844bbe5059..d2dd41472e9f7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/EnableCollection/enablecol001/TestDescription.java @@ -54,9 +54,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.EnableCollection.enablecol001 - * nsk.jdwp.ObjectReference.EnableCollection.enablecol001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.EnableCollection.enablecol001a + * @run main/othervm * nsk.jdwp.ObjectReference.EnableCollection.enablecol001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001/TestDescription.java index a40b457426c08..7ecb552e6c9d8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/GetValues/getvalues001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.GetValues.getvalues001 - * nsk.jdwp.ObjectReference.GetValues.getvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.GetValues.getvalues001a + * @run main/othervm * nsk.jdwp.ObjectReference.GetValues.getvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/InvokeMethod/invokemeth001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/InvokeMethod/invokemeth001/TestDescription.java index 460b9e39647ba..71bfafa7718f6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/InvokeMethod/invokemeth001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/InvokeMethod/invokemeth001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.InvokeMethod.invokemeth001 - * nsk.jdwp.ObjectReference.InvokeMethod.invokemeth001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.InvokeMethod.invokemeth001a + * @run main/othervm * nsk.jdwp.ObjectReference.InvokeMethod.invokemeth001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/IsCollected/iscollected001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/IsCollected/iscollected001/TestDescription.java index 1da1282d0afb3..fda668d8b3201 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/IsCollected/iscollected001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/IsCollected/iscollected001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.IsCollected.iscollected001 - * nsk.jdwp.ObjectReference.IsCollected.iscollected001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.IsCollected.iscollected001a + * @run main/othervm * nsk.jdwp.ObjectReference.IsCollected.iscollected001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/MonitorInfo/monitorinfo001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/MonitorInfo/monitorinfo001/TestDescription.java index 933a206543c50..cf58779b87dd3 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/MonitorInfo/monitorinfo001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/MonitorInfo/monitorinfo001/TestDescription.java @@ -68,9 +68,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.MonitorInfo.monitorinfo001 - * nsk.jdwp.ObjectReference.MonitorInfo.monitorinfo001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.MonitorInfo.monitorinfo001a + * @run main/othervm * nsk.jdwp.ObjectReference.MonitorInfo.monitorinfo001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferenceType/referencetype001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferenceType/referencetype001/TestDescription.java index c7069367d2071..0e7e8b9bb6b2e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferenceType/referencetype001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferenceType/referencetype001/TestDescription.java @@ -58,9 +58,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.ReferenceType.referencetype001 - * nsk.jdwp.ObjectReference.ReferenceType.referencetype001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.ReferenceType.referencetype001a + * @run main/othervm * nsk.jdwp.ObjectReference.ReferenceType.referencetype001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects001/referringObjects001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects001/referringObjects001.java index 4c637ae14a286..c9ee73fa67c96 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects001/referringObjects001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects001/referringObjects001.java @@ -69,8 +69,7 @@ * @requires !vm.graal.enabled * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.ReferringObjects.referringObjects001.referringObjects001 - * @run main/othervm/native PropertyResolvingWrapper + * @run main/othervm/native * nsk.jdwp.ObjectReference.ReferringObjects.referringObjects001.referringObjects001 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -82,10 +81,13 @@ package nsk.jdwp.ObjectReference.ReferringObjects.referringObjects001; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; -import nsk.share.jpda.AbstractDebuggeeTest; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class referringObjects001 extends TestDebuggerType1 { @@ -93,11 +95,11 @@ protected String getDebugeeClassName() { return nsk.jdwp.ObjectReference.ReferringObjects.referringObjects001.referringObjects001a.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new referringObjects001().runIt(argv, out); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects002/referringObjects002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects002/referringObjects002.java index d9b38851eaeff..4ad6b6ae32881 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects002/referringObjects002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/ReferringObjects/referringObjects002/referringObjects002.java @@ -58,8 +58,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.ReferringObjects.referringObjects002.referringObjects002 - * @run main/othervm/native PropertyResolvingWrapper + * @run main/othervm/native * nsk.jdwp.ObjectReference.ReferringObjects.referringObjects002.referringObjects002 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -71,20 +70,24 @@ package nsk.jdwp.ObjectReference.ReferringObjects.referringObjects002; -import java.io.PrintStream; import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class referringObjects002 extends TestDebuggerType1 { protected String getDebugeeClassName() { return nsk.jdwp.ObjectReference.ReferringObjects.referringObjects002.referringObjects002a.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new referringObjects002().runIt(argv, out); } @@ -124,7 +127,7 @@ private void testCommand() { setSuccess(false); } - long expectedReferrersID[] = new long[expectedReferrersCount]; + long[] expectedReferrersID = new long[expectedReferrersCount]; // initialize expected IDs of referrers for (int i = 0; i < expectedReferrersCount; i++) { @@ -132,21 +135,21 @@ private void testCommand() { + (i + 1)); } - long receivedReferrersID[] = new long[referringObjects]; + long[] receivedReferrersID = new long[referringObjects]; for (int i = 0; i < referringObjects; i++) { JDWP.Value value = reply.getValue(); log.display("tagged-ObjectID = " + value); - receivedReferrersID[i] = ((Long) value.getValue()).longValue(); + receivedReferrersID[i] = (Long) value.getValue(); } // check that correct IDs of referrers was received for (int i = 0; i < referringObjects; i++) { boolean isIDExpected = false; - for (int j = 0; j < expectedReferrersID.length; j++) { - if (receivedReferrersID[i] == expectedReferrersID[j]) { + for (long l : expectedReferrersID) { + if (receivedReferrersID[i] == l) { isIDExpected = true; break; } @@ -160,8 +163,9 @@ private void testCommand() { if (!getSuccess()) { log.complain("Expected IDs:"); - for (int i = 0; i < expectedReferrersID.length; i++) - log.complain("" + expectedReferrersID[i]); + for (long l : expectedReferrersID) { + log.complain("" + l); + } } if (!reply.isParsed()) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001/TestDescription.java index 146be486185cd..9fc3f9949cfe2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001/TestDescription.java @@ -67,9 +67,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ObjectReference.SetValues.setvalues001 - * nsk.jdwp.ObjectReference.SetValues.setvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ObjectReference.SetValues.setvalues001a + * @run main/othervm * nsk.jdwp.ObjectReference.SetValues.setvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassLoader/classloader001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassLoader/classloader001/TestDescription.java index a149bb8672f60..be36b5eccee5b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassLoader/classloader001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassLoader/classloader001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.ClassLoader.classloader001 - * nsk.jdwp.ReferenceType.ClassLoader.classloader001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.ClassLoader.classloader001a + * @run main/othervm * nsk.jdwp.ReferenceType.ClassLoader.classloader001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassObject/classobj001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassObject/classobj001/TestDescription.java index 25eef4d52a993..12baa51bca2cc 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassObject/classobj001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/ClassObject/classobj001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.ClassObject.classobj001 - * nsk.jdwp.ReferenceType.ClassObject.classobj001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.ClassObject.classobj001a + * @run main/othervm * nsk.jdwp.ReferenceType.ClassObject.classobj001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Fields/fields001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Fields/fields001/TestDescription.java index 9cd039fba797d..a337e6b7fb5a6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Fields/fields001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Fields/fields001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Fields.fields001 - * nsk.jdwp.ReferenceType.Fields.fields001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Fields.fields001a + * @run main/othervm * nsk.jdwp.ReferenceType.Fields.fields001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/FieldsWithGeneric/fldwithgeneric001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/FieldsWithGeneric/fldwithgeneric001/TestDescription.java index 0fa13506be14d..c410dabad0893 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/FieldsWithGeneric/fldwithgeneric001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/FieldsWithGeneric/fldwithgeneric001/TestDescription.java @@ -44,9 +44,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.FieldsWithGeneric.fldwithgeneric001 - * nsk.jdwp.ReferenceType.FieldsWithGeneric.fldwithgeneric001t - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.FieldsWithGeneric.fldwithgeneric001t + * @run main/othervm * nsk.jdwp.ReferenceType.FieldsWithGeneric.fldwithgeneric001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/GetValues/getvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/GetValues/getvalues001/TestDescription.java index fb43f82cc1e49..6a0ceb754d8c6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/GetValues/getvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/GetValues/getvalues001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.GetValues.getvalues001 - * nsk.jdwp.ReferenceType.GetValues.getvalues001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.GetValues.getvalues001a + * @run main/othervm * nsk.jdwp.ReferenceType.GetValues.getvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances001/instances001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances001/instances001.java index e5bbfb0d99d22..2312f571822d4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances001/instances001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances001/instances001.java @@ -64,8 +64,7 @@ * @requires !vm.graal.enabled * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Instances.instances001.instances001 - * @run main/othervm/native PropertyResolvingWrapper + * @run main/othervm/native * nsk.jdwp.ReferenceType.Instances.instances001.instances001 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -77,21 +76,24 @@ package nsk.jdwp.ReferenceType.Instances.instances001; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; -import nsk.share.jpda.AbstractDebuggeeTest; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class instances001 extends TestDebuggerType1 { protected String getDebugeeClassName() { return nsk.jdwp.ReferenceType.Instances.instances001.instances001a.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new instances001().runIt(argv, out); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances002/instances002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances002/instances002.java index d88b61847bd98..cd90392f3d939 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances002/instances002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Instances/instances002/instances002.java @@ -57,8 +57,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Instances.instances002.instances002 - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.ReferenceType.Instances.instances002.instances002 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -70,20 +69,24 @@ package nsk.jdwp.ReferenceType.Instances.instances002; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class instances002 extends TestDebuggerType1 { protected String getDebugeeClassName() { return nsk.jdwp.ReferenceType.Instances.instances002.instances002a.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new instances002().runIt(argv, out); } @@ -118,7 +121,7 @@ private void testClass(String className, int maxInstances, int expectedInstances log.complain("Unexpected 'instances' value: " + instances + ", expected is " + expectedInstances); } - long expectedInstancesID[] = new long[expectedInstances]; + long[] expectedInstancesID = new long[expectedInstances]; // initialize expected IDs of instances for (int i = 0; i < expectedInstances; i++) { @@ -126,21 +129,21 @@ private void testClass(String className, int maxInstances, int expectedInstances JDWP.Tag.OBJECT); } - long receivedInstancesID[] = new long[instances]; + long[] receivedInstancesID = new long[instances]; for (int i = 0; i < instances; i++) { JDWP.Value value = reply.getValue(); log.display("tagged-ObjectID = " + value); - receivedInstancesID[i] = ((Long) value.getValue()).longValue(); + receivedInstancesID[i] = (Long) value.getValue(); } // check that correct IDs of instances was received for (int i = 0; i < instances; i++) { boolean isIDExpected = false; - for (int j = 0; j < expectedInstancesID.length; j++) { - if (receivedInstancesID[i] == expectedInstancesID[j]) { + for (long l : expectedInstancesID) { + if (receivedInstancesID[i] == l) { isIDExpected = true; break; } @@ -154,8 +157,9 @@ private void testClass(String className, int maxInstances, int expectedInstances if (!getSuccess()) { log.complain("Expected IDs:"); - for (int i = 0; i < expectedInstancesID.length; i++) - log.complain("" + expectedInstancesID[i]); + for (long l : expectedInstancesID) { + log.complain("" + l); + } } if (!reply.isParsed()) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Interfaces/interfaces001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Interfaces/interfaces001/TestDescription.java index ff0e5e8343685..b67ad06b1c333 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Interfaces/interfaces001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Interfaces/interfaces001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Interfaces.interfaces001 - * nsk.jdwp.ReferenceType.Interfaces.interfaces001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Interfaces.interfaces001a + * @run main/othervm * nsk.jdwp.ReferenceType.Interfaces.interfaces001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Methods/methods001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Methods/methods001/TestDescription.java index 1f5cc02379ebe..f24bcd39b8453 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Methods/methods001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Methods/methods001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Methods.methods001 - * nsk.jdwp.ReferenceType.Methods.methods001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Methods.methods001a + * @run main/othervm * nsk.jdwp.ReferenceType.Methods.methods001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/MethodsWithGeneric/methwithgeneric001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/MethodsWithGeneric/methwithgeneric001/TestDescription.java index b001697f77eb4..648349f887e56 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/MethodsWithGeneric/methwithgeneric001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/MethodsWithGeneric/methwithgeneric001/TestDescription.java @@ -44,9 +44,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.MethodsWithGeneric.methwithgeneric001 - * nsk.jdwp.ReferenceType.MethodsWithGeneric.methwithgeneric001t - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.MethodsWithGeneric.methwithgeneric001t + * @run main/othervm * nsk.jdwp.ReferenceType.MethodsWithGeneric.methwithgeneric001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Modifiers/modifiers001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Modifiers/modifiers001/TestDescription.java index 9df697eb28805..fa26934f1497a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Modifiers/modifiers001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Modifiers/modifiers001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Modifiers.modifiers001 - * nsk.jdwp.ReferenceType.Modifiers.modifiers001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Modifiers.modifiers001a + * @run main/othervm * nsk.jdwp.ReferenceType.Modifiers.modifiers001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/NestedTypes/nestedtypes001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/NestedTypes/nestedtypes001/TestDescription.java index bd6d6d1c6b1d5..4436bcccbb607 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/NestedTypes/nestedtypes001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/NestedTypes/nestedtypes001/TestDescription.java @@ -60,9 +60,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.NestedTypes.nestedtypes001 - * nsk.jdwp.ReferenceType.NestedTypes.nestedtypes001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.NestedTypes.nestedtypes001a + * @run main/othervm * nsk.jdwp.ReferenceType.NestedTypes.nestedtypes001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Signature/signature001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Signature/signature001/TestDescription.java index 50fb762d228fc..27628d13e610a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Signature/signature001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Signature/signature001/TestDescription.java @@ -51,9 +51,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Signature.signature001 - * nsk.jdwp.ReferenceType.Signature.signature001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Signature.signature001a + * @run main/othervm * nsk.jdwp.ReferenceType.Signature.signature001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SignatureWithGeneric/sigwithgeneric001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SignatureWithGeneric/sigwithgeneric001/TestDescription.java index 2f0c0de7fa30c..9dc7275de7d13 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SignatureWithGeneric/sigwithgeneric001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SignatureWithGeneric/sigwithgeneric001/TestDescription.java @@ -43,9 +43,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.SignatureWithGeneric.sigwithgeneric001 - * nsk.jdwp.ReferenceType.SignatureWithGeneric.sigwithgeneric001t - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.SignatureWithGeneric.sigwithgeneric001t + * @run main/othervm * nsk.jdwp.ReferenceType.SignatureWithGeneric.sigwithgeneric001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceDebugExtension/srcdebugext001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceDebugExtension/srcdebugext001/TestDescription.java index c32afe01d51e7..c614604e55d71 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceDebugExtension/srcdebugext001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceDebugExtension/srcdebugext001/TestDescription.java @@ -38,9 +38,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.SourceDebugExtension.srcdebugext001 - * nsk.jdwp.ReferenceType.SourceDebugExtension.srcdebugext001t - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.SourceDebugExtension.srcdebugext001t + * @run main/othervm * nsk.jdwp.ReferenceType.SourceDebugExtension.srcdebugext001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceFile/srcfile001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceFile/srcfile001/TestDescription.java index 56a9ea1083854..09608b3757d74 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceFile/srcfile001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/SourceFile/srcfile001/TestDescription.java @@ -51,9 +51,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.SourceFile.srcfile001 - * nsk.jdwp.ReferenceType.SourceFile.srcfile001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.SourceFile.srcfile001a + * @run main/othervm * nsk.jdwp.ReferenceType.SourceFile.srcfile001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Status/status001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Status/status001/TestDescription.java index 574882961f718..aefbb989bf98e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Status/status001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ReferenceType/Status/status001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ReferenceType.Status.status001 - * nsk.jdwp.ReferenceType.Status.status001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ReferenceType.Status.status001a + * @run main/othervm * nsk.jdwp.ReferenceType.Status.status001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001/TestDescription.java index ebdab4505d3e9..09ee0ba021a9b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001/TestDescription.java @@ -60,12 +60,11 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.StackFrame.GetValues.getvalues001 - * nsk.jdwp.StackFrame.GetValues.getvalues001a + * @build nsk.jdwp.StackFrame.GetValues.getvalues001a * @comment debuggee should be compiled w/ debug info * @clean nsk.jdwp.StackFrame.GetValues.getvalues001a * @compile -g:lines,source,vars ../getvalues001a.java - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.StackFrame.GetValues.getvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001/TestDescription.java index 4d4205c4ec9dd..2fd126b9fbb2a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/PopFrames/popframes001/TestDescription.java @@ -59,9 +59,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.StackFrame.PopFrames.popframes001 - * nsk.jdwp.StackFrame.PopFrames.popframes001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.StackFrame.PopFrames.popframes001a + * @run main/othervm * nsk.jdwp.StackFrame.PopFrames.popframes001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001/TestDescription.java index a8a08c25ac4ba..96302cd95925f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001/TestDescription.java @@ -71,12 +71,11 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.StackFrame.SetValues.setvalues001 - * nsk.jdwp.StackFrame.SetValues.setvalues001a + * @build nsk.jdwp.StackFrame.SetValues.setvalues001a * @comment debuggee should be compiled w/ debug info * @clean nsk.jdwp.StackFrame.SetValues.setvalues001a * @compile -g:lines,source,vars ../setvalues001a.java - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.StackFrame.SetValues.setvalues001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001/TestDescription.java index cd1642998ac88..9216e598b04c6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001/TestDescription.java @@ -58,9 +58,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.StackFrame.ThisObject.thisobject001 - * nsk.jdwp.StackFrame.ThisObject.thisobject001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.StackFrame.ThisObject.thisobject001a + * @run main/othervm * nsk.jdwp.StackFrame.ThisObject.thisobject001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001/TestDescription.java index 591d4e9a09afd..ff107802db07b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StringReference/Value/value001/TestDescription.java @@ -51,9 +51,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.StringReference.Value.value001 - * nsk.jdwp.StringReference.Value.value001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.StringReference.Value.value001a + * @run main/othervm * nsk.jdwp.StringReference.Value.value001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/TEST.properties b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/TEST.properties deleted file mode 100644 index a1e382092a6cb..0000000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/TEST.properties +++ /dev/null @@ -1,2 +0,0 @@ -# disabled till JDK-8252002 is fixed -allowSmartActionArgs=false diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001/TestDescription.java index 7fe75fec178ae..679af7f78c7a5 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Children/children001/TestDescription.java @@ -48,9 +48,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadGroupReference.Children.children001 - * nsk.jdwp.ThreadGroupReference.Children.children001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadGroupReference.Children.children001a + * @run main/othervm * nsk.jdwp.ThreadGroupReference.Children.children001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001/TestDescription.java index f5dda76b475c2..14218e86942b3 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Name/name001/TestDescription.java @@ -48,9 +48,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadGroupReference.Name.name001 - * nsk.jdwp.ThreadGroupReference.Name.name001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadGroupReference.Name.name001a + * @run main/othervm * nsk.jdwp.ThreadGroupReference.Name.name001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Parent/parent001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Parent/parent001/TestDescription.java index 41cd508af4f26..4a2ff8684acbf 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Parent/parent001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadGroupReference/Parent/parent001/TestDescription.java @@ -51,9 +51,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadGroupReference.Parent.parent001 - * nsk.jdwp.ThreadGroupReference.Parent.parent001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadGroupReference.Parent.parent001a + * @run main/othervm * nsk.jdwp.ThreadGroupReference.Parent.parent001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001/TestDescription.java index 3e57d64fc0fb5..c1310a9c3fbf8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/CurrentContendedMonitor/curcontmonitor001/TestDescription.java @@ -61,9 +61,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.CurrentContendedMonitor.curcontmonitor001 - * nsk.jdwp.ThreadReference.CurrentContendedMonitor.curcontmonitor001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.CurrentContendedMonitor.curcontmonitor001a + * @run main/othervm * nsk.jdwp.ThreadReference.CurrentContendedMonitor.curcontmonitor001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java index da1d8d117011e..8453e54e2c105 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn001/forceEarlyReturn001.java @@ -74,8 +74,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn001.forceEarlyReturn001 - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn001.forceEarlyReturn001 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -87,21 +86,21 @@ package nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn001; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; import nsk.share.jdwp.JDWP.Value; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; import nsk.share.jpda.ForceEarlyReturnTestThread; -public class forceEarlyReturn001 -extends TestDebuggerType1 -{ +import java.io.PrintStream; + +public class forceEarlyReturn001 extends TestDebuggerType1 { // data needed to create JDWP command, // also this class create breakpoint in method which should be forced to return - class TestData - { - public TestData(long classID, String methodName, int lineNumber, long threadID, Value value, Value invalidValue) - { + class TestData { + public TestData(long classID, String methodName, int lineNumber, long threadID, Value value, Value invalidValue) { breakpointID = debuggee.requestBreakpointEvent( JDWP.TypeTag.CLASS, classID, @@ -120,27 +119,22 @@ public TestData(long classID, String methodName, int lineNumber, long threadID, public long threadID; } - protected String getDebugeeClassName() - { + protected String getDebugeeClassName() { return "nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn001.forceEarlyReturn001a"; } - public static void main (String argv[]) - { - System.exit(run(argv,System.out) + Consts.JCK_STATUS_BASE); + public static void main(String[] argv) { + System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) - { + public static int run(String[] argv, PrintStream out) { return new forceEarlyReturn001().runIt(argv, out); } // send command and receive empty reply // all asserts should be done in debuggee - private void sendCommand(long threadID, Value value, boolean expectError, int errorCode) - { - try - { + private void sendCommand(long threadID, Value value, boolean expectError, int errorCode) { + try { int JDWP_COMMAND_ID = JDWP.Command.ThreadReference.ForceEarlyReturn; log.display("Create command: " + JDWP.commandNames.get(JDWP_COMMAND_ID)); @@ -159,19 +153,16 @@ private void sendCommand(long threadID, Value value, boolean expectError, int er reply = getReply(command, expectError, errorCode); - if(expectError) + if (expectError) return; log.display("Empty reply"); - if(!reply.isParsed()) - { + if (!reply.isParsed()) { setSuccess(false); log.complain("Extra trailing bytes found in reply packet at: " + reply.currentPosition()); } - } - catch(Exception e) - { + } catch (Exception e) { setSuccess(false); log.complain("Caught exception while testing JDWP command: " + e); e.printStackTrace(log.getOutStream()); @@ -182,24 +173,21 @@ private void sendCommand(long threadID, Value value, boolean expectError, int er // create Value objects which should be send in command packet and // initialize breapoints in tested methods - private void initTestData() - { + private void initTestData() { long classID = debuggee.getReferenceTypeID(createTypeSignature(ForceEarlyReturnTestThread.class.getName())); - Value testValues[] = new Value[ForceEarlyReturnTestThread.testedTypesNames.length + 1]; - Value testInvalidValues[] = new Value[ForceEarlyReturnTestThread.testedTypesNames.length + 1]; + Value[] testValues = new Value[ForceEarlyReturnTestThread.testedTypesNames.length + 1]; + Value[] testInvalidValues = new Value[ForceEarlyReturnTestThread.testedTypesNames.length + 1]; - testValues[0] = new JDWP.Value(JDWP.Tag.VOID, new Long(0)); + testValues[0] = new JDWP.Value(JDWP.Tag.VOID, 0L); - for(int i = 1; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) - { + for (int i = 1; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) { testValues[i] = debuggee.getStaticFieldValue( classID, debuggee.getClassFieldID(classID, "expected" + ForceEarlyReturnTestThread.testedTypesNames[i] + "Value", true)); } - for(int i = 0; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) - { + for (int i = 0; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) { testInvalidValues[i] = debuggee.getStaticFieldValue( classID, debuggee.getClassFieldID(classID, "invalid" + ForceEarlyReturnTestThread.testedTypesNames[i] + "Value", true)); @@ -209,8 +197,7 @@ private void initTestData() testData = new TestData[ForceEarlyReturnTestThread.testedTypesNames.length]; - for(int i = 0; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) - { + for (int i = 0; i < ForceEarlyReturnTestThread.testedTypesNames.length; i++) { testData[i] = new TestData(classID, ForceEarlyReturnTestThread.testedTypesNames[i] + "Method", ForceEarlyReturnTestThread.breakpointLines[i], @@ -220,27 +207,25 @@ private void initTestData() } } - public void doTest() - { + public void doTest() { initTestData(); pipe.println(forceEarlyReturn001a.COMMAND_START_EXECUTION); - if(!isDebuggeeReady()) + if (!isDebuggeeReady()) return; - for(int i = 0; i < testData.length; i++) - { + for (TestData testDatum : testData) { // wait when tested thread call method with breapoint - debuggee.waitForBreakpointEvent(testData[i].breakpointID); + debuggee.waitForBreakpointEvent(testDatum.breakpointID); - log.display("Send invalid command: valid value: " + testData[i].value + " invalid value: " + testData[i].invalidValue); + log.display("Send invalid command: valid value: " + testDatum.value + " invalid value: " + testDatum.invalidValue); // send ForceEarlyReturn command with invalid value - sendCommand(testData[i].threadID, testData[i].invalidValue, true, JDWP.Error.TYPE_MISMATCH); + sendCommand(testDatum.threadID, testDatum.invalidValue, true, JDWP.Error.TYPE_MISMATCH); - log.display("Send valid command: valid value: " + testData[i].value); + log.display("Send valid command: valid value: " + testDatum.value); // send ForceEarlyReturn command - sendCommand(testData[i].threadID, testData[i].value, false, 0); + sendCommand(testDatum.threadID, testDatum.value, false, 0); // resume debuggee debuggee.resume(); @@ -248,7 +233,7 @@ public void doTest() pipe.println(forceEarlyReturn001a.COMMAND_END_EXECUTION); - if(!isDebuggeeReady()) + if (!isDebuggeeReady()) return; } } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java index 329b6bf22eb45..420dd0650536d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ForceEarlyReturn/forceEarlyReturn002/forceEarlyReturn002.java @@ -66,8 +66,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn002.forceEarlyReturn002 - * @run main/othervm/native PropertyResolvingWrapper + * @run main/othervm/native * nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn002.forceEarlyReturn002 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -79,24 +78,28 @@ package nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn002; -import java.io.*; - import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.EventPacket; +import nsk.share.jdwp.JDWP; import nsk.share.jdwp.JDWP.Value; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; import nsk.share.jpda.AbstractDebuggeeTest; import nsk.share.jpda.StateTestThread; +import java.io.PrintStream; + public class forceEarlyReturn002 extends TestDebuggerType1 { protected String getDebugeeClassName() { return "nsk.jdwp.ThreadReference.ForceEarlyReturn.forceEarlyReturn002.forceEarlyReturn002a"; } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new forceEarlyReturn002().runIt(argv, out); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001/TestDescription.java index 9f791d4e9581e..16adec92f82e4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001/TestDescription.java @@ -56,9 +56,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.FrameCount.framecnt001 - * nsk.jdwp.ThreadReference.FrameCount.framecnt001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.FrameCount.framecnt001a + * @run main/othervm * nsk.jdwp.ThreadReference.FrameCount.framecnt001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001/TestDescription.java index 2ce91d8ff5cfb..d742fb39d0ebb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001/TestDescription.java @@ -61,9 +61,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Frames.frames001 - * nsk.jdwp.ThreadReference.Frames.frames001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Frames.frames001a + * @run main/othervm * nsk.jdwp.ThreadReference.Frames.frames001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001/TestDescription.java index 962fa6ca2d99b..236ff3140d583 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Interrupt/interrupt001/TestDescription.java @@ -65,9 +65,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Interrupt.interrupt001 - * nsk.jdwp.ThreadReference.Interrupt.interrupt001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Interrupt.interrupt001a + * @run main/othervm * nsk.jdwp.ThreadReference.Interrupt.interrupt001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Name/name001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Name/name001/TestDescription.java index a057e723b3341..afc50298c1c8d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Name/name001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Name/name001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Name.name001 - * nsk.jdwp.ThreadReference.Name.name001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Name.name001a + * @run main/othervm * nsk.jdwp.ThreadReference.Name.name001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitors/ownmonitors001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitors/ownmonitors001/TestDescription.java index 02abb6e945db5..84c7f627e6d9f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitors/ownmonitors001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitors/ownmonitors001/TestDescription.java @@ -61,9 +61,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.OwnedMonitors.ownmonitors001 - * nsk.jdwp.ThreadReference.OwnedMonitors.ownmonitors001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.OwnedMonitors.ownmonitors001a + * @run main/othervm * nsk.jdwp.ThreadReference.OwnedMonitors.ownmonitors001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo001/ownedMonitorsStackDepthInfo001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo001/ownedMonitorsStackDepthInfo001.java index b489d21e501b4..f178c88ae1474 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo001/ownedMonitorsStackDepthInfo001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo001/ownedMonitorsStackDepthInfo001.java @@ -62,8 +62,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo001.ownedMonitorsStackDepthInfo001 - * @run main/othervm/native/timeout=420 PropertyResolvingWrapper + * @run main/othervm/native/timeout=420 * nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo001.ownedMonitorsStackDepthInfo001 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -75,20 +74,24 @@ package nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo001; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class ownedMonitorsStackDepthInfo001 extends TestDebuggerType1 { protected String getDebugeeClassName() { return nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo001.ownedMonitorsStackDepthInfo001a.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new ownedMonitorsStackDepthInfo001().runIt(argv, out); } @@ -126,14 +129,14 @@ private void testCommand() { reply = getReply(command); - MonitorInfo expectedMonitors[] = new MonitorInfo[ownedMonitorsStackDepthInfo001a.expectedMonitorCounts]; + MonitorInfo[] expectedMonitors = new MonitorInfo[ownedMonitorsStackDepthInfo001a.expectedMonitorCounts]; long classID = debuggee.getReferenceTypeID(createTypeSignature(getDebugeeClassName())); // obtain information about aquired monitors for (int i = 0; i < ownedMonitorsStackDepthInfo001a.expectedMonitorCounts; i++) { long monitorID = queryObjectID(classID, "monitor" + (i + 1)); - int depth = ((Integer) debuggee.getStaticFieldValue(classID, "depth" + (i + 1), JDWP.Tag.INT).getValue()).intValue(); + int depth = (Integer) debuggee.getStaticFieldValue(classID, "depth" + (i + 1), JDWP.Tag.INT).getValue(); expectedMonitors[i] = new MonitorInfo(monitorID, depth); } @@ -148,7 +151,7 @@ private void testCommand() { log.complain("Unexpected value of 'owned': " + owned + ", expected value is " + expectedMonitors.length); } - MonitorInfo receivedMonitors[] = new MonitorInfo[owned]; + MonitorInfo[] receivedMonitors = new MonitorInfo[owned]; for (int i = 0; i < owned; i++) { JDWP.Value value = reply.getValue(); @@ -157,21 +160,21 @@ private void testCommand() { int stack_depth = reply.getInt(); log.display("stack_depth = " + stack_depth); - receivedMonitors[i] = new MonitorInfo(((Long) value.getValue()).longValue(), stack_depth); + receivedMonitors[i] = new MonitorInfo((Long) value.getValue(), stack_depth); } // check that correct information about acquired monitors was received for (int i = 0; i < owned; i++) { boolean monitorFound = false; - for (int j = 0; j < expectedMonitors.length; j++) { - if (receivedMonitors[i].monitorObjectID == expectedMonitors[j].monitorObjectID) { + for (MonitorInfo expectedMonitor : expectedMonitors) { + if (receivedMonitors[i].monitorObjectID == expectedMonitor.monitorObjectID) { monitorFound = true; - if (receivedMonitors[i].depth != expectedMonitors[j].depth) { + if (receivedMonitors[i].depth != expectedMonitor.depth) { setSuccess(false); log.complain("Unexpected monitor depth for monitor " + receivedMonitors[i].monitorObjectID + ": " - + receivedMonitors[i].depth + ", expected value is " + expectedMonitors[j].depth); + + receivedMonitors[i].depth + ", expected value is " + expectedMonitor.depth); } break; @@ -186,8 +189,8 @@ private void testCommand() { if (!getSuccess()) { log.complain("Expected monitors: "); - for (int i = 0; i < expectedMonitors.length; i++) { - log.complain("monitor: " + expectedMonitors[i].monitorObjectID + " " + expectedMonitors[i].depth); + for (MonitorInfo expectedMonitor : expectedMonitors) { + log.complain("monitor: " + expectedMonitor.monitorObjectID + " " + expectedMonitor.depth); } } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo002/ownedMonitorsStackDepthInfo002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo002/ownedMonitorsStackDepthInfo002.java index 47646f744c288..cbc5fb63a235b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo002/ownedMonitorsStackDepthInfo002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/OwnedMonitorsStackDepthInfo/ownedMonitorsStackDepthInfo002/ownedMonitorsStackDepthInfo002.java @@ -50,8 +50,7 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo002.ownedMonitorsStackDepthInfo002 - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo002.ownedMonitorsStackDepthInfo002 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -63,22 +62,26 @@ package nsk.jdwp.ThreadReference.OwnedMonitorsStackDepthInfo.ownedMonitorsStackDepthInfo002; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; +import nsk.share.jdwp.AbstractJDWPDebuggee; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.TestDebuggerType1; import nsk.share.jpda.AbstractDebuggeeTest; import nsk.share.jpda.StateTestThread; +import java.io.PrintStream; + public class ownedMonitorsStackDepthInfo002 extends TestDebuggerType1 { protected String getDebugeeClassName() { return AbstractJDWPDebuggee.class.getName(); } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new ownedMonitorsStackDepthInfo002().runIt(argv, out); } @@ -102,8 +105,6 @@ private void sendCommand(long threadID, boolean trySuspend, int errorCode) { // in this test always expect reply with error getReply(command, true, errorCode); - - return; } catch (Exception e) { setSuccess(false); log.complain("Caught exception while testing JDWP command: " + e); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001/TestDescription.java index 5b8df96da9bad..e5eb1c510f1a1 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Resume/resume001/TestDescription.java @@ -58,9 +58,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Resume.resume001 - * nsk.jdwp.ThreadReference.Resume.resume001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Resume.resume001a + * @run main/othervm * nsk.jdwp.ThreadReference.Resume.resume001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Status/status001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Status/status001/TestDescription.java index ff56db49b5d3a..14ff024714377 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Status/status001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Status/status001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Status.status001 - * nsk.jdwp.ThreadReference.Status.status001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Status.status001a + * @run main/othervm * nsk.jdwp.ThreadReference.Status.status001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001/TestDescription.java index a483fb95dc2a6..9229392142b77 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Stop/stop001/TestDescription.java @@ -58,9 +58,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Stop.stop001 - * nsk.jdwp.ThreadReference.Stop.stop001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Stop.stop001a + * @run main/othervm * nsk.jdwp.ThreadReference.Stop.stop001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Suspend/suspend001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Suspend/suspend001/TestDescription.java index bfc6f96368fb3..d1477e4774933 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Suspend/suspend001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Suspend/suspend001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.Suspend.suspend001 - * nsk.jdwp.ThreadReference.Suspend.suspend001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.Suspend.suspend001a + * @run main/othervm * nsk.jdwp.ThreadReference.Suspend.suspend001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001/TestDescription.java index f6c9789305294..39e5469173a30 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/SuspendCount/suspendcnt001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.SuspendCount.suspendcnt001 - * nsk.jdwp.ThreadReference.SuspendCount.suspendcnt001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.SuspendCount.suspendcnt001a + * @run main/othervm * nsk.jdwp.ThreadReference.SuspendCount.suspendcnt001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001/TestDescription.java index 6cb00c44a8d8a..f9b503a82fe1d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/ThreadGroup/threadgroup001/TestDescription.java @@ -57,9 +57,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.ThreadReference.ThreadGroup.threadgroup001 - * nsk.jdwp.ThreadReference.ThreadGroup.threadgroup001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.ThreadReference.ThreadGroup.threadgroup001a + * @run main/othervm * nsk.jdwp.ThreadReference.ThreadGroup.threadgroup001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClasses/allclasses001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClasses/allclasses001/TestDescription.java index cc7ed9702c7ac..4f11e1d91bde0 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClasses/allclasses001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClasses/allclasses001/TestDescription.java @@ -48,9 +48,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.AllClasses.allclasses001 - * nsk.jdwp.VirtualMachine.AllClasses.allclasses001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.AllClasses.allclasses001a + * @run main/othervm * nsk.jdwp.VirtualMachine.AllClasses.allclasses001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001/TestDescription.java index 960bdd3b212ee..980bdb98c8939 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001/TestDescription.java @@ -44,9 +44,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001 - * nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001t - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001t + * @run main/othervm * nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001/TestDescription.java index 950f0432f1448..782045881ac51 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllThreads/allthreads001/TestDescription.java @@ -46,9 +46,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.AllThreads.allthreads001 - * nsk.jdwp.VirtualMachine.AllThreads.allthreads001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.AllThreads.allthreads001a + * @run main/othervm * nsk.jdwp.VirtualMachine.AllThreads.allthreads001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Capabilities/capabilities001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Capabilities/capabilities001/TestDescription.java index c39197f2f6696..bba5b1c30153e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Capabilities/capabilities001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Capabilities/capabilities001/TestDescription.java @@ -46,9 +46,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Capabilities.capabilities001 - * nsk.jdwp.VirtualMachine.Capabilities.capabilities001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Capabilities.capabilities001a + * @run main/othervm * nsk.jdwp.VirtualMachine.Capabilities.capabilities001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001/TestDescription.java index d9ced694de717..4d4c69cde636d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CapabilitiesNew/capabilitiesnew001/TestDescription.java @@ -48,9 +48,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.CapabilitiesNew.capabilitiesnew001 - * nsk.jdwp.VirtualMachine.CapabilitiesNew.capabilitiesnew001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.CapabilitiesNew.capabilitiesnew001a + * @run main/othervm * nsk.jdwp.VirtualMachine.CapabilitiesNew.capabilitiesnew001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001/TestDescription.java index f723219ab5dab..4f7d685117c9d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassPaths/classpaths001/TestDescription.java @@ -39,9 +39,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.ClassPaths.classpaths001 - * nsk.jdwp.VirtualMachine.ClassPaths.classpaths001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.ClassPaths.classpaths001a + * @run main/othervm * nsk.jdwp.VirtualMachine.ClassPaths.classpaths001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001/TestDescription.java index 4c749eeb473f9..14f40d16e78f8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ClassesBySignature/classbysig001/TestDescription.java @@ -46,9 +46,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.ClassesBySignature.classbysig001 - * nsk.jdwp.VirtualMachine.ClassesBySignature.classbysig001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.ClassesBySignature.classbysig001a + * @run main/othervm * nsk.jdwp.VirtualMachine.ClassesBySignature.classbysig001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001/TestDescription.java index ad73870f3bdbe..54789071b5132 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/CreateString/createstr001/TestDescription.java @@ -42,9 +42,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.CreateString.createstr001 - * nsk.jdwp.VirtualMachine.CreateString.createstr001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.CreateString.createstr001a + * @run main/othervm * nsk.jdwp.VirtualMachine.CreateString.createstr001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001/TestDescription.java index 2f003e1e10221..44b64f614f31e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Dispose/dispose001/TestDescription.java @@ -50,9 +50,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Dispose.dispose001 - * nsk.jdwp.VirtualMachine.Dispose.dispose001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Dispose.dispose001a + * @run main/othervm * nsk.jdwp.VirtualMachine.Dispose.dispose001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001/TestDescription.java index 7c0b5ce187f7d..3782fc59b3fbd 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/DisposeObjects/disposeobj001/TestDescription.java @@ -54,9 +54,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.DisposeObjects.disposeobj001 - * nsk.jdwp.VirtualMachine.DisposeObjects.disposeobj001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.DisposeObjects.disposeobj001a + * @run main/othervm * nsk.jdwp.VirtualMachine.DisposeObjects.disposeobj001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001/TestDescription.java index ae86ef4fc7c4a..c1fb69e22281a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Exit/exit001/TestDescription.java @@ -52,9 +52,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Exit.exit001 - * nsk.jdwp.VirtualMachine.Exit.exit001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Exit.exit001a + * @run main/othervm * nsk.jdwp.VirtualMachine.Exit.exit001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001/TestDescription.java index e1a95c9eaa9a8..c562dc2e2a66b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents001/TestDescription.java @@ -51,9 +51,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.HoldEvents.holdevents001 - * nsk.jdwp.VirtualMachine.HoldEvents.holdevents001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.HoldEvents.holdevents001a + * @run main/othervm * nsk.jdwp.VirtualMachine.HoldEvents.holdevents001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents002/TestDescription.java index 52babe215a220..e41efd46bb4ed 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/HoldEvents/holdevents002/TestDescription.java @@ -52,9 +52,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.HoldEvents.holdevents002 - * nsk.jdwp.VirtualMachine.HoldEvents.holdevents002a - * @run main/othervm/timeout=420 PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.HoldEvents.holdevents002a + * @run main/othervm/timeout=420 * nsk.jdwp.VirtualMachine.HoldEvents.holdevents002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/IDSizes/idsizes001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/IDSizes/idsizes001/TestDescription.java index b34414f5a1a4a..0dcb07c803b40 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/IDSizes/idsizes001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/IDSizes/idsizes001/TestDescription.java @@ -39,9 +39,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.IDSizes.idsizes001 - * nsk.jdwp.VirtualMachine.IDSizes.idsizes001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.IDSizes.idsizes001a + * @run main/othervm * nsk.jdwp.VirtualMachine.IDSizes.idsizes001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/InstanceCounts/instanceCounts001/instanceCounts001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/InstanceCounts/instanceCounts001/instanceCounts001.java index c903f61209813..e25d2cc3189f8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/InstanceCounts/instanceCounts001/instanceCounts001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/InstanceCounts/instanceCounts001/instanceCounts001.java @@ -65,9 +65,8 @@ * @requires !vm.graal.enabled * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001.instanceCounts001 - * nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001.instanceCounts001a - * @run main/othervm/native PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001.instanceCounts001a + * @run main/othervm/native * nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001.instanceCounts001 * -arch=${os.family}-${os.simpleArch} * -verbose @@ -79,25 +78,28 @@ package nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001; -import java.io.*; import nsk.share.Consts; -import nsk.share.jdwp.*; -import nsk.share.jpda.AbstractDebuggeeTest; +import nsk.share.jdwp.CommandPacket; +import nsk.share.jdwp.JDWP; +import nsk.share.jdwp.ReplyPacket; +import nsk.share.jdwp.TestDebuggerType1; + +import java.io.PrintStream; public class instanceCounts001 extends TestDebuggerType1 { protected String getDebugeeClassName() { return "nsk.jdwp.VirtualMachine.InstanceCounts.instanceCounts001.instanceCounts001a"; } - public static void main(String argv[]) { + public static void main(String[] argv) { System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE); } - public static int run(String argv[], PrintStream out) { + public static int run(String[] argv, PrintStream out) { return new instanceCounts001().runIt(argv, out); } - private void testCommand(long typeIDs[], int refTypesCount, int[] expectedInstanceCounts, boolean expectError, int errorCode) { + private void testCommand(long[] typeIDs, int refTypesCount, int[] expectedInstanceCounts, boolean expectError, int errorCode) { try { int JDWP_COMMAND_ID = JDWP.Command.VirtualMachine.InstanceCounts; @@ -109,8 +111,9 @@ private void testCommand(long typeIDs[], int refTypesCount, int[] expectedInstan CommandPacket command = new CommandPacket(JDWP_COMMAND_ID); command.addInt(refTypesCount); - for (int i = 0; i < refTypesCount; i++) + for (int i = 0; i < refTypesCount; i++) { command.addReferenceTypeID(typeIDs[i]); + } command.setLength(); @@ -172,11 +175,11 @@ public void doTest() { int expectedCount = instanceCounts001a.expectedCount; - String classNames[]; + String[] classNames; - classNames = new String[] { createTypeSignature(testClass1) }; + classNames = new String[]{createTypeSignature(testClass1)}; - long typeIDs[]; + long[] typeIDs; typeIDs = new long[classNames.length]; @@ -184,9 +187,9 @@ public void doTest() { for (int i = 0; i < classNames.length; i++) typeIDs[i] = debuggee.getReferenceTypeID(classNames[i]); - testCommand(typeIDs, typeIDs.length, new int[] { expectedCount }, false, 0); + testCommand(typeIDs, typeIDs.length, new int[]{expectedCount}, false, 0); - classNames = new String[] { createTypeSignature(testClass1), createTypeSignature(testClass2) }; + classNames = new String[]{createTypeSignature(testClass1), createTypeSignature(testClass2)}; typeIDs = new long[classNames.length]; @@ -194,10 +197,10 @@ public void doTest() { for (int i = 0; i < classNames.length; i++) typeIDs[i] = debuggee.getReferenceTypeID(classNames[i]); - testCommand(typeIDs, typeIDs.length, new int[] { expectedCount, expectedCount }, false, 0); + testCommand(typeIDs, typeIDs.length, new int[]{expectedCount, expectedCount}, false, 0); // create command with refTypesCount < 0, expect ILLEGAL_ARGUMENT error - testCommand(typeIDs, -1, new int[] { expectedCount }, true, JDWP.Error.ILLEGAL_ARGUMENT); + testCommand(typeIDs, -1, new int[]{expectedCount}, true, JDWP.Error.ILLEGAL_ARGUMENT); resetStatusIfGC(); } } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001/TestDescription.java index 8070578231f54..5ea557b5164f5 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/RedefineClasses/redefinecls001/TestDescription.java @@ -70,12 +70,11 @@ * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib * @build ExecDriver - * @build nsk.jdwp.VirtualMachine.RedefineClasses.redefinecls001 - * nsk.jdwp.VirtualMachine.RedefineClasses.redefinecls001a + * @build nsk.jdwp.VirtualMachine.RedefineClasses.redefinecls001a * nsk.jdwp.VirtualMachine.RedefineClasses.redefinecls001b * @run driver nsk.share.ExtraClassesBuilder * newclass - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdwp.VirtualMachine.RedefineClasses.redefinecls001 * . * -arch=${os.family}-${os.simpleArch} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001/TestDescription.java index cc75bb61fa0d8..589d061373d49 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents001/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents001 - * nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents001a + * @run main/othervm * nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002/TestDescription.java index 8d1ec4a40ff13..cb6760f97876b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/ReleaseEvents/releaseevents002/TestDescription.java @@ -55,9 +55,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents002 - * nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents002a + * @run main/othervm * nsk.jdwp.VirtualMachine.ReleaseEvents.releaseevents002 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001/TestDescription.java index dee7545489add..14fcd815f2897 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Resume/resume001/TestDescription.java @@ -50,9 +50,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Resume.resume001 - * nsk.jdwp.VirtualMachine.Resume.resume001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Resume.resume001a + * @run main/othervm * nsk.jdwp.VirtualMachine.Resume.resume001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001/TestDescription.java index 38230b43bdd93..94828c43d800b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/SetDefaultStratum/setdefstrat001/TestDescription.java @@ -53,9 +53,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.SetDefaultStratum.setdefstrat001 - * nsk.jdwp.VirtualMachine.SetDefaultStratum.setdefstrat001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.SetDefaultStratum.setdefstrat001a + * @run main/othervm * nsk.jdwp.VirtualMachine.SetDefaultStratum.setdefstrat001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001/TestDescription.java index ddaf4f02f94d6..ecd37d43e848f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/TopLevelThreadGroups/threadgroups001/TestDescription.java @@ -39,9 +39,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.TopLevelThreadGroups.threadgroups001 - * nsk.jdwp.VirtualMachine.TopLevelThreadGroups.threadgroups001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.TopLevelThreadGroups.threadgroups001a + * @run main/othervm * nsk.jdwp.VirtualMachine.TopLevelThreadGroups.threadgroups001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version001/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version001/TestDescription.java index 02028908fe57d..c26171f0dec23 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version001/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version001/TestDescription.java @@ -38,9 +38,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Version.version001 - * nsk.jdwp.VirtualMachine.Version.version001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Version.version001a + * @run main/othervm * nsk.jdwp.VirtualMachine.Version.version001 * -arch=${os.family}-${os.simpleArch} * -verbose diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002/TestDescription.java b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002/TestDescription.java index 4d68fa8c894f0..cfc6ed266c173 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/Version/version002/TestDescription.java @@ -39,9 +39,8 @@ * * @library /vmTestbase /test/hotspot/jtreg/vmTestbase * /test/lib - * @build nsk.jdwp.VirtualMachine.Version.version002 - * nsk.jdwp.VirtualMachine.Version.version002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdwp.VirtualMachine.Version.version002a + * @run main/othervm * nsk.jdwp.VirtualMachine.Version.version002 * -arch=${os.family}-${os.simpleArch} * -verbose From 1eca634736f1414f4dd799927189ed1f3bd5e450 Mon Sep 17 00:00:00 2001 From: Igor Ignatyev Date: Wed, 30 Sep 2020 03:03:53 +0000 Subject: [PATCH 70/79] 8252000: remove usage of PropertyResolvingWrapper in vmTestbase/nsk/jdb Reviewed-by: shade, cjplummer, sspitsyn --- test/hotspot/jtreg/vmTestbase/nsk/jdb/TEST.properties | 2 -- .../caught_exception002/caught_exception002.java | 5 ++--- .../nsk/jdb/classes/classes001/classes001.java | 6 +++--- .../nsk/jdb/classpath/classpath001/classpath001.java | 6 +++--- .../vmTestbase/nsk/jdb/clear/clear002/clear002.java | 6 +++--- .../vmTestbase/nsk/jdb/clear/clear003/clear003.java | 6 +++--- .../vmTestbase/nsk/jdb/clear/clear004/clear004.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/down/down002/down002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/dump/dump002/dump002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java | 3 ++- .../nsk/jdb/exclude/exclude001/exclude001.java | 6 +++--- .../vmTestbase/nsk/jdb/fields/fields001/fields001.java | 6 +++--- .../vmTestbase/nsk/jdb/hidden_class/hc001/hc001.java | 6 +++--- .../vmTestbase/nsk/jdb/ignore/ignore001/ignore001.java | 6 +++--- .../nsk/jdb/interrupt/interrupt001/interrupt001.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.java | 6 +++--- .../vmTestbase/nsk/jdb/klass/class001/class001.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/list/list002/list002.java | 10 +++++----- .../vmTestbase/nsk/jdb/locals/locals002/locals002.java | 3 ++- .../nsk/jdb/methods/methods002/methods002.java | 6 +++--- .../nsk/jdb/monitor/monitor001/monitor001.java | 6 +++--- .../nsk/jdb/monitor/monitor002/monitor002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/next/next001/next001.java | 6 +++--- .../nsk/jdb/options/connect/connect001/connect001.java | 6 +++--- .../nsk/jdb/options/connect/connect002/connect002.java | 6 +++--- .../nsk/jdb/options/connect/connect003/connect003.java | 6 +++--- .../nsk/jdb/options/connect/connect004/connect004.java | 6 +++--- .../nsk/jdb/options/connect/connect005/connect005.java | 6 +++--- .../listconnectors001/listconnectors001.java | 3 +-- .../jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.java | 6 +++--- .../pop_exception001/pop_exception001.java | 5 ++--- .../vmTestbase/nsk/jdb/print/print002/print002.java | 3 ++- .../jtreg/vmTestbase/nsk/jdb/read/read001/read001.java | 3 ++- .../nsk/jdb/redefine/redefine001/redefine001.java | 10 +++++----- .../nsk/jdb/reenter/reenter001/reenter001.java | 6 +++--- .../nsk/jdb/regression/b4689395/b4689395.java | 7 ++++--- .../vmTestbase/nsk/jdb/resume/resume002/resume002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/run/run002/run002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/set/set001/set001.java | 3 ++- .../jtreg/vmTestbase/nsk/jdb/set/set002/set002.java | 3 ++- .../jtreg/vmTestbase/nsk/jdb/step/step002/step002.java | 3 ++- .../nsk/jdb/step_up/step_up001/step_up001.java | 6 +++--- .../nsk/jdb/stop_at/stop_at002/stop_at002.java | 6 +++--- .../nsk/jdb/stop_at/stop_at003/stop_at003.java | 6 +++--- .../nsk/jdb/stop_in/stop_in002/stop_in002.java | 6 +++--- .../nsk/jdb/suspend/suspend001/suspend001.java | 6 +++--- .../vmTestbase/nsk/jdb/thread/thread002/thread002.java | 6 +++--- .../jdb/threadgroup/threadgroup002/threadgroup002.java | 6 +++--- .../threadgroups/threadgroups002/threadgroups002.java | 6 +++--- .../nsk/jdb/threads/threads002/threads002.java | 6 +++--- .../vmTestbase/nsk/jdb/trace/trace001/trace001.java | 6 +++--- .../uncaught_exception002/uncaught_exception002.java | 2 +- .../nsk/jdb/unmonitor/unmonitor001/unmonitor001.java | 3 ++- .../nsk/jdb/untrace/untrace001/untrace001.java | 6 +++--- .../nsk/jdb/unwatch/unwatch001/unwatch001.java | 6 +++--- .../nsk/jdb/unwatch/unwatch002/unwatch002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/up/up002/up002.java | 6 +++--- .../jtreg/vmTestbase/nsk/jdb/use/use001/use001.java | 6 +++--- .../vmTestbase/nsk/jdb/watch/watch001/watch001.java | 6 +++--- .../vmTestbase/nsk/jdb/watch/watch002/watch002.java | 6 +++--- .../vmTestbase/nsk/jdb/where/where004/where004.java | 6 +++--- .../vmTestbase/nsk/jdb/where/where005/where005.java | 6 +++--- .../vmTestbase/nsk/jdb/where/where006/where006.java | 6 +++--- .../vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java | 6 +++--- .../vmTestbase/nsk/share/jdb/JdbArgumentHandler.java | 8 ++++++-- 66 files changed, 189 insertions(+), 181 deletions(-) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/jdb/TEST.properties diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/TEST.properties b/test/hotspot/jtreg/vmTestbase/nsk/jdb/TEST.properties deleted file mode 100644 index 1f4ad32288e08..0000000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/TEST.properties +++ /dev/null @@ -1,2 +0,0 @@ -# disabled till JDK-8252000 is fixed -allowSmartActionArgs=false diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/caught_exception/caught_exception002/caught_exception002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/caught_exception/caught_exception002/caught_exception002.java index 7ab8ef9ad8c64..4eef7900d4231 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/caught_exception/caught_exception002/caught_exception002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/caught_exception/caught_exception002/caught_exception002.java @@ -45,9 +45,8 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.caught_exception.caught_exception002.caught_exception002 - * nsk.jdb.caught_exception.caught_exception002.caught_exception002a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdb.caught_exception.caught_exception002.caught_exception002a + * @run main/othervm * nsk.jdb.caught_exception.caught_exception002.caught_exception002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/classes/classes001/classes001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/classes/classes001/classes001.java index 2e2f4e266da6c..40a5ebaa9393c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/classes/classes001/classes001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/classes/classes001/classes001.java @@ -36,9 +36,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.classes.classes001.classes001 - * nsk.jdb.classes.classes001.classes001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.classes.classes001.classes001 + * @build nsk.jdb.classes.classes001.classes001a + * @run main/othervm + * nsk.jdb.classes.classes001.classes001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/classpath/classpath001/classpath001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/classpath/classpath001/classpath001.java index af77f08807a32..0eea9a92ab26f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/classpath/classpath001/classpath001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/classpath/classpath001/classpath001.java @@ -35,9 +35,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.classpath.classpath001.classpath001 - * nsk.jdb.classpath.classpath001.classpath001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.classpath.classpath001.classpath001 + * @build nsk.jdb.classpath.classpath001.classpath001a + * @run main/othervm + * nsk.jdb.classpath.classpath001.classpath001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear002/clear002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear002/clear002.java index 5590c771115f7..7869a1340a7cd 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear002/clear002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear002/clear002.java @@ -37,9 +37,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.clear.clear002.clear002 - * nsk.jdb.clear.clear002.clear002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.clear.clear002.clear002 + * @build nsk.jdb.clear.clear002.clear002a + * @run main/othervm + * nsk.jdb.clear.clear002.clear002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear003/clear003.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear003/clear003.java index b7f0830b76666..cbbc851f29a6f 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear003/clear003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear003/clear003.java @@ -38,9 +38,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.clear.clear003.clear003 - * nsk.jdb.clear.clear003.clear003a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.clear.clear003.clear003 + * @build nsk.jdb.clear.clear003.clear003a + * @run main/othervm + * nsk.jdb.clear.clear003.clear003 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear004/clear004.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear004/clear004.java index 696139c514b6c..c0ec8d2037095 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear004/clear004.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/clear/clear004/clear004.java @@ -39,9 +39,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.clear.clear004.clear004 - * nsk.jdb.clear.clear004.clear004a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.clear.clear004.clear004 + * @build nsk.jdb.clear.clear004.clear004a + * @run main/othervm + * nsk.jdb.clear.clear004.clear004 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/down/down002/down002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/down/down002/down002.java index 1372b2d2eed9d..29a40d9471d67 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/down/down002/down002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/down/down002/down002.java @@ -42,9 +42,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.down.down002.down002 - * nsk.jdb.down.down002.down002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.down.down002.down002 + * @build nsk.jdb.down.down002.down002a + * @run main/othervm + * nsk.jdb.down.down002.down002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/dump/dump002/dump002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/dump/dump002/dump002.java index b7e62ed032130..3e3b5b9b85872 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/dump/dump002/dump002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/dump/dump002/dump002.java @@ -46,9 +46,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.dump.dump002.dump002 - * nsk.jdb.dump.dump002.dump002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.dump.dump002.dump002 + * @build nsk.jdb.dump.dump002.dump002a + * @run main/othervm + * nsk.jdb.dump.dump002.dump002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java index df0fb5c40e892..98848ced90bc7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/eval/eval001/eval001.java @@ -52,7 +52,8 @@ * @clean nsk.jdb.eval.eval001.eval001a * @compile -g:lines,source,vars eval001a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.eval.eval001.eval001 + * @run main/othervm + * nsk.jdb.eval.eval001.eval001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java index 2f59ea05ccf7d..cee8ca44d585b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/exclude/exclude001/exclude001.java @@ -58,9 +58,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.exclude.exclude001.exclude001 - * nsk.jdb.exclude.exclude001.exclude001a - * @run main/othervm/timeout=600 PropertyResolvingWrapper nsk.jdb.exclude.exclude001.exclude001 + * @build nsk.jdb.exclude.exclude001.exclude001a + * @run main/othervm/timeout=600 + * nsk.jdb.exclude.exclude001.exclude001 * -arch=${os.family}-${os.simpleArch} * -waittime=10 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/fields/fields001/fields001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/fields/fields001/fields001.java index fdbf97e06125b..b5e2ccb58e566 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/fields/fields001/fields001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/fields/fields001/fields001.java @@ -40,9 +40,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.fields.fields001.fields001 - * nsk.jdb.fields.fields001.fields001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.fields.fields001.fields001 + * @build nsk.jdb.fields.fields001.fields001a + * @run main/othervm + * nsk.jdb.fields.fields001.fields001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/hidden_class/hc001/hc001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/hidden_class/hc001/hc001.java index d2544a80c38ec..5040eef9cefb2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/hidden_class/hc001/hc001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/hidden_class/hc001/hc001.java @@ -29,10 +29,10 @@ * /test/lib * @modules jdk.jdi * jdk.jdwp.agent - * @build nsk.jdb.hidden_class.hc001.hc001 - * nsk.jdb.hidden_class.hc001.hc001a + * @build nsk.jdb.hidden_class.hc001.hc001a * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.hidden_class.hc001.hc001 + * @run main/othervm + * nsk.jdb.hidden_class.hc001.hc001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/ignore/ignore001/ignore001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/ignore/ignore001/ignore001.java index 9763bcd47fdc1..6eb8c91e1eb78 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/ignore/ignore001/ignore001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/ignore/ignore001/ignore001.java @@ -39,9 +39,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.ignore.ignore001.ignore001 - * nsk.jdb.ignore.ignore001.ignore001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.ignore.ignore001.ignore001 + * @build nsk.jdb.ignore.ignore001.ignore001a + * @run main/othervm + * nsk.jdb.ignore.ignore001.ignore001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java index 47162adfedc85..a2d46e4ac15be 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/interrupt/interrupt001/interrupt001.java @@ -46,9 +46,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.interrupt.interrupt001.interrupt001 - * nsk.jdb.interrupt.interrupt001.interrupt001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.interrupt.interrupt001.interrupt001 + * @build nsk.jdb.interrupt.interrupt001.interrupt001a + * @run main/othervm + * nsk.jdb.interrupt.interrupt001.interrupt001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001.java index dbce2558a5ee0..15ec0902021b4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill001/kill001.java @@ -46,9 +46,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.kill.kill001.kill001 - * nsk.jdb.kill.kill001.kill001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.kill.kill001.kill001 + * @build nsk.jdb.kill.kill001.kill001a + * @run main/othervm + * nsk.jdb.kill.kill001.kill001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.java index 60b59e2a3375f..230dcdf12baaf 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/kill/kill002/kill002.java @@ -42,9 +42,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.kill.kill002.kill002 - * nsk.jdb.kill.kill002.kill002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.kill.kill002.kill002 + * @build nsk.jdb.kill.kill002.kill002a + * @run main/othervm + * nsk.jdb.kill.kill002.kill002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/klass/class001/class001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/klass/class001/class001.java index b291ff0860bbb..4c548348dc356 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/klass/class001/class001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/klass/class001/class001.java @@ -39,9 +39,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.klass.class001.class001 - * nsk.jdb.klass.class001.class001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.klass.class001.class001 + * @build nsk.jdb.klass.class001.class001a + * @run main/othervm + * nsk.jdb.klass.class001.class001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/list/list002/list002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/list/list002/list002.java index eb4f95d6979e2..4180ea3bb453b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/list/list002/list002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/list/list002/list002.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -42,10 +42,10 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.list.list002.list002 - * nsk.jdb.list.list002.list002a + * @build nsk.jdb.list.list002.list002a * @run driver jdk.test.lib.FileInstaller list002a.java src/nsk/jdb/list/list002/list002a.java - * @run main/othervm PropertyResolvingWrapper nsk.jdb.list.list002.list002 + * @run main/othervm + * nsk.jdb.list.list002.list002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java @@ -53,7 +53,7 @@ * -jdb=${test.jdk}/bin/jdb * -java.options="${test.vm.opts} ${test.java.opts}" * -workdir=. - * "-jdb.option=-sourcepath src/" + * -jdb.option="-sourcepath src/" * -debugee.vmkeys="${test.vm.opts} ${test.java.opts}" */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/locals/locals002/locals002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/locals/locals002/locals002.java index 3212484271b55..793cdc0460876 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/locals/locals002/locals002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/locals/locals002/locals002.java @@ -52,7 +52,8 @@ * @clean nsk.jdb.locals.locals002.locals002a * @compile -g:lines,source,vars locals002a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.locals.locals002.locals002 + * @run main/othervm + * nsk.jdb.locals.locals002.locals002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java index 73a94589da56e..2bacbab101bd4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/methods/methods002/methods002.java @@ -49,9 +49,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.methods.methods002.methods002 - * nsk.jdb.methods.methods002.methods002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.methods.methods002.methods002 + * @build nsk.jdb.methods.methods002.methods002a + * @run main/othervm + * nsk.jdb.methods.methods002.methods002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java index 47c81df9d0f59..181fe199dfecd 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.monitor.monitor001.monitor001 - * nsk.jdb.monitor.monitor001.monitor001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.monitor.monitor001.monitor001 + * @build nsk.jdb.monitor.monitor001.monitor001a + * @run main/othervm + * nsk.jdb.monitor.monitor001.monitor001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor002/monitor002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor002/monitor002.java index b65b195f286df..53c856128ce7b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor002/monitor002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor002/monitor002.java @@ -41,9 +41,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.monitor.monitor002.monitor002 - * nsk.jdb.monitor.monitor002.monitor002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.monitor.monitor002.monitor002 + * @build nsk.jdb.monitor.monitor002.monitor002a + * @run main/othervm + * nsk.jdb.monitor.monitor002.monitor002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/next/next001/next001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/next/next001/next001.java index cf21d2f713d8e..206199f0bb325 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/next/next001/next001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/next/next001/next001.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.next.next001.next001 - * nsk.jdb.next.next001.next001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.next.next001.next001 + * @build nsk.jdb.next.next001.next001a + * @run main/othervm + * nsk.jdb.next.next001.next001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect001/connect001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect001/connect001.java index c6fe0bed751a0..a78f3a96db421 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect001/connect001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect001/connect001.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.connect.connect001.connect001 - * nsk.jdb.options.connect.connect001.connect001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect001.connect001 + * @build nsk.jdb.options.connect.connect001.connect001a + * @run main/othervm + * nsk.jdb.options.connect.connect001.connect001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect002/connect002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect002/connect002.java index 130c2924e198a..78bcf2fb9737e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect002/connect002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect002/connect002.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.connect.connect002.connect002 - * nsk.jdb.options.connect.connect002.connect002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect002.connect002 + * @build nsk.jdb.options.connect.connect002.connect002a + * @run main/othervm + * nsk.jdb.options.connect.connect002.connect002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect003/connect003.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect003/connect003.java index f6e3eee716731..701f611d2ff39 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect003/connect003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect003/connect003.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.connect.connect003.connect003 - * nsk.jdb.options.connect.connect003.connect003a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect003.connect003 + * @build nsk.jdb.options.connect.connect003.connect003a + * @run main/othervm + * nsk.jdb.options.connect.connect003.connect003 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect004/connect004.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect004/connect004.java index 2a715bd6e26ac..adaa58627dd47 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect004/connect004.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect004/connect004.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.connect.connect004.connect004 - * nsk.jdb.options.connect.connect004.connect004a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect004.connect004 + * @build nsk.jdb.options.connect.connect004.connect004a + * @run main/othervm + * nsk.jdb.options.connect.connect004.connect004 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect005/connect005.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect005/connect005.java index 066c04149079f..8a67039246605 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect005/connect005.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/connect/connect005/connect005.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.connect.connect005.connect005 - * nsk.jdb.options.connect.connect005.connect005a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.options.connect.connect005.connect005 + * @build nsk.jdb.options.connect.connect005.connect005a + * @run main/othervm + * nsk.jdb.options.connect.connect005.connect005 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/listconnectors/listconnectors001/listconnectors001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/listconnectors/listconnectors001/listconnectors001.java index b54d1a011c582..d814df91cc693 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/listconnectors/listconnectors001/listconnectors001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/options/listconnectors/listconnectors001/listconnectors001.java @@ -51,8 +51,7 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.options.listconnectors.listconnectors001.listconnectors001 - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdb.options.listconnectors.listconnectors001.listconnectors001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.java index 1502dc6863fb2..e449a5771f27c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop/pop001/pop001.java @@ -46,9 +46,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.pop.pop001.pop001 - * nsk.jdb.pop.pop001.pop001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.pop.pop001.pop001 + * @build nsk.jdb.pop.pop001.pop001a + * @run main/othervm + * nsk.jdb.pop.pop001.pop001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop_exception/pop_exception001/pop_exception001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop_exception/pop_exception001/pop_exception001.java index 02eb088a74e4f..f70a5ffb96023 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop_exception/pop_exception001/pop_exception001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/pop_exception/pop_exception001/pop_exception001.java @@ -33,9 +33,8 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.pop_exception.pop_exception001.pop_exception001 - * nsk.jdb.pop_exception.pop_exception001.pop_exception001a - * @run main/othervm PropertyResolvingWrapper + * @build nsk.jdb.pop_exception.pop_exception001.pop_exception001a + * @run main/othervm * nsk.jdb.pop_exception.pop_exception001.pop_exception001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/print/print002/print002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/print/print002/print002.java index a9b5fd6d10078..e339a0a321b97 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/print/print002/print002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/print/print002/print002.java @@ -52,7 +52,8 @@ * @clean nsk.jdb.print.print002.print002a * @compile -g:lines,source,vars print002a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.print.print002.print002 + * @run main/othervm + * nsk.jdb.print.print002.print002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/read/read001/read001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/read/read001/read001.java index a72314fd19651..b5ca64334d775 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/read/read001/read001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/read/read001/read001.java @@ -52,7 +52,8 @@ * @clean nsk.jdb.read.read001.read001a * @compile -g:lines,source,vars read001a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.read.read001.read001 + * @run main/othervm + * nsk.jdb.read.read001.read001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/redefine/redefine001/redefine001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/redefine/redefine001/redefine001.java index 60684543c6e4d..80ff33889a410 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/redefine/redefine001/redefine001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/redefine/redefine001/redefine001.java @@ -45,19 +45,19 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.redefine.redefine001.redefine001 - * nsk.jdb.redefine.redefine001.redefine001a + * @build nsk.jdb.redefine.redefine001.redefine001a * * @comment compile newclass_g/RedefinedClass.java to newclass_g - * @build ExecDriver - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver + * ExecDriver --cmd * ${compile.jdk}/bin/javac * -d ${test.classes}/newclass_g * -g:lines,source,vars * -cp ${test.class.path} * ${test.src}/newclass_g/RedefinedClass.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.redefine.redefine001.redefine001 + * @run main/othervm + * nsk.jdb.redefine.redefine001.redefine001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/reenter/reenter001/reenter001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/reenter/reenter001/reenter001.java index 3cf654cee54b4..ebc063942c608 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/reenter/reenter001/reenter001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/reenter/reenter001/reenter001.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.reenter.reenter001.reenter001 - * nsk.jdb.reenter.reenter001.reenter001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.reenter.reenter001.reenter001 + * @build nsk.jdb.reenter.reenter001.reenter001a + * @run main/othervm + * nsk.jdb.reenter.reenter001.reenter001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/regression/b4689395/b4689395.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/regression/b4689395/b4689395.java index 91dc56c5ade28..82d8235fee724 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/regression/b4689395/b4689395.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/regression/b4689395/b4689395.java @@ -94,14 +94,15 @@ * nsk.jdb.regression.b4689395.b4689395a * * @comment compile newclass/b4689395a.java to newclass - * @build ExecDriver - * @run driver PropertyResolvingWrapper ExecDriver --cmd + * @run driver + * ExecDriver --cmd * ${compile.jdk}/bin/javac * -d ${test.classes}/newclass * -cp ${test.class.path} * ${test.src}/newclass/b4689395a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.regression.b4689395.b4689395 + * @run main/othervm + * nsk.jdb.regression.b4689395.b4689395 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/resume/resume002/resume002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/resume/resume002/resume002.java index c081008bcf834..1643ff28fe5c8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/resume/resume002/resume002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/resume/resume002/resume002.java @@ -49,9 +49,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.resume.resume002.resume002 - * nsk.jdb.resume.resume002.resume002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.resume.resume002.resume002 + * @build nsk.jdb.resume.resume002.resume002a + * @run main/othervm + * nsk.jdb.resume.resume002.resume002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/run/run002/run002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/run/run002/run002.java index e2f4fb2c40570..da837ab0f8bce 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/run/run002/run002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/run/run002/run002.java @@ -43,9 +43,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.run.run002.run002 - * nsk.jdb.run.run002.run002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.run.run002.run002 + * @build nsk.jdb.run.run002.run002a + * @run main/othervm + * nsk.jdb.run.run002.run002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set001/set001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set001/set001.java index 1026ab703cd97..d00362b228cbf 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set001/set001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set001/set001.java @@ -53,7 +53,8 @@ * @clean nsk.jdb.set.set001.set001a * @compile -g:lines,source,vars set001a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.set.set001.set001 + * @run main/othervm + * nsk.jdb.set.set001.set001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set002/set002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set002/set002.java index 797243801c748..dca4e554afaf9 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set002/set002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/set/set002/set002.java @@ -53,7 +53,8 @@ * @clean nsk.jdb.set.set002.set002a * @compile -g:lines,source,vars set002a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.set.set002.set002 + * @run main/othervm + * nsk.jdb.set.set002.set002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/step/step002/step002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/step/step002/step002.java index c9d360e386348..4df163ca1a92c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/step/step002/step002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/step/step002/step002.java @@ -56,7 +56,8 @@ * @clean nsk.jdb.step.step002.step002a * @compile -g:lines,source,vars step002a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.step.step002.step002 + * @run main/othervm + * nsk.jdb.step.step002.step002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/step_up/step_up001/step_up001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/step_up/step_up001/step_up001.java index a468d62ee75bd..590a476dbbe60 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/step_up/step_up001/step_up001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/step_up/step_up001/step_up001.java @@ -44,9 +44,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.step_up.step_up001.step_up001 - * nsk.jdb.step_up.step_up001.step_up001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.step_up.step_up001.step_up001 + * @build nsk.jdb.step_up.step_up001.step_up001a + * @run main/othervm + * nsk.jdb.step_up.step_up001.step_up001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java index 7bf4f72b78046..620c50fa2ae22 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java @@ -36,9 +36,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.stop_at.stop_at002.stop_at002 - * nsk.jdb.stop_at.stop_at002.stop_at002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.stop_at.stop_at002.stop_at002 + * @build nsk.jdb.stop_at.stop_at002.stop_at002a + * @run main/othervm + * nsk.jdb.stop_at.stop_at002.stop_at002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at003/stop_at003.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at003/stop_at003.java index 1a6a84aaf05d4..ecd66ca7c9573 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at003/stop_at003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_at/stop_at003/stop_at003.java @@ -48,9 +48,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.stop_at.stop_at003.stop_at003 - * nsk.jdb.stop_at.stop_at003.stop_at003a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.stop_at.stop_at003.stop_at003 + * @build nsk.jdb.stop_at.stop_at003.stop_at003a + * @run main/othervm + * nsk.jdb.stop_at.stop_at003.stop_at003 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_in/stop_in002/stop_in002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_in/stop_in002/stop_in002.java index 074e3490a705a..e4c2058fd97a3 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_in/stop_in002/stop_in002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/stop_in/stop_in002/stop_in002.java @@ -49,9 +49,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.stop_in.stop_in002.stop_in002 - * nsk.jdb.stop_in.stop_in002.stop_in002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.stop_in.stop_in002.stop_in002 + * @build nsk.jdb.stop_in.stop_in002.stop_in002a + * @run main/othervm + * nsk.jdb.stop_in.stop_in002.stop_in002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001.java index bf122add0fb3e..18e5c27d31c6c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/suspend/suspend001/suspend001.java @@ -45,9 +45,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.suspend.suspend001.suspend001 - * nsk.jdb.suspend.suspend001.suspend001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.suspend.suspend001.suspend001 + * @build nsk.jdb.suspend.suspend001.suspend001a + * @run main/othervm + * nsk.jdb.suspend.suspend001.suspend001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002.java index 17b1a3dddbfd5..487ac49e66ec9 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/thread/thread002/thread002.java @@ -42,9 +42,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.thread.thread002.thread002 - * nsk.jdb.thread.thread002.thread002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.thread.thread002.thread002 + * @build nsk.jdb.thread.thread002.thread002a + * @run main/othervm + * nsk.jdb.thread.thread002.thread002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroup/threadgroup002/threadgroup002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroup/threadgroup002/threadgroup002.java index d0476cffa21ca..cb8004643d3b7 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroup/threadgroup002/threadgroup002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroup/threadgroup002/threadgroup002.java @@ -40,9 +40,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.threadgroup.threadgroup002.threadgroup002 - * nsk.jdb.threadgroup.threadgroup002.threadgroup002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.threadgroup.threadgroup002.threadgroup002 + * @build nsk.jdb.threadgroup.threadgroup002.threadgroup002a + * @run main/othervm + * nsk.jdb.threadgroup.threadgroup002.threadgroup002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroups/threadgroups002/threadgroups002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroups/threadgroups002/threadgroups002.java index d3391872c9b3d..67ee29006b474 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroups/threadgroups002/threadgroups002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threadgroups/threadgroups002/threadgroups002.java @@ -40,9 +40,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.threadgroups.threadgroups002.threadgroups002 - * nsk.jdb.threadgroups.threadgroups002.threadgroups002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.threadgroups.threadgroups002.threadgroups002 + * @build nsk.jdb.threadgroups.threadgroups002.threadgroups002a + * @run main/othervm + * nsk.jdb.threadgroups.threadgroups002.threadgroups002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002.java index 6acead5c22f4f..3197c371943b0 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads002/threads002.java @@ -39,9 +39,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.threads.threads002.threads002 - * nsk.jdb.threads.threads002.threads002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.threads.threads002.threads002 + * @build nsk.jdb.threads.threads002.threads002a + * @run main/othervm + * nsk.jdb.threads.threads002.threads002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001.java index 24ee022f797d9..c345e80073659 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/trace/trace001/trace001.java @@ -46,9 +46,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.trace.trace001.trace001 - * nsk.jdb.trace.trace001.trace001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.trace.trace001.trace001 + * @build nsk.jdb.trace.trace001.trace001a + * @run main/othervm + * nsk.jdb.trace.trace001.trace001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/uncaught_exception/uncaught_exception002/uncaught_exception002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/uncaught_exception/uncaught_exception002/uncaught_exception002.java index a214515e9ad45..dd1d0748c0ff2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/uncaught_exception/uncaught_exception002/uncaught_exception002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/uncaught_exception/uncaught_exception002/uncaught_exception002.java @@ -52,7 +52,7 @@ * @clean nsk.jdb.uncaught_exception.uncaught_exception002.uncaught_exception002a * @compile -g:lines,source,vars uncaught_exception002a.java * - * @run main/othervm PropertyResolvingWrapper + * @run main/othervm * nsk.jdb.uncaught_exception.uncaught_exception002.uncaught_exception002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java index 05974b23439ed..54a90a930f277 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java @@ -56,7 +56,8 @@ * @clean nsk.jdb.unmonitor.unmonitor001.unmonitor001a * @compile -g:lines,source,vars unmonitor001a.java * - * @run main/othervm PropertyResolvingWrapper nsk.jdb.unmonitor.unmonitor001.unmonitor001 + * @run main/othervm + * nsk.jdb.unmonitor.unmonitor001.unmonitor001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java index 6c21f21d1e817..daad477dbb439 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/untrace/untrace001/untrace001.java @@ -53,9 +53,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.untrace.untrace001.untrace001 - * nsk.jdb.untrace.untrace001.untrace001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.untrace.untrace001.untrace001 + * @build nsk.jdb.untrace.untrace001.untrace001a + * @run main/othervm + * nsk.jdb.untrace.untrace001.untrace001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch001/unwatch001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch001/unwatch001.java index ec0d9ba82d049..b8c71645edb47 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch001/unwatch001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch001/unwatch001.java @@ -49,9 +49,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.unwatch.unwatch001.unwatch001 - * nsk.jdb.unwatch.unwatch001.unwatch001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.unwatch.unwatch001.unwatch001 + * @build nsk.jdb.unwatch.unwatch001.unwatch001a + * @run main/othervm + * nsk.jdb.unwatch.unwatch001.unwatch001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.java index 20781c8ea25e8..e32cc0b8e5dc6 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unwatch/unwatch002/unwatch002.java @@ -50,9 +50,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.unwatch.unwatch002.unwatch002 - * nsk.jdb.unwatch.unwatch002.unwatch002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.unwatch.unwatch002.unwatch002 + * @build nsk.jdb.unwatch.unwatch002.unwatch002a + * @run main/othervm + * nsk.jdb.unwatch.unwatch002.unwatch002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/up/up002/up002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/up/up002/up002.java index 22b5cc11ecbaa..5b2cb393df4e8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/up/up002/up002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/up/up002/up002.java @@ -42,9 +42,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.up.up002.up002 - * nsk.jdb.up.up002.up002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.up.up002.up002 + * @build nsk.jdb.up.up002.up002a + * @run main/othervm + * nsk.jdb.up.up002.up002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/use/use001/use001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/use/use001/use001.java index e6f08dc5477b9..1454b39b2bf8e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/use/use001/use001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/use/use001/use001.java @@ -42,9 +42,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.use.use001.use001 - * nsk.jdb.use.use001.use001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.use.use001.use001 + * @build nsk.jdb.use.use001.use001a + * @run main/othervm + * nsk.jdb.use.use001.use001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch001/watch001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch001/watch001.java index dfa8bdae04043..8d434fcfc7444 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch001/watch001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch001/watch001.java @@ -47,9 +47,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.watch.watch001.watch001 - * nsk.jdb.watch.watch001.watch001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.watch.watch001.watch001 + * @build nsk.jdb.watch.watch001.watch001a + * @run main/othervm + * nsk.jdb.watch.watch001.watch001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch002/watch002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch002/watch002.java index e0bfa26763453..cb0535117d9fd 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch002/watch002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/watch/watch002/watch002.java @@ -47,9 +47,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.watch.watch002.watch002 - * nsk.jdb.watch.watch002.watch002a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.watch.watch002.watch002 + * @build nsk.jdb.watch.watch002.watch002a + * @run main/othervm + * nsk.jdb.watch.watch002.watch002 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where004/where004.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where004/where004.java index e25316a5da63a..e4cbf50e62f68 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where004/where004.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where004/where004.java @@ -40,9 +40,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.where.where004.where004 - * nsk.jdb.where.where004.where004a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.where.where004.where004 + * @build nsk.jdb.where.where004.where004a + * @run main/othervm + * nsk.jdb.where.where004.where004 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where005/where005.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where005/where005.java index a405150e748a6..b949916aae74e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where005/where005.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where005/where005.java @@ -41,9 +41,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.where.where005.where005 - * nsk.jdb.where.where005.where005a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.where.where005.where005 + * @build nsk.jdb.where.where005.where005a + * @run main/othervm + * nsk.jdb.where.where005.where005 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006.java index 8532520ff0322..bf7622c48b345 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/where/where006/where006.java @@ -41,9 +41,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.where.where006.where006 - * nsk.jdb.where.where006.where006a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.where.where006.where006 + * @build nsk.jdb.where.where006.where006a + * @run main/othervm + * nsk.jdb.where.where006.where006 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java index c6cbefaaa51cc..431206b55510e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/wherei/wherei001/wherei001.java @@ -36,9 +36,9 @@ * * @library /vmTestbase * /test/lib - * @build nsk.jdb.wherei.wherei001.wherei001 - * nsk.jdb.wherei.wherei001.wherei001a - * @run main/othervm PropertyResolvingWrapper nsk.jdb.wherei.wherei001.wherei001 + * @build nsk.jdb.wherei.wherei001.wherei001a + * @run main/othervm + * nsk.jdb.wherei.wherei001.wherei001 * -arch=${os.family}-${os.simpleArch} * -waittime=5 * -debugee.vmkind=java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbArgumentHandler.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbArgumentHandler.java index dee6152777b10..40643308eeda8 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbArgumentHandler.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/JdbArgumentHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, 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 @@ -181,7 +181,11 @@ public String getJdbExecPath() { * Returns command line options jdb was launched with. */ public String getJdbOptions() { - return options.getProperty("jdb.option", ""); + String value = options.getProperty("jdb.option", "").trim(); + if (value.length() > 1 && value.startsWith("\"") && value.endsWith("\"")) { + value = value.substring(1, value.length() - 1).trim(); + } + return value; } /** From 4d9f20734791b30000547e90171191ae690ed245 Mon Sep 17 00:00:00 2001 From: Tejpal Rebari Date: Wed, 30 Sep 2020 05:00:26 +0000 Subject: [PATCH 71/79] 7151826: [TEST_BUG] [macosx] The test javax/swing/JPopupMenu/4966112/bug4966112.java not for mac Reviewed-by: serb, jdv --- test/jdk/ProblemList.txt | 1 - .../swing/JPopupMenu/4966112/bug4966112.java | 34 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 59acda983d8e6..40b9ce74002b7 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -777,7 +777,6 @@ javax/swing/JFileChooser/8062561/bug8062561.java 8196466 linux-all,macosx-all javax/swing/JInternalFrame/Test6325652.java 8224977 macosx-all javax/swing/JInternalFrame/8146321/JInternalFrameIconTest.java 8225045 linux-all javax/swing/JPopupMenu/4870644/bug4870644.java 8194130 macosx-all,linux-all -javax/swing/JPopupMenu/4966112/bug4966112.java 8064915 macosx-all javax/swing/MultiUIDefaults/Test6860438.java 8198391 generic-all javax/swing/UITest/UITest.java 8198392 generic-all javax/swing/plaf/basic/BasicComboBoxEditor/Test8015336.java 8198394 generic-all diff --git a/test/jdk/javax/swing/JPopupMenu/4966112/bug4966112.java b/test/jdk/javax/swing/JPopupMenu/4966112/bug4966112.java index a569d654e234d..1cb9c64118dbf 100644 --- a/test/jdk/javax/swing/JPopupMenu/4966112/bug4966112.java +++ b/test/jdk/javax/swing/JPopupMenu/4966112/bug4966112.java @@ -31,11 +31,27 @@ * @author Alexander Zuev * @run main bug4966112 */ -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JSpinner; +import javax.swing.JSplitPane; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; import javax.swing.event.PopupMenuListener; import javax.swing.event.PopupMenuEvent; -import java.awt.*; -import java.awt.event.*; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Robot; +import java.awt.Point; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class bug4966112 { @@ -48,6 +64,7 @@ public class bug4966112 { private static volatile JFileChooser filec; private static int buttonMask; private static Robot robot; + private static boolean isAquaFileChooser; public static void main(String[] args) throws Exception { robot = new Robot(); @@ -99,6 +116,11 @@ public static void main(String[] args) throws Exception { createAndShowFileChooser(); robot.waitForIdle(); + if ((UIManager.getLookAndFeel().getID()).equals("Aqua")) { + isAquaFileChooser = true; + } else { + isAquaFileChooser = false; + } clickMouse(filec); robot.waitForIdle(); @@ -146,7 +168,11 @@ private static void setClickPoint(final JComponent c) throws Exception { public void run() { Point p = c.getLocationOnScreen(); Dimension size = c.getSize(); - result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + if (isAquaFileChooser) { + result[0] = new Point(p.x + size.width / 2, p.y + 5); + } else { + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } } }); From ac02afe9dc0013bfab765b700b0e18a014e42f6c Mon Sep 17 00:00:00 2001 From: Jatin Bhateja Date: Wed, 30 Sep 2020 05:09:12 +0000 Subject: [PATCH 72/79] 8253721: Flag -XX:AVX3Threshold does not accept Zero value Reviewed-by: kvn, thartmann --- src/hotspot/cpu/x86/globals_x86.hpp | 1 + src/hotspot/cpu/x86/vm_version_x86.cpp | 7 ------- .../runtime/flags/jvmFlagConstraintsCompiler.cpp | 11 +++++++++++ .../runtime/flags/jvmFlagConstraintsCompiler.hpp | 1 + .../compiler/lir/amd64/AMD64ArrayCompareToOp.java | 1 - .../lir/amd64/AMD64StringLatin1InflateOp.java | 1 - .../lir/amd64/AMD64StringUTF16CompressOp.java | 1 - 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hotspot/cpu/x86/globals_x86.hpp b/src/hotspot/cpu/x86/globals_x86.hpp index 57acc05031ce0..ccc814e5d52fd 100644 --- a/src/hotspot/cpu/x86/globals_x86.hpp +++ b/src/hotspot/cpu/x86/globals_x86.hpp @@ -213,6 +213,7 @@ define_pd_global(intx, InitArrayShortSize, 8*BytesPerLong); "for copy, inflate and fill. When this value is set as zero" \ "compare operations can also use AVX512 intrinsics.") \ range(0, max_jint) \ + constraint(AVX3ThresholdConstraintFunc,AfterErgo) \ \ product(bool, IntelJccErratumMitigation, true, DIAGNOSTIC, \ "Turn off JVM mitigations related to Intel micro code " \ diff --git a/src/hotspot/cpu/x86/vm_version_x86.cpp b/src/hotspot/cpu/x86/vm_version_x86.cpp index dd3bc57c9aca1..d6a7a92a0ae49 100644 --- a/src/hotspot/cpu/x86/vm_version_x86.cpp +++ b/src/hotspot/cpu/x86/vm_version_x86.cpp @@ -1162,13 +1162,6 @@ void VM_Version::get_processor_features() { } #endif // COMPILER2 && ASSERT - if (!FLAG_IS_DEFAULT(AVX3Threshold)) { - if (!is_power_of_2(AVX3Threshold)) { - warning("AVX3Threshold must be a power of 2"); - FLAG_SET_DEFAULT(AVX3Threshold, 4096); - } - } - #ifdef _LP64 if (FLAG_IS_DEFAULT(UseMultiplyToLenIntrinsic)) { UseMultiplyToLenIntrinsic = true; diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp index 0119162ead1ec..80a1db91b15a3 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp @@ -285,6 +285,17 @@ JVMFlag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verb return JVMFlag::SUCCESS; } +JVMFlag::Error AVX3ThresholdConstraintFunc(int value, bool verbose) { + if (value != 0 && !is_power_of_2(value)) { + JVMFlag::printError(verbose, + "AVX3Threshold ( %d ) must be 0 or " + "a power of two value between 0 and MAX_INT\n", value); + return JVMFlag::VIOLATES_CONSTRAINT; + } + + return JVMFlag::SUCCESS; +} + JVMFlag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) { if (value >= 4032) { JVMFlag::printError(verbose, diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp index 6b4abf8a50117..85048b0836205 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp @@ -47,6 +47,7 @@ f(intx, OptoLoopAlignmentConstraintFunc) \ f(uintx, ArraycopyDstPrefetchDistanceConstraintFunc) \ f(uintx, ArraycopySrcPrefetchDistanceConstraintFunc) \ + f(int, AVX3ThresholdConstraintFunc) \ f(uintx, TypeProfileLevelConstraintFunc) \ f(intx, InitArrayShortSizeConstraintFunc) \ f(int , RTMTotalCountIncrRateConstraintFunc) \ diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java index 8c64732eae2a2..242265a2a6e5f 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java @@ -84,7 +84,6 @@ public final class AMD64ArrayCompareToOp extends AMD64LIRInstruction { public AMD64ArrayCompareToOp(LIRGeneratorTool tool, int useAVX3Threshold, JavaKind kind1, JavaKind kind2, Value result, Value array1, Value array2, Value length1, Value length2) { super(TYPE); - assert CodeUtil.isPowerOf2(useAVX3Threshold) : "AVX3Threshold must be power of 2"; this.useAVX3Threshold = useAVX3Threshold; this.kind1 = kind1; this.kind2 = kind2; diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringLatin1InflateOp.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringLatin1InflateOp.java index 6c82fb2e7e848..938ca78f94209 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringLatin1InflateOp.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringLatin1InflateOp.java @@ -71,7 +71,6 @@ public final class AMD64StringLatin1InflateOp extends AMD64LIRInstruction { public AMD64StringLatin1InflateOp(LIRGeneratorTool tool, int useAVX3Threshold, Value src, Value dst, Value len) { super(TYPE); - assert CodeUtil.isPowerOf2(useAVX3Threshold) : "AVX3Threshold must be power of 2"; this.useAVX3Threshold = useAVX3Threshold; assert asRegister(src).equals(rsi); diff --git a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringUTF16CompressOp.java b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringUTF16CompressOp.java index 8b04f272b70ea..e45f0d7c13faf 100644 --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringUTF16CompressOp.java +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64StringUTF16CompressOp.java @@ -76,7 +76,6 @@ public final class AMD64StringUTF16CompressOp extends AMD64LIRInstruction { public AMD64StringUTF16CompressOp(LIRGeneratorTool tool, int useAVX3Threshold, Value res, Value src, Value dst, Value len) { super(TYPE); - assert CodeUtil.isPowerOf2(useAVX3Threshold) : "AVX3Threshold must be power of 2"; this.useAVX3Threshold = useAVX3Threshold; assert asRegister(src).equals(rsi); From 4622a18a72c30c4fc72c166bee7de42903e1d036 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Wed, 30 Sep 2020 05:28:20 +0000 Subject: [PATCH 73/79] 8253791: Issue with useAppleColor check in CSystemColors.m Reviewed-by: phh, lucy, serb --- .../macosx/native/libawt_lwawt/awt/CSystemColors.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m index d437d6d96978f..5591a56d24661 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, 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 @@ -126,7 +126,7 @@ + (void)reloadColors { + (NSColor*)getColor:(NSUInteger)colorIndex useAppleColor:(BOOL)useAppleColor { NSColor* result = nil; - if (colorIndex < (useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS) { + if (colorIndex < ((useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS)) { result = (useAppleColor ? appleColors : sColors)[colorIndex]; } else { From 3078b5f340b6f23315a2511bc38c57ae57b47758 Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Wed, 30 Sep 2020 07:02:29 +0000 Subject: [PATCH 74/79] 6441211: Small Error in API at javax.swing.plaf.synth.Region Reviewed-by: trebari, jdv --- .../share/classes/javax/swing/plaf/synth/Region.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java b/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java index ea6e264b51e20..5a59f3bb98dc8 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/Region.java @@ -237,7 +237,7 @@ public class Region { public static final Region RADIO_BUTTON = new Region("RadioButton", false); /** - * RegionButtonMenuItem region. To bind a style to this Region + * RadioButtonMenuItem region. To bind a style to this Region * use the name RadioButtonMenuItem. */ public static final Region RADIO_BUTTON_MENU_ITEM = new Region("RadioButtonMenuItem", false); From 4c6536511664bc218d82e09208ef04019040cea8 Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Wed, 30 Sep 2020 07:04:00 +0000 Subject: [PATCH 75/79] 8253792: javax.swing.text.GapContent documentation typos Reviewed-by: jdv --- .../share/classes/javax/swing/text/GapContent.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/text/GapContent.java b/src/java.desktop/share/classes/javax/swing/text/GapContent.java index 282e08f78b2c4..a5673b52540d2 100644 --- a/src/java.desktop/share/classes/javax/swing/text/GapContent.java +++ b/src/java.desktop/share/classes/javax/swing/text/GapContent.java @@ -39,7 +39,7 @@ /** * An implementation of the AbstractDocument.Content interface * implemented using a gapped buffer similar to that used by emacs. - * The underlying storage is a array of unicode characters with + * The underlying storage is an array of Unicode characters with * a gap somewhere. The gap is moved to the location of changes * to take advantage of common behavior where most changes are * in the same location. Changes that occur at a gap boundary are @@ -49,8 +49,8 @@ * The positions tracking change are also generally cheap to * maintain. The Position implementations (marks) store the array * index and can easily calculate the sequential position from - * the current gap location. Changes only require update to the - * the marks between the old and new gap boundaries when the gap + * the current gap location. Changes only require updating the + * marks between the old and new gap boundaries when the gap * is moved, so generally updating the marks is pretty cheap. * The marks are stored sorted so they can be located quickly * with a binary search. This increases the cost of adding a @@ -320,7 +320,7 @@ public String toString() { /** * Record used for searching for the place to - * start updating mark indexs when the gap + * start updating mark indexes when the gap * boundaries are moved. */ private transient MarkData search; From 8331e63fe419e9ab796732fb01e0a68f8474045c Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Wed, 30 Sep 2020 08:58:24 +0000 Subject: [PATCH 76/79] 8253778: ShenandoahSafepoint::is_at_shenandoah_safepoint should not access VMThread state from other threads Reviewed-by: jiefu, rehn, rkennke --- src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp b/src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp index 8324c5caef827..2f4fde1364115 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahUtils.hpp @@ -141,10 +141,17 @@ class ShenandoahGCPauseMark : public StackObj { class ShenandoahSafepoint : public AllStatic { public: - // check if Shenandoah GC safepoint is in progress + // Check if Shenandoah GC safepoint is in progress. This is nominally + // equivalent to calling SafepointSynchronize::is_at_safepoint(), but + // it also checks the Shenandoah specifics, when it can. static inline bool is_at_shenandoah_safepoint() { if (!SafepointSynchronize::is_at_safepoint()) return false; + // This is not VM thread, cannot see what VM thread is doing, + // so pretend this is a proper Shenandoah safepoint + if (!Thread::current()->is_VM_thread()) return true; + + // Otherwise check we are at proper operation type VM_Operation* vm_op = VMThread::vm_operation(); if (vm_op == NULL) return false; From dc3a0f5f88bb7b4255c7aa324f6160550173f2c2 Mon Sep 17 00:00:00 2001 From: Martin Doerr Date: Wed, 30 Sep 2020 09:03:06 +0000 Subject: [PATCH 77/79] 8253183: Fragile memory barrier selection for some weak memory model platforms Reviewed-by: dholmes, eosterlund, dcubed --- src/hotspot/share/gc/shared/taskqueue.inline.hpp | 10 +++------- src/hotspot/share/runtime/objectMonitor.cpp | 11 ++++------- src/hotspot/share/runtime/orderAccess.hpp | 11 +++++++++++ src/hotspot/share/runtime/synchronizer.cpp | 12 +++++------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/hotspot/share/gc/shared/taskqueue.inline.hpp b/src/hotspot/share/gc/shared/taskqueue.inline.hpp index 3e377a7a7a9aa..46372956cf005 100644 --- a/src/hotspot/share/gc/shared/taskqueue.inline.hpp +++ b/src/hotspot/share/gc/shared/taskqueue.inline.hpp @@ -205,7 +205,7 @@ bool OverflowTaskQueue::pop_overflow(E& t) template bool GenericTaskQueue::pop_global(E& t) { Age oldAge = age_relaxed(); -#ifndef CPU_MULTI_COPY_ATOMIC + // Architectures with non-multi-copy-atomic memory model require a // full fence here to guarantee that bottom is not older than age, // which is crucial for the correctness of the algorithm. @@ -219,12 +219,8 @@ bool GenericTaskQueue::pop_global(E& t) { // The requirement is that Thread3 must never read an older bottom // value than Thread2 after Thread3 has seen the age value from // Thread2. - OrderAccess::fence(); -#else - // Everyone else can make do with a LoadLoad barrier to keep reads - // from age and bottom in order. - OrderAccess::loadload(); -#endif + OrderAccess::loadload_for_IRIW(); + uint localBot = bottom_acquire(); uint n_elems = clean_size(localBot, oldAge.top()); if (n_elems == 0) { diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp index 212a52d682463..74671fbbf6c2e 100644 --- a/src/hotspot/share/runtime/objectMonitor.cpp +++ b/src/hotspot/share/runtime/objectMonitor.cpp @@ -489,13 +489,10 @@ void ObjectMonitor::install_displaced_markword_in_object(const oop obj) { // Separate loads in is_being_async_deflated(), which is almost always // called before this function, from the load of dmw/header below. - if (support_IRIW_for_not_multiple_copy_atomic_cpu) { - // A non-multiple copy atomic (nMCA) machine needs a bigger - // hammer to separate the loads before and the load below. - OrderAccess::fence(); - } else { - OrderAccess::loadload(); - } + + // _contentions and dmw/header may get written by different threads. + // Make sure to observe them in the same order when having several observers. + OrderAccess::loadload_for_IRIW(); const oop l_object = object_peek(); if (l_object == NULL) { diff --git a/src/hotspot/share/runtime/orderAccess.hpp b/src/hotspot/share/runtime/orderAccess.hpp index fee9518ef926a..ab522a59a8124 100644 --- a/src/hotspot/share/runtime/orderAccess.hpp +++ b/src/hotspot/share/runtime/orderAccess.hpp @@ -243,6 +243,17 @@ class OrderAccess : public AllStatic { static void fence(); static void cross_modify_fence(); + + // Processors which are not multi-copy-atomic require a full fence + // to enforce a globally consistent order of Independent Reads of + // Independent Writes. Please use only for such patterns! + static void loadload_for_IRIW() { +#ifndef CPU_MULTI_COPY_ATOMIC + fence(); +#else + loadload(); +#endif + } private: // This is a helper that invokes the StubRoutines::fence_entry() // routine if it exists, It should only be used by platforms that diff --git a/src/hotspot/share/runtime/synchronizer.cpp b/src/hotspot/share/runtime/synchronizer.cpp index 1f7db809c99ff..fda95d66b8d68 100644 --- a/src/hotspot/share/runtime/synchronizer.cpp +++ b/src/hotspot/share/runtime/synchronizer.cpp @@ -1105,13 +1105,11 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* self, oop obj) { // Separate load of dmw/header above from the loads in // is_being_async_deflated(). - if (support_IRIW_for_not_multiple_copy_atomic_cpu) { - // A non-multiple copy atomic (nMCA) machine needs a bigger - // hammer to separate the load above and the loads below. - OrderAccess::fence(); - } else { - OrderAccess::loadload(); - } + + // dmw/header and _contentions may get written by different threads. + // Make sure to observe them in the same order when having several observers. + OrderAccess::loadload_for_IRIW(); + if (monitor->is_being_async_deflated()) { // But we can't safely use the hash if we detect that async // deflation has occurred. So we attempt to restore the From 04775f11fe637029b6040b494bb495939c6d3fcf Mon Sep 17 00:00:00 2001 From: Patric Hedlin Date: Wed, 30 Sep 2020 09:06:17 +0000 Subject: [PATCH 78/79] 8253768: Deleting unused pipe_class definitions in adl-file (x86_64.ad). Reviewed-by: neliasso --- src/hotspot/cpu/x86/x86_64.ad | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/hotspot/cpu/x86/x86_64.ad b/src/hotspot/cpu/x86/x86_64.ad index 9664b4a30410b..fe1b44741a853 100644 --- a/src/hotspot/cpu/x86/x86_64.ad +++ b/src/hotspot/cpu/x86/x86_64.ad @@ -4250,16 +4250,6 @@ pipe_class ialu_reg_fat(rRegI dst) ALU : S3; // any alu %} -// Long ALU reg operation using big decoder -pipe_class ialu_reg_long_fat(rRegL dst) -%{ - instruction_count(2); - dst : S4(write); - dst : S3(read); - D0 : S0(2); // big decoder only; twice - ALU : S3(2); // any 2 alus -%} - // Integer ALU reg-reg operation pipe_class ialu_reg_reg(rRegI dst, rRegI src) %{ @@ -4270,16 +4260,6 @@ pipe_class ialu_reg_reg(rRegI dst, rRegI src) ALU : S3; // any alu %} -// Long ALU reg-reg operation -pipe_class ialu_reg_reg_long(rRegL dst, rRegL src) -%{ - instruction_count(2); - dst : S4(write); - src : S3(read); - DECODE : S0(2); // any 2 decoders - ALU : S3(2); // both alus -%} - // Integer ALU reg-reg operation pipe_class ialu_reg_reg_fat(rRegI dst, memory src) %{ @@ -4290,16 +4270,6 @@ pipe_class ialu_reg_reg_fat(rRegI dst, memory src) ALU : S3; // any alu %} -// Long ALU reg-reg operation -pipe_class ialu_reg_reg_long_fat(rRegL dst, rRegL src) -%{ - instruction_count(2); - dst : S4(write); - src : S3(read); - D0 : S0(2); // big decoder only; twice - ALU : S3(2); // both alus -%} - // Integer ALU reg-mem operation pipe_class ialu_reg_mem(rRegI dst, memory mem) %{ From f80a6066e45c3d53a61715abfe71abc3b2e162a1 Mon Sep 17 00:00:00 2001 From: Paul Hohensee Date: Wed, 30 Sep 2020 12:16:25 +0000 Subject: [PATCH 79/79] 8253375: OSX build fails with Xcode 12.0 (12A7209) Replace double array with short array in AdapterHandlerLibrary::create_native_wrapper, add parens around ?: in CSystemColors:getColor Reviewed-by: prr, kbarrett, lucy --- src/hotspot/share/runtime/sharedRuntime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index 44e2da7f39953..1a614b83b844f 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -2856,8 +2856,8 @@ void AdapterHandlerLibrary::create_native_wrapper(const methodHandle& method) { BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache if (buf != NULL) { CodeBuffer buffer(buf); - double locs_buf[20]; - buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo)); + struct { double data[20]; } locs_buf; + buffer.insts()->initialize_shared_locs((relocInfo*)&locs_buf, sizeof(locs_buf) / sizeof(relocInfo)); #if defined(AARCH64) // On AArch64 with ZGC and nmethod entry barriers, we need all oops to be // in the constant pool to ensure ordering between the barrier and oops