diff --git a/doc/building.html b/doc/building.html index d6f7b5a8c19..71c0d621ee2 100644 --- a/doc/building.html +++ b/doc/building.html @@ -72,6 +72,7 @@

Building the JDK

  • Specifying the Target Platform
  • Toolchain Considerations
  • Native Libraries
  • +
  • Creating And Using Sysroots With qemu-deboostrap
  • Building for ARM/aarch64
  • Verifying the Build
  • @@ -634,6 +635,72 @@

    X11

    cp: cannot stat `arm-linux-gnueabihf/libXt.so': No such file or directory
  • If the X11 libraries are not properly detected by configure, you can point them out by --with-x.

  • +

    Creating And Using Sysroots With qemu-deboostrap

    +

    Fortunately, you can create sysroots for foreign architectures with tools provided by your OS. On Debian/Ubuntu systems, one could use qemu-deboostrap to create the target system chroot, which would have the native libraries and headers specific to that target system. After that, we can use the cross-compiler on the build system, pointing into chroot to get the build dependencies right. This allows building for foreign architectures with native compilation speed.

    +

    For example, cross-compiling to AArch64 from x86_64 could be done like this:

    + +

    The build does not create new files in that chroot, so it can be reused for multiple builds without additional cleanup.

    +

    Architectures that are known to successfully cross-compile like this are:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TargetCCCXX--arch=...--openjdk-target=...
    x86defaultdefaulti386i386-linux-gnu
    armhfgcc-arm-linux-gnueabihfg++-arm-linux-gnueabihfarmhfarm-linux-gnueabihf
    aarch64gcc-aarch64-linux-gnug++-aarch64-linux-gnuarm64aarch64-linux-gnu
    ppc64elgcc-powerpc64le-linux-gnug++-powerpc64le-linux-gnuppc64elpowerpc64le-linux-gnu
    s390xgcc-s390x-linux-gnug++-s390x-linux-gnus390xs390x-linux-gnu
    +

    Additional architectures might be supported by Debian/Ubuntu Ports.

    Building for ARM/aarch64

    A common cross-compilation target is the ARM CPU. When building for ARM, it is useful to set the ABI profile. A number of pre-defined ABI profiles are available using --with-abi-profile: arm-vfp-sflt, arm-vfp-hflt, arm-sflt, armv5-vfp-sflt, armv6-vfp-hflt. Note that soft-float ABIs are no longer properly supported by the JDK.

    The JDK contains two different ports for the aarch64 platform, one is the original aarch64 port from the AArch64 Port Project and one is a 64-bit version of the Oracle contributed ARM port. When targeting aarch64, by the default the original aarch64 port is used. To select the Oracle ARM 64 port, use --with-cpu-port=arm64. Also set the corresponding value (aarch64 or arm64) to --with-abi-profile, to ensure a consistent build.

    diff --git a/doc/building.md b/doc/building.md index e5990a76300..653683d10d7 100644 --- a/doc/building.md +++ b/doc/building.md @@ -1018,6 +1018,51 @@ Note that X11 is needed even if you only want to build a headless JDK. * If the X11 libraries are not properly detected by `configure`, you can point them out by `--with-x`. +### Creating And Using Sysroots With qemu-deboostrap + +Fortunately, you can create sysroots for foreign architectures with tools +provided by your OS. On Debian/Ubuntu systems, one could use `qemu-deboostrap` to +create the *target* system chroot, which would have the native libraries and headers +specific to that *target* system. After that, we can use the cross-compiler on the *build* +system, pointing into chroot to get the build dependencies right. This allows building +for foreign architectures with native compilation speed. + +For example, cross-compiling to AArch64 from x86_64 could be done like this: + + * Install cross-compiler on the *build* system: +``` +apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu +``` + + * Create chroot on the *build* system, configuring it for *target* system: +``` +sudo qemu-debootstrap --arch=arm64 --verbose \ + --include=fakeroot,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng12-dev \ + --resolve-deps jessie /chroots/arm64 http://httpredir.debian.org/debian/ +``` + + * Configure and build with newly created chroot as sysroot/toolchain-path: +``` +CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ sh ./configure --openjdk-target=aarch64-linux-gnu --with-sysroot=/chroots/arm64/ --with-toolchain-path=/chroots/arm64/ +make images +ls build/linux-aarch64-normal-server-release/ +``` + +The build does not create new files in that chroot, so it can be reused for multiple builds +without additional cleanup. + +Architectures that are known to successfully cross-compile like this are: + + Target `CC` `CXX` `--arch=...` `--openjdk-target=...` + ------------ ------------------------- --------------------------- ------------ ---------------------- + x86 default default i386 i386-linux-gnu + armhf gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf armhf arm-linux-gnueabihf + aarch64 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu arm64 aarch64-linux-gnu + ppc64el gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu ppc64el powerpc64le-linux-gnu + s390x gcc-s390x-linux-gnu g++-s390x-linux-gnu s390x s390x-linux-gnu + +Additional architectures might be supported by Debian/Ubuntu Ports. + ### Building for ARM/aarch64 A common cross-compilation target is the ARM CPU. When building for ARM, it is diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk index 41c5a8e1efc..e90921e70af 100644 --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -94,7 +94,7 @@ define SetupTestFilesCompilationBody CFLAGS := $$($1_CFLAGS) $$($1_CFLAGS_$$(name)), \ LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$(name)), \ LIBS := $$($1_LIBS_$$(name)), \ - OPTIMIZATION := LOW, \ + OPTIMIZATION := $$(if $$($1_OPTIMIZATION_$$(name)),$$($1_OPTIMIZATION_$$(name)),LOW), \ COPY_DEBUG_SYMBOLS := false, \ STRIP_SYMBOLS := false, \ )) \ diff --git a/make/jdk/src/classes/build/tools/module/GenModuleInfoSource.java b/make/jdk/src/classes/build/tools/module/GenModuleInfoSource.java index 478a90811b5..5189c995d53 100644 --- a/make/jdk/src/classes/build/tools/module/GenModuleInfoSource.java +++ b/make/jdk/src/classes/build/tools/module/GenModuleInfoSource.java @@ -431,14 +431,12 @@ private void process(Parser parser, boolean extraFile) throws IOException { } uses.put(name, statement); break; - /* Disable this check until jdk.internal.vm.compiler generated file is fixed. case "provides": if (provides.containsKey(name)) { throw parser.newError("multiple " + keyword + " " + name); } provides.put(name, statement); break; - */ } String lookAhead = lookAhead(parser); if (lookAhead.equals(statement.qualifier)) { diff --git a/make/jdk/src/classes/build/tools/module/ModuleInfoExtraTest.java b/make/jdk/src/classes/build/tools/module/ModuleInfoExtraTest.java index 5f15a20bb58..f9a09ef3f3b 100644 --- a/make/jdk/src/classes/build/tools/module/ModuleInfoExtraTest.java +++ b/make/jdk/src/classes/build/tools/module/ModuleInfoExtraTest.java @@ -230,7 +230,11 @@ void check(GenModuleInfoSource source, new String[] { " uses s;", " uses s;" - }, ".*, line .*, multiple uses s.*" + }, ".*, line .*, multiple uses s.*", + new String[] { + " provides s with impl1;", + " provides s with impl2, impl3;" + }, ".*, line .*, multiple provides s.*" ); void errorCases() { diff --git a/make/test/JtregNativeHotspot.gmk b/make/test/JtregNativeHotspot.gmk index 19d352da797..eef272c6a5b 100644 --- a/make/test/JtregNativeHotspot.gmk +++ b/make/test/JtregNativeHotspot.gmk @@ -139,6 +139,15 @@ NSK_AOD_INCLUDES := \ -I$(VM_TESTBASE_DIR)/nsk/share/native \ -I$(VM_TESTBASE_DIR)/nsk/share/jni +NO_FRAMEPOINTER_CFLAGS := +ifeq ($(OPENJDK_TARGET_OS),linux) + NO_FRAMEPOINTER_CFLAGS := -fomit-frame-pointer +endif + +BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libNoFramePointer := $(NO_FRAMEPOINTER_CFLAGS) +# Optimization -O3 needed, HIGH == -O3 +BUILD_HOTSPOT_JTREG_LIBRARIES_OPTIMIZATION_libNoFramePointer := HIGH + BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libProcessUtils := $(VM_SHARE_INCLUDES) BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libThreadController := $(NSK_MONITORING_INCLUDES) diff --git a/src/java.base/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java b/src/java.base/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java index e85b8816a28..9c76839f385 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java @@ -73,62 +73,69 @@ protected void engineInit(Key key, AlgorithmParameterSpec params) salt = pbeKey.getSalt(); // maybe null if unspecified iCount = pbeKey.getIterationCount(); // maybe 0 if unspecified } else if (key instanceof SecretKey) { - byte[] passwdBytes = key.getEncoded(); - if ((passwdBytes == null) || - !(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) { + byte[] passwdBytes; + if (!(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3)) || + (passwdBytes = key.getEncoded()) == null) { throw new InvalidKeyException("Missing password"); } passwdChars = new char[passwdBytes.length]; for (int i=0; i { - java.util.Arrays.fill(k, (byte)0x00); - java.util.Arrays.fill(p, '0'); - }); + // Use the cleaner to zero the key when no longer referenced + final byte[] k = this.key; + final char[] p = this.passwd; + CleanerFactory.cleaner().register(this, + () -> { + Arrays.fill(k, (byte) 0x00); + Arrays.fill(p, '\0'); + }); + } } private static byte[] deriveKey(final Mac prf, final byte[] password, @@ -266,8 +270,8 @@ public boolean equals(Object obj) { if (!(that.getFormat().equalsIgnoreCase("RAW"))) return false; byte[] thatEncoded = that.getEncoded(); - boolean ret = MessageDigest.isEqual(key, that.getEncoded()); - java.util.Arrays.fill(thatEncoded, (byte)0x00); + boolean ret = MessageDigest.isEqual(key, thatEncoded); + Arrays.fill(thatEncoded, (byte)0x00); return ret; } diff --git a/src/java.base/share/classes/com/sun/crypto/provider/PBMAC1Core.java b/src/java.base/share/classes/com/sun/crypto/provider/PBMAC1Core.java index 2f0ba131a55..2ff02904c00 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/PBMAC1Core.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/PBMAC1Core.java @@ -108,72 +108,76 @@ protected void engineInit(Key key, AlgorithmParameterSpec params) salt = pbeKey.getSalt(); // maybe null if unspecified iCount = pbeKey.getIterationCount(); // maybe 0 if unspecified } else if (key instanceof SecretKey) { - byte[] passwdBytes = key.getEncoded(); - if ((passwdBytes == null) || - !(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) { + byte[] passwdBytes; + if (!(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3)) || + (passwdBytes = key.getEncoded()) == null) { throw new InvalidKeyException("Missing password"); } passwdChars = new char[passwdBytes.length]; for (int i=0; i>> 31); + // HD, Count trailing 0's + i = ~i & (i - 1); + if (i <= 0) return i & 32; + int n = 1; + if (i > 1 << 16) { n += 16; i >>>= 16; } + if (i > 1 << 8) { n += 8; i >>>= 8; } + if (i > 1 << 4) { n += 4; i >>>= 4; } + if (i > 1 << 2) { n += 2; i >>>= 2; } + return n + (i >>> 1); } /** diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java index eca555216b2..304089571cc 100644 --- a/src/java.base/share/classes/java/lang/Long.java +++ b/src/java.base/share/classes/java/lang/Long.java @@ -1782,16 +1782,9 @@ public static int numberOfLeadingZeros(long i) { */ @HotSpotIntrinsicCandidate public static int numberOfTrailingZeros(long i) { - // HD, Figure 5-14 - int x, y; - if (i == 0) return 64; - int n = 63; - y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32); - y = x <<16; if (y != 0) { n = n -16; x = y; } - y = x << 8; if (y != 0) { n = n - 8; x = y; } - y = x << 4; if (y != 0) { n = n - 4; x = y; } - y = x << 2; if (y != 0) { n = n - 2; x = y; } - return n - ((x << 1) >>> 31); + int x = (int)i; + return x == 0 ? 32 + Integer.numberOfTrailingZeros((int)(i >>> 32)) + : Integer.numberOfTrailingZeros(x); } /** diff --git a/src/java.base/share/classes/sun/security/provider/DSA.java b/src/java.base/share/classes/sun/security/provider/DSA.java index 56495e08301..175b724e1f7 100644 --- a/src/java.base/share/classes/sun/security/provider/DSA.java +++ b/src/java.base/share/classes/sun/security/provider/DSA.java @@ -152,7 +152,7 @@ protected void engineInitSign(PrivateKey privateKey) // check key size against hash output size for signing // skip this check for verification to minimize impact on existing apps - if (md.getAlgorithm() != "NullDigest20") { + if (!"NullDigest20".equals(md.getAlgorithm())) { checkKey(params, md.getDigestLength()*8, md.getAlgorithm()); } diff --git a/src/java.base/share/classes/sun/security/provider/DigestBase.java b/src/java.base/share/classes/sun/security/provider/DigestBase.java index 24847c0abf3..54eb85527bb 100644 --- a/src/java.base/share/classes/sun/security/provider/DigestBase.java +++ b/src/java.base/share/classes/sun/security/provider/DigestBase.java @@ -28,6 +28,7 @@ import java.security.MessageDigestSpi; import java.security.DigestException; import java.security.ProviderException; +import java.util.Arrays; import java.util.Objects; import jdk.internal.HotSpotIntrinsicCandidate; @@ -178,6 +179,7 @@ protected final void engineReset() { implReset(); bufOfs = 0; bytesProcessed = 0; + Arrays.fill(buffer, (byte) 0x00); } // return the digest. See JCA doc. diff --git a/src/java.base/share/classes/sun/security/provider/MD4.java b/src/java.base/share/classes/sun/security/provider/MD4.java index 3c94f6ce66d..b1c45ab90ec 100644 --- a/src/java.base/share/classes/sun/security/provider/MD4.java +++ b/src/java.base/share/classes/sun/security/provider/MD4.java @@ -26,6 +26,7 @@ package sun.security.provider; import java.security.*; +import java.util.Arrays; import static sun.security.provider.ByteArrayAccess.*; import static sun.security.util.SecurityConstants.PROVIDER_VER; @@ -92,7 +93,7 @@ public MD4() { super("MD4", 16, 64); state = new int[4]; x = new int[16]; - implReset(); + resetHashes(); } // clone this object @@ -108,6 +109,12 @@ public Object clone() throws CloneNotSupportedException { */ void implReset() { // Load magic initialization constants. + resetHashes(); + // clear out old data + Arrays.fill(x, 0); + } + + private void resetHashes() { state[0] = 0x67452301; state[1] = 0xefcdab89; state[2] = 0x98badcfe; diff --git a/src/java.base/share/classes/sun/security/provider/MD5.java b/src/java.base/share/classes/sun/security/provider/MD5.java index c9747de8a59..c168ace71a3 100644 --- a/src/java.base/share/classes/sun/security/provider/MD5.java +++ b/src/java.base/share/classes/sun/security/provider/MD5.java @@ -25,6 +25,8 @@ package sun.security.provider; +import java.util.Arrays; + import static sun.security.provider.ByteArrayAccess.*; /** @@ -66,7 +68,7 @@ public MD5() { super("MD5", 16, 64); state = new int[4]; x = new int[16]; - implReset(); + resetHashes(); } // clone this object @@ -82,6 +84,12 @@ public Object clone() throws CloneNotSupportedException { */ void implReset() { // Load magic initialization constants. + resetHashes(); + // clear out old data + Arrays.fill(x, 0); + } + + private void resetHashes() { state[0] = 0x67452301; state[1] = 0xefcdab89; state[2] = 0x98badcfe; diff --git a/src/java.base/share/classes/sun/security/provider/SHA.java b/src/java.base/share/classes/sun/security/provider/SHA.java index e34ff517537..1eaeaa4ffc3 100644 --- a/src/java.base/share/classes/sun/security/provider/SHA.java +++ b/src/java.base/share/classes/sun/security/provider/SHA.java @@ -25,6 +25,7 @@ package sun.security.provider; +import java.util.Arrays; import java.util.Objects; import static sun.security.provider.ByteArrayAccess.*; @@ -62,7 +63,7 @@ public SHA() { super("SHA-1", 20, 64); state = new int[5]; W = new int[80]; - implReset(); + resetHashes(); } /* @@ -79,6 +80,13 @@ public Object clone() throws CloneNotSupportedException { * Resets the buffers and hash value to start a new hash. */ void implReset() { + // Load magic initialization constants. + resetHashes(); + // clear out old data + Arrays.fill(W, 0); + } + + private void resetHashes() { state[0] = 0x67452301; state[1] = 0xefcdab89; state[2] = 0x98badcfe; diff --git a/src/java.base/share/classes/sun/security/provider/SHA2.java b/src/java.base/share/classes/sun/security/provider/SHA2.java index 4cadf569f9a..5c293e5ac17 100644 --- a/src/java.base/share/classes/sun/security/provider/SHA2.java +++ b/src/java.base/share/classes/sun/security/provider/SHA2.java @@ -25,6 +25,7 @@ package sun.security.provider; +import java.util.Arrays; import java.util.Objects; import jdk.internal.HotSpotIntrinsicCandidate; @@ -83,13 +84,18 @@ abstract class SHA2 extends DigestBase { this.initialHashes = initialHashes; state = new int[8]; W = new int[64]; - implReset(); + resetHashes(); } /** * Resets the buffers and hash value to start a new hash. */ void implReset() { + resetHashes(); + Arrays.fill(W, 0); + } + + private void resetHashes() { System.arraycopy(initialHashes, 0, state, 0, state.length); } diff --git a/src/java.base/share/classes/sun/security/provider/SHA5.java b/src/java.base/share/classes/sun/security/provider/SHA5.java index 163d30e3fb9..22af8436027 100644 --- a/src/java.base/share/classes/sun/security/provider/SHA5.java +++ b/src/java.base/share/classes/sun/security/provider/SHA5.java @@ -25,6 +25,7 @@ package sun.security.provider; +import java.util.Arrays; import java.util.Objects; import jdk.internal.HotSpotIntrinsicCandidate; @@ -98,10 +99,15 @@ abstract class SHA5 extends DigestBase { this.initialHashes = initialHashes; state = new long[8]; W = new long[80]; - implReset(); + resetHashes(); } final void implReset() { + resetHashes(); + Arrays.fill(W, 0L); + } + + private void resetHashes() { System.arraycopy(initialHashes, 0, state, 0, state.length); } diff --git a/src/java.base/unix/classes/java/io/UnixFileSystem.java b/src/java.base/unix/classes/java/io/UnixFileSystem.java index 23d3e52bad8..05615d6d081 100644 --- a/src/java.base/unix/classes/java/io/UnixFileSystem.java +++ b/src/java.base/unix/classes/java/io/UnixFileSystem.java @@ -44,6 +44,8 @@ public UnixFileSystem() { colon = props.getProperty("path.separator").charAt(0); javaHome = StaticProperty.javaHome(); userDir = StaticProperty.userDir(); + cache = useCanonCaches ? new ExpiringCache() : null; + javaHomePrefixCache = useCanonPrefixCache ? new ExpiringCache() : null; } @@ -145,11 +147,11 @@ public String resolve(File f) { // same directory, and must not create results differing from the true // canonicalization algorithm in canonicalize_md.c. For this reason the // prefix cache is conservative and is not used for complex path names. - private ExpiringCache cache = new ExpiringCache(); + private final ExpiringCache cache; // On Unix symlinks can jump anywhere in the file system, so we only // treat prefixes in java.home as trusted and cacheable in the // canonicalization algorithm - private ExpiringCache javaHomePrefixCache = new ExpiringCache(); + private final ExpiringCache javaHomePrefixCache; public String canonicalize(String path) throws IOException { if (!useCanonCaches) { @@ -158,7 +160,7 @@ public String canonicalize(String path) throws IOException { String res = cache.get(path); if (res == null) { String dir = null; - String resDir = null; + String resDir; if (useCanonPrefixCache) { // Note that this can cause symlinks that should // be resolved to a destination directory to be @@ -266,8 +268,12 @@ public boolean delete(File f) { // (i.e., only remove/update affected entries) but probably // not worth it since these entries expire after 30 seconds // anyway. - cache.clear(); - javaHomePrefixCache.clear(); + if (useCanonCaches) { + cache.clear(); + } + if (useCanonPrefixCache) { + javaHomePrefixCache.clear(); + } return delete0(f); } private native boolean delete0(File f); @@ -279,8 +285,12 @@ public boolean rename(File f1, File f2) { // (i.e., only remove/update affected entries) but probably // not worth it since these entries expire after 30 seconds // anyway. - cache.clear(); - javaHomePrefixCache.clear(); + if (useCanonCaches) { + cache.clear(); + } + if (useCanonPrefixCache) { + javaHomePrefixCache.clear(); + } return rename0(f1, f2); } private native boolean rename0(File f1, File f2); diff --git a/src/java.base/windows/classes/java/io/WinNTFileSystem.java b/src/java.base/windows/classes/java/io/WinNTFileSystem.java index 94cac268ceb..c97d8dcda6b 100644 --- a/src/java.base/windows/classes/java/io/WinNTFileSystem.java +++ b/src/java.base/windows/classes/java/io/WinNTFileSystem.java @@ -51,6 +51,8 @@ public WinNTFileSystem() { semicolon = props.getProperty("path.separator").charAt(0); altSlash = (this.slash == '\\') ? '/' : '\\'; userDir = normalize(props.getProperty("user.dir")); + cache = useCanonCaches ? new ExpiringCache() : null; + prefixCache = useCanonPrefixCache ? new ExpiringCache() : null; } private boolean isSlash(char c) { @@ -387,8 +389,8 @@ private String getDriveDirectory(char drive) { // same directory, and must not create results differing from the true // canonicalization algorithm in canonicalize_md.c. For this reason the // prefix cache is conservative and is not used for complex path names. - private ExpiringCache cache = new ExpiringCache(); - private ExpiringCache prefixCache = new ExpiringCache(); + private final ExpiringCache cache; + private final ExpiringCache prefixCache; @Override public String canonicalize(String path) throws IOException { @@ -568,8 +570,12 @@ public boolean delete(File f) { // (i.e., only remove/update affected entries) but probably // not worth it since these entries expire after 30 seconds // anyway. - cache.clear(); - prefixCache.clear(); + if (useCanonCaches) { + cache.clear(); + } + if (useCanonPrefixCache) { + prefixCache.clear(); + } return delete0(f); } @@ -582,8 +588,12 @@ public boolean rename(File f1, File f2) { // (i.e., only remove/update affected entries) but probably // not worth it since these entries expire after 30 seconds // anyway. - cache.clear(); - prefixCache.clear(); + if (useCanonCaches) { + cache.clear(); + } + if (useCanonPrefixCache) { + prefixCache.clear(); + } return rename0(f1, f2); } diff --git a/src/java.security.jgss/share/classes/sun/security/jgss/spnego/SpNegoContext.java b/src/java.security.jgss/share/classes/sun/security/jgss/spnego/SpNegoContext.java index 3e25487d7c1..d32e49a46b3 100644 --- a/src/java.security.jgss/share/classes/sun/security/jgss/spnego/SpNegoContext.java +++ b/src/java.security.jgss/share/classes/sun/security/jgss/spnego/SpNegoContext.java @@ -583,7 +583,8 @@ public final byte[] acceptSecContext(InputStream is, int mechTokenSize) } } else { negoResult = SpNegoToken.NegoResult.REJECT; - state = STATE_DONE; + state = STATE_DELETED; + throw new GSSException(GSSException.FAILURE); } if (DEBUG) { @@ -642,7 +643,8 @@ public final byte[] acceptSecContext(InputStream is, int mechTokenSize) } } else { negoResult = SpNegoToken.NegoResult.REJECT; - state = STATE_DONE; + state = STATE_DELETED; + throw new GSSException(GSSException.FAILURE); } // generate SPNEGO token diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java index 6e628fbaa5d..3e2a554d49b 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java @@ -1634,6 +1634,8 @@ protected boolean scanCDATASection(XMLStringBuffer contentBuffer, boolean comple } } else { //CData partially returned due to the size limit + fInCData = true; + fCDataEnd = false; break; } //by this time we have also read surrogate contents if any... @@ -2928,7 +2930,11 @@ else if (c != -1 && isInvalidLiteral(c)) { fUsebuffer = true; //CDATA section is read up to the chunk size limit scanCDATASection(fContentBuffer , true); - setScannerState(SCANNER_STATE_CONTENT); + if (!fCDataEnd) { + setScannerState(SCANNER_STATE_CDATA); + } else { + setScannerState(SCANNER_STATE_CONTENT); + } //1. if fIsCoalesce is set to true we set the variable fLastSectionWasCData to true //and just call fDispatche.next(). Since we have set the scanner state to //SCANNER_STATE_CONTENT (super state) parser will automatically recover and @@ -2941,9 +2947,6 @@ else if (c != -1 && isInvalidLiteral(c)) { //there might be more data to coalesce. continue; } else if(fReportCdataEvent) { - if (!fCDataEnd) { - setScannerState(SCANNER_STATE_CDATA); - } return XMLEvent.CDATA; } else { return XMLEvent.CHARACTERS; diff --git a/src/java.xml/share/classes/javax/xml/validation/Validator.java b/src/java.xml/share/classes/javax/xml/validation/Validator.java index 5e1999c0f81..a79955de9b5 100644 --- a/src/java.xml/share/classes/javax/xml/validation/Validator.java +++ b/src/java.xml/share/classes/javax/xml/validation/Validator.java @@ -214,7 +214,7 @@ public void validate(Source source) * * @throws IllegalArgumentException * If the {@code Result} type doesn't match the - * {@code Source} type of if the {@code Source} + * {@code Source} type or if the {@code Source} * is an XML artifact that the implementation cannot * validate (for example, a processing instruction). * @throws SAXException diff --git a/test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp b/test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp new file mode 100644 index 00000000000..f01a55b3cca --- /dev/null +++ b/test/hotspot/gtest/utilities/test_singleWriterSynchronizer.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 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. + * + * 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/interfaceSupport.inline.hpp" +#include "runtime/orderAccess.hpp" +#include "runtime/os.hpp" +#include "runtime/thread.hpp" +#include "utilities/debug.hpp" +#include "utilities/globalCounter.inline.hpp" +#include "utilities/globalDefinitions.hpp" +#include "utilities/ostream.hpp" +#include "utilities/singleWriterSynchronizer.hpp" +#include "threadHelper.inline.hpp" +#include "unittest.hpp" + +class SingleWriterSynchronizerTestReader : public JavaTestThread { + SingleWriterSynchronizer* _synchronizer; + volatile uintx* _synchronized_value; + volatile int* _continue_running; + + static const uint reader_iterations = 10; + +public: + SingleWriterSynchronizerTestReader(Semaphore* post, + SingleWriterSynchronizer* synchronizer, + volatile uintx* synchronized_value, + volatile int* continue_running) : + JavaTestThread(post), + _synchronizer(synchronizer), + _synchronized_value(synchronized_value), + _continue_running(continue_running) + {} + + virtual void main_run() { + uintx iterations = 0; + while (OrderAccess::load_acquire(_continue_running) != 0) { + ++iterations; + SingleWriterSynchronizer::CriticalSection cs(_synchronizer); + uintx value = OrderAccess::load_acquire(_synchronized_value); + for (uint i = 0; i < reader_iterations; ++i) { + uintx new_value = OrderAccess::load_acquire(_synchronized_value); + // A reader can see either the value it first read after + // entering the critical section, or that value + 1. No other + // values are possible. + if (value != new_value) { + ASSERT_EQ((value + 1), new_value); + } + } + } + tty->print_cr("reader iterations: " UINTX_FORMAT, iterations); + } +}; + +class SingleWriterSynchronizerTestWriter : public JavaTestThread { + SingleWriterSynchronizer* _synchronizer; + volatile uintx* _synchronized_value; + volatile int* _continue_running; + +public: + SingleWriterSynchronizerTestWriter(Semaphore* post, + SingleWriterSynchronizer* synchronizer, + volatile uintx* synchronized_value, + volatile int* continue_running) : + JavaTestThread(post), + _synchronizer(synchronizer), + _synchronized_value(synchronized_value), + _continue_running(continue_running) + {} + + virtual void main_run() { + while (OrderAccess::load_acquire(_continue_running) != 0) { + ++*_synchronized_value; + _synchronizer->synchronize(); + } + tty->print_cr("writer iterations: " UINTX_FORMAT, *_synchronized_value); + } +}; + +const uint nreaders = 5; +const uint milliseconds_to_run = 3000; + +TEST_VM(TestSingleWriterSynchronizer, stress) { + Semaphore post; + SingleWriterSynchronizer synchronizer; + volatile uintx synchronized_value = 0; + volatile int continue_running = 1; + + JavaTestThread* readers[nreaders] = {}; + for (uint i = 0; i < nreaders; ++i) { + readers[i] = new SingleWriterSynchronizerTestReader(&post, + &synchronizer, + &synchronized_value, + &continue_running); + readers[i]->doit(); + } + + JavaTestThread* writer = + new SingleWriterSynchronizerTestWriter(&post, + &synchronizer, + &synchronized_value, + &continue_running); + + writer->doit(); + + tty->print_cr("Stressing synchronizer for %u ms", milliseconds_to_run); + { + ThreadInVMfromNative invm(JavaThread::current()); + os::sleep(Thread::current(), milliseconds_to_run, true); + } + continue_running = 0; + for (uint i = 0; i < nreaders + 1; ++i) { + post.wait(); + } +} diff --git a/test/hotspot/jtreg/ProblemList-graal.txt b/test/hotspot/jtreg/ProblemList-graal.txt index c0c2e9045e9..ba2bc25d515 100644 --- a/test/hotspot/jtreg/ProblemList-graal.txt +++ b/test/hotspot/jtreg/ProblemList-graal.txt @@ -136,8 +136,6 @@ vmTestbase/nsk/jvmti/PopFrame/popframe009/TestDescription.java vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn001/TestDescription.java 8195674 generic-all vmTestbase/nsk/jvmti/ForceEarlyReturn/ForceEarlyReturn002/TestDescription.java 8195674 generic-all -vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/TestDescription.java 8202342 generic-all - runtime/appcds/cacheObject/RedefineClassTest.java 8204506 macosx-all vmTestbase/nsk/jvmti/scenarios/hotswap/HS102/hs102t001/TestDescription.java 8204506 macosx-all vmTestbase/nsk/jvmti/scenarios/hotswap/HS102/hs102t002/TestDescription.java 8204506 macosx-all diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 5edc5cd515c..f90dc8c1efe 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -83,6 +83,7 @@ runtime/appcds/javaldr/GCDuringDump.java 8208778 macosx-x64 runtime/CompressedOops/UseCompressedOops.java 8079353 generic-all runtime/RedefineTests/RedefineRunningMethods.java 8208778 macosx-x64 runtime/SharedArchiveFile/SASymbolTableTest.java 8193639 solaris-all +runtime/MemberName/MemberNameLeak.java 8209844 generic-all ############################################################################# @@ -179,7 +180,6 @@ vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted001/TestDescription.java 7013 vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted003/TestDescription.java 6606767 generic-all vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted004/TestDescription.java 7013634,6606767 generic-all vmTestbase/nsk/jvmti/ThreadStart/threadstart001/TestDescription.java 8016181 generic-all -vmTestbase/nsk/jvmti/ThreadStart/threadstart003/TestDescription.java 8034084 generic-all vmTestbase/nsk/jvmti/scenarios/extension/EX03/ex03t001/TestDescription.java 8173658 generic-all vmTestbase/nsk/jvmti/scenarios/hotswap/HS102/hs102t002/TestDescription.java 8204506,8203350 generic-all vmTestbase/nsk/jvmti/scenarios/hotswap/HS204/hs204t001/hs204t001.java 6813266 generic-all diff --git a/test/hotspot/jtreg/compiler/intrinsics/object/TestClone.java b/test/hotspot/jtreg/compiler/intrinsics/object/TestClone.java index e239f55d597..98cc9a93ff1 100644 --- a/test/hotspot/jtreg/compiler/intrinsics/object/TestClone.java +++ b/test/hotspot/jtreg/compiler/intrinsics/object/TestClone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -29,7 +29,7 @@ * @library /test/lib * * @run main/othervm -XX:-TieredCompilation -Xbatch - * -XX:CompileCommand=compileonly,compiler.intrinsics.object.TestClone::f + * -XX:CompileCommand=compileonly,compiler.intrinsics.object.TestClone::test* * compiler.intrinsics.object.TestClone */ @@ -37,6 +37,43 @@ import jdk.test.lib.Asserts; +abstract class MyAbstract { + + public Object myClone1() throws CloneNotSupportedException { + return this.clone(); + } + + public Object myClone2() throws CloneNotSupportedException { + return this.clone(); + } + + public Object myClone3() throws CloneNotSupportedException { + return this.clone(); + } +} + +class MyClass1 extends MyAbstract { + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} + +class MyClass2 extends MyAbstract { + +} + +class MyClass3 extends MyAbstract implements Cloneable { + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} + +class MyClass4 extends MyAbstract implements Cloneable { + +} + public class TestClone implements Cloneable { static class A extends TestClone {} static class B extends TestClone { @@ -56,29 +93,70 @@ public D clone() { } static TestClone a = new A(), b = new B(), c = new C(), d = new D(); - public static Object f(TestClone o) throws CloneNotSupportedException { + public static Object test1(TestClone o) throws CloneNotSupportedException { // Polymorphic call site: >90% Object::clone / <10% other methods return o.clone(); } + public static void test2(MyAbstract obj, boolean shouldThrow) throws Exception { + try { + obj.myClone1(); + } catch (Exception e) { + return; // Expected + } + Asserts.assertFalse(shouldThrow, "No exception thrown"); + } + + public static void test3(MyAbstract obj, boolean shouldThrow) throws Exception { + try { + obj.myClone2(); + } catch (Exception e) { + return; // Expected + } + Asserts.assertFalse(shouldThrow, "No exception thrown"); + } + + public static void test4(MyAbstract obj, boolean shouldThrow) throws Exception { + try { + obj.myClone3(); + } catch (Exception e) { + return; // Expected + } + Asserts.assertFalse(shouldThrow, "No exception thrown"); + } + public static void main(String[] args) throws Exception { TestClone[] params1 = {a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, b, c, d}; + MyClass1 obj1 = new MyClass1(); + MyClass2 obj2 = new MyClass2(); + MyClass3 obj3 = new MyClass3(); + MyClass4 obj4 = new MyClass4(); + for (int i = 0; i < 15000; i++) { - f(params1[i % params1.length]); + test1(params1[i % params1.length]); + + test2(obj1, true); + test2(obj2, true); + + test3(obj3, false); + test3(obj2, true); + + test4(obj3, false); + test4(obj4, false); } - Asserts.assertTrue(f(a) != a); - Asserts.assertTrue(f(b) == b); - Asserts.assertTrue(f(c) == c); - Asserts.assertTrue(f(d) == d); + Asserts.assertTrue(test1(a) != a); + Asserts.assertTrue(test1(b) == b); + Asserts.assertTrue(test1(c) == c); + Asserts.assertTrue(test1(d) == d); try { - f(null); - throw new AssertionError(""); + test1(null); + throw new AssertionError("No exception thrown"); } catch (NullPointerException e) { /* expected */ } System.out.println("TEST PASSED"); diff --git a/test/hotspot/jtreg/runtime/BootstrapMethod/TestLambdaExceptionInInitializer.java b/test/hotspot/jtreg/runtime/BootstrapMethod/TestLambdaExceptionInInitializer.java new file mode 100644 index 00000000000..7c92f90034b --- /dev/null +++ b/test/hotspot/jtreg/runtime/BootstrapMethod/TestLambdaExceptionInInitializer.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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. + * + * 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 8208172 + * @library /test/lib + * @compile TestPkg/LambdaMetafactory.java + * @compile TestPkg/Lambda.jasm + * @run main TestLambdaExceptionInInitializer + */ + +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class TestLambdaExceptionInInitializer { + public static void main(String args[]) throws Throwable { + + // Run Lamba class + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("TestPkg.Lambda"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + output.shouldContain("Exception in thread \"main\" java.lang.ExceptionInInitializerError"); + + output.shouldContain("Caused by: java.lang.NullPointerException"); + output.shouldContain("at TestPkg.LambdaMetafactory.throwNpe(LambdaMetafactory.java:34)"); + output.shouldContain("at TestPkg.LambdaMetafactory.(LambdaMetafactory.java:30)"); + output.shouldHaveExitValue(1); + } +} diff --git a/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/Lambda.jasm b/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/Lambda.jasm new file mode 100644 index 00000000000..1fdc36746b8 --- /dev/null +++ b/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/Lambda.jasm @@ -0,0 +1,66 @@ +/* + * Copyright (c) 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. + * + * 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. + */ + +// Generated file to call Metafactory that gets NPE in initializer while +// calling the bootstrap method. + +package TestPkg; + +super public final class Lambda + version 52:0 +{ + + +public Method "":"()V" + stack 1 locals 1 +{ + aload_0; + invokespecial Method java/lang/Object."":"()V"; + return; +} + +public Method test:"()V" + stack 1 locals 2 +{ + invokedynamic InvokeDynamic REF_invokeStatic:LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":run:"()Ljava/lang/Runnable;" MethodType "()V", MethodHandle REF_invokeStatic:Lambda.lambda$test$0:"()V", MethodType "()V"; + astore_1; + return; +} + +private static synthetic Method lambda$test$0:"()V" + stack 0 locals 0 +{ + return; +} + +public static Method main:"([Ljava/lang/String;)V" + stack 2 locals 1 +{ + new class Lambda; + dup; + invokespecial Method "":"()V"; + invokevirtual Method test:"()V"; + return; +} + +} // end Class Lambda diff --git a/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/LambdaMetafactory.java b/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/LambdaMetafactory.java new file mode 100644 index 00000000000..0b71aae0658 --- /dev/null +++ b/test/hotspot/jtreg/runtime/BootstrapMethod/TestPkg/LambdaMetafactory.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 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. + * + * 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 TestPkg; + +import java.lang.invoke.LambdaConversionException; + +public class LambdaMetafactory { + static { + throwNpe(); // ExceptionInInitializerError + } + + static void throwNpe(){ + throw new NullPointerException(); + } + + public static java.lang.invoke.CallSite metafactory(java.lang.invoke.MethodHandles.Lookup owner, + String invokedName, + java.lang.invoke.MethodType invokedType, + java.lang.invoke.MethodType samMethodType, + java.lang.invoke.MethodHandle implMethod, + java.lang.invoke.MethodType instantiatedMethodType) + throws LambdaConversionException { + return java.lang.invoke.LambdaMetafactory.metafactory(owner, + invokedName, + invokedType, + samMethodType, + implMethod, + instantiatedMethodType); + } +} diff --git a/test/hotspot/jtreg/runtime/appcds/HelloExtTest.java b/test/hotspot/jtreg/runtime/appcds/HelloExtTest.java index 489dabd0231..e4504b5d073 100644 --- a/test/hotspot/jtreg/runtime/appcds/HelloExtTest.java +++ b/test/hotspot/jtreg/runtime/appcds/HelloExtTest.java @@ -52,7 +52,7 @@ public static void main(String[] args) throws Exception { TestCommon.dump(appJar, TestCommon.list("javax/annotation/processing/FilerException", "[Ljava/lang/Comparable;"), - bootClassPath, "-verbose:class"); + bootClassPath); String prefix = ".class.load. "; String class_pattern = ".*LambdaForm[$]MH[/][0123456789].*"; @@ -60,12 +60,12 @@ public static void main(String[] args) throws Exception { String pattern = prefix + class_pattern + suffix; TestCommon.run("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-cp", appJar, bootClassPath, "-verbose:class", "HelloExt") + "-cp", appJar, bootClassPath, "-Xlog:class+load", "HelloExt") .assertNormalExit(output -> output.shouldNotMatch(pattern)); TestCommon.run("-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-cp", appJar, bootClassPath, "-verbose:class", + "-cp", appJar, bootClassPath, "-Xlog:class+load", "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", "HelloExt") .assertNormalExit(output -> output.shouldNotMatch(class_pattern)); diff --git a/test/hotspot/jtreg/runtime/appcds/OldClassTest.java b/test/hotspot/jtreg/runtime/appcds/OldClassTest.java index bb1b0e25112..23ebf837acf 100644 --- a/test/hotspot/jtreg/runtime/appcds/OldClassTest.java +++ b/test/hotspot/jtreg/runtime/appcds/OldClassTest.java @@ -67,7 +67,6 @@ public static void main(String[] args) throws Exception { TestCommon.run( "-cp", jar, - "-verbose:class", "Hello") .assertNormalExit("Hello Unicode world (Old)"); @@ -79,7 +78,6 @@ public static void main(String[] args) throws Exception { TestCommon.run( "-cp", classpath, - "-verbose:class", "Hello") .assertNormalExit("Hello Unicode world (Old)"); } diff --git a/test/hotspot/jtreg/runtime/appcds/ProhibitedPackage.java b/test/hotspot/jtreg/runtime/appcds/ProhibitedPackage.java index 861bb36a158..9e5553ae573 100644 --- a/test/hotspot/jtreg/runtime/appcds/ProhibitedPackage.java +++ b/test/hotspot/jtreg/runtime/appcds/ProhibitedPackage.java @@ -79,20 +79,20 @@ public static void main(String[] args) throws Exception { // -Xshare:on TestCommon.run( "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-cp", appJar, "-Xlog:class+load=info", "ProhibitedHelper") + "-cp", appJar, "ProhibitedHelper") .assertNormalExit("Prohibited package name: java.lang"); // -Xshare:auto output = TestCommon.execAuto( "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-cp", appJar, "-Xlog:class+load=info", "ProhibitedHelper"); + "-cp", appJar, "ProhibitedHelper"); CDSOptions opts = (new CDSOptions()).setXShareMode("auto"); TestCommon.checkExec(output, opts, "Prohibited package name: java.lang"); // -Xshare:off output = TestCommon.execOff( "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-cp", appJar, "-Xlog:class+load=info", "ProhibitedHelper"); + "-cp", appJar, "ProhibitedHelper"); output.shouldContain("Prohibited package name: java.lang"); } } diff --git a/test/hotspot/jtreg/runtime/appcds/ProtectionDomain.java b/test/hotspot/jtreg/runtime/appcds/ProtectionDomain.java index 5ba0cf31451..3c3c692750d 100644 --- a/test/hotspot/jtreg/runtime/appcds/ProtectionDomain.java +++ b/test/hotspot/jtreg/runtime/appcds/ProtectionDomain.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -57,16 +57,16 @@ public static void main(String[] args) throws Exception { OutputAnalyzer output; // First class is loaded from CDS, second class is loaded from JAR - output = TestCommon.exec(appJar, "-verbose:class", "ProtDomain"); + output = TestCommon.exec(appJar, "ProtDomain"); TestCommon.checkExec(output, "Protection Domains match"); // First class is loaded from JAR, second class is loaded from CDS - output = TestCommon.exec(appJar, "-verbose:class", "ProtDomainB"); + output = TestCommon.exec(appJar, "ProtDomainB"); TestCommon.checkExec(output, "Protection Domains match"); // Test ProtectionDomain for application and extension module classes from the // "modules" jimage - output = TestCommon.exec(appJar, "-verbose:class", "JimageClassProtDomain"); + output = TestCommon.exec(appJar, "JimageClassProtDomain"); output.shouldNotContain("Failed: Protection Domains do not match"); } } diff --git a/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java b/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java index af452fee325..add30dae3ac 100644 --- a/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java +++ b/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -62,11 +62,11 @@ public class SharedArchiveConsistency { public static WhiteBox wb; public static int offset_magic; // FileMapHeader::_magic - public static int sp_offset_crc; // FileMapHeader::space_info::_crc + public static int sp_offset_crc; // CDSFileMapRegion::_crc public static int file_header_size = -1;// total size of header, variant, need calculation - public static int space_info_size; // size of space_info - public static int sp_offset; // offset of FileMapHeader::space_info - public static int sp_used_offset; // offset of space_info::_used + public static int CDSFileMapRegion_size; // size of CDSFileMapRegion + public static int sp_offset; // offset of CDSFileMapRegion + public static int sp_used_offset; // offset of CDSFileMapRegion::_used public static int size_t_size; // size of size_t public static File jsa; // will be updated during test @@ -83,7 +83,7 @@ public class SharedArchiveConsistency { public static void getFileOffsetInfo() throws Exception { wb = WhiteBox.getWhiteBox(); offset_magic = wb.getOffsetForName("FileMapHeader::_magic"); - sp_offset_crc = wb.getOffsetForName("space_info::_crc"); + sp_offset_crc = wb.getOffsetForName("CDSFileMapRegion::_crc"); try { int nonExistOffset = wb.getOffsetForName("FileMapHeader::_non_exist_offset"); System.exit(-1); // should fail @@ -92,9 +92,9 @@ public static void getFileOffsetInfo() throws Exception { } sp_offset = wb.getOffsetForName("FileMapHeader::_space[0]") - offset_magic; - sp_used_offset = wb.getOffsetForName("space_info::_used") - sp_offset_crc; + sp_used_offset = wb.getOffsetForName("CDSFileMapRegion::_used") - sp_offset_crc; size_t_size = wb.getOffsetForName("size_t_size"); - space_info_size = wb.getOffsetForName("space_info_size"); + CDSFileMapRegion_size = wb.getOffsetForName("CDSFileMapRegion_size"); } public static int getFileHeaderSize(FileChannel fc) throws Exception { @@ -166,7 +166,7 @@ public static void modifyJsaContentRandomly() throws Exception { System.out.printf("%-12s%-12s%-12s%-12s%-12s\n", "Space Name", "Offset", "Used bytes", "Reg Start", "Random Offset"); start0 = getFileHeaderSize(fc); for (int i = 0; i < num_regions; i++) { - used_offset = sp_offset + space_info_size * i + sp_used_offset; + used_offset = sp_offset + CDSFileMapRegion_size * i + sp_used_offset; // read 'used' used[i] = readInt(fc, used_offset, size_t_size); start = start0; @@ -199,7 +199,7 @@ public static void modifyJsaContent() throws Exception { long[] used = new long[num_regions]; System.out.printf("%-12s%-12s\n", "Space name", "Used bytes"); for (int i = 0; i < num_regions; i++) { - used_offset = sp_offset + space_info_size* i + sp_used_offset; + used_offset = sp_offset + CDSFileMapRegion_size* i + sp_used_offset; // read 'used' used[i] = readInt(fc, used_offset, size_t_size); System.out.printf("%-12s%-12d\n", shared_region_name[i], used[i]); diff --git a/test/hotspot/jtreg/runtime/appcds/cacheObject/DifferentHeapSizes.java b/test/hotspot/jtreg/runtime/appcds/cacheObject/DifferentHeapSizes.java new file mode 100644 index 00000000000..d00f4544ced --- /dev/null +++ b/test/hotspot/jtreg/runtime/appcds/cacheObject/DifferentHeapSizes.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 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. + * + * 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 + * @summary Test automatic relocation of archive heap regions dur to heap size changes. + * @requires vm.cds.archived.java.heap + * @requires (vm.gc=="null") + * @library /test/lib /test/hotspot/jtreg/runtime/appcds + * @modules jdk.jartool/sun.tools.jar + * @compile ../test-classes/Hello.java + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. DifferentHeapSizes + */ + +import jdk.test.lib.process.OutputAnalyzer; +import sun.hotspot.WhiteBox; +import jdk.test.lib.cds.CDSTestUtils; + +public class DifferentHeapSizes { + static class Scenario { + int dumpSize; // in MB + int runSizes[]; // in MB + Scenario(int ds, int... rs) { + dumpSize = ds; + runSizes = rs; + } + } + + static Scenario[] scenarios = { + // dump -Xmx , run -Xmx + new Scenario( 32, 32, 64, 512, 2048, 4097, 16374, 31000), + new Scenario( 128, 32, 64, 512, 2048, 4097, 16374, 31000, 40000), + new Scenario( 2048, 32, 512, 2600, 4097, 8500, 31000, 40000), + new Scenario( 17000, 32, 512, 2048, 4097, 8500, 31000, 40000), + new Scenario( 31000, 32, 512, 2048, 4097, 8500, 17000, 40000) + }; + + public static void main(String[] args) throws Exception { + String dedup = "-XX:+UseStringDeduplication"; // This increases code coverage. + JarBuilder.getOrCreateHelloJar(); + String appJar = TestCommon.getTestJar("hello.jar"); + String appClasses[] = TestCommon.list("Hello"); + + for (Scenario s : scenarios) { + String dumpXmx = "-Xmx" + s.dumpSize + "m"; + OutputAnalyzer output = TestCommon.dump(appJar, appClasses, dumpXmx); + + for (int runSize : s.runSizes) { + String runXmx = "-Xmx" + runSize + "m"; + CDSTestUtils.Result result = TestCommon.run("-cp", appJar, "-showversion", + "-Xlog:cds", runXmx, dedup, "Hello"); + if (runSize < 32768) { + result + .assertNormalExit("Hello World") + .assertNormalExit(out -> { + out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP); + out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE); + }); + } else { + result.assertAbnormalExit("Unable to use shared archive: UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); + } + } + } + String flag = "HeapBaseMinAddress"; + String xxflag = "-XX:" + flag + "="; + String mx = "-Xmx128m"; + long base = WhiteBox.getWhiteBox().getSizeTVMFlag(flag).longValue(); + + TestCommon.dump(appJar, appClasses, mx, xxflag + base); + TestCommon.run("-cp", appJar, "-showversion", "-Xlog:cds", mx, xxflag + (base + 256 * 1024 * 1024), dedup, "Hello") + .assertNormalExit("Hello World") + .assertNormalExit(out -> { + out.shouldNotContain(CDSTestUtils.MSG_RANGE_NOT_WITHIN_HEAP); + out.shouldNotContain(CDSTestUtils.MSG_RANGE_ALREADT_IN_USE); + }); + } +} diff --git a/test/hotspot/jtreg/runtime/appcds/cacheObject/RangeNotWithinHeap.java b/test/hotspot/jtreg/runtime/appcds/cacheObject/RangeNotWithinHeap.java deleted file mode 100644 index 23603ab0478..00000000000 --- a/test/hotspot/jtreg/runtime/appcds/cacheObject/RangeNotWithinHeap.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2017, 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. - * - * 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 - * @summary Shared classes can still be used when archived heap regions cannot be - * mapped due to out of range, and -Xshare:on should not fail. Test on - * linux 64-bit only since the HeapBaseMinAddress value is platform specific. - * The value used in the test may cause different behavior on other platforms. - * @requires vm.cds.archived.java.heap - * @requires os.family == "linux" - * @library /test/lib /test/hotspot/jtreg/runtime/appcds - * @modules java.base/jdk.internal.misc - * @modules java.management - * jdk.jartool/sun.tools.jar - * @compile ../test-classes/Hello.java - * @run main RangeNotWithinHeap - */ - -import jdk.test.lib.process.OutputAnalyzer; - -public class RangeNotWithinHeap { - public static void main(String[] args) throws Exception { - JarBuilder.getOrCreateHelloJar(); - String appJar = TestCommon.getTestJar("hello.jar"); - String appClasses[] = TestCommon.list("Hello"); - - OutputAnalyzer output = TestCommon.dump(appJar, appClasses, - "-XX:HeapBaseMinAddress=0x600000000", "-Xmx6G", "-Xlog:gc+heap=trace"); - TestCommon.checkDump(output, "oa0 space:"); - - // Force archive region out of runtime java heap - output = TestCommon.exec(appJar, "Hello"); - TestCommon.checkExec(output, "Hello World"); - output = TestCommon.exec(appJar, - "-XX:HeapBaseMinAddress=0x600000000", "-Xmx2G", "-Xlog:gc+heap=trace,cds", "Hello"); - TestCommon.checkExec(output, "Hello World"); - try { - output.shouldContain( - "UseSharedSpaces: Unable to allocate region, range is not within java heap."); - } catch (Exception e) { - // In rare case the heap data is not used. - if (output.getOutput().contains("Cached heap data from the CDS archive is being ignored")) { - return; - } - // Check for common shared class data mapping failures. - TestCommon.checkCommonExecExceptions(output, e); - } - } -} diff --git a/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java b/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java index 5349543166c..18497db68e1 100644 --- a/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java +++ b/test/hotspot/jtreg/runtime/appcds/cacheObject/RedefineClassTest.java @@ -34,7 +34,7 @@ * RedefineClassApp * InstrumentationClassFileTransformer * InstrumentationRegisterClassFileTransformer - * @run main/othervm RedefineClassTest + * @run main RedefineClassTest */ import com.sun.tools.attach.VirtualMachine; @@ -89,7 +89,7 @@ public static void runTest() throws Throwable { bootCP, "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", - "-Xlog:gc+region=trace,cds=info", + "-Xlog:cds=info", agentCmdArg, "RedefineClassApp", bootJar, appJar); out.reportDiagnosticSummary(); diff --git a/test/hotspot/jtreg/runtime/appcds/javaldr/ArrayTest.java b/test/hotspot/jtreg/runtime/appcds/javaldr/ArrayTest.java index 21094c82747..3d692993d98 100644 --- a/test/hotspot/jtreg/runtime/appcds/javaldr/ArrayTest.java +++ b/test/hotspot/jtreg/runtime/appcds/javaldr/ArrayTest.java @@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception { String bootClassPath = "-Xbootclasspath/a:" + whiteBoxJar; // create an archive containing array classes - OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list(arrayClasses), bootClassPath, "-verbose:class"); + OutputAnalyzer output = TestCommon.dump(appJar, TestCommon.list(arrayClasses), bootClassPath); // we currently don't support array classes during CDS dump output.shouldContain("Preload Warning: Cannot find [Ljava/lang/Comparable;") .shouldContain("Preload Warning: Cannot find [I") @@ -70,7 +70,6 @@ public static void main(String[] args) throws Exception { argsList.add("-cp"); argsList.add(appJar); argsList.add(bootClassPath); - argsList.add("-verbose:class"); argsList.add("ArrayTestHelper"); // the following are input args to the ArrayTestHelper. // skip checking array classes during run time diff --git a/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDump.java b/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDump.java index 763c7384cdc..ca2c2dec077 100644 --- a/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDump.java +++ b/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDump.java @@ -56,7 +56,8 @@ public static void main(String[] args) throws Throwable { String appJar = ClassFileInstaller.writeJar("GCDuringDumpApp.jar", appClasses); - String gcLog = "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug"; + String gcLog = Boolean.getBoolean("test.cds.verbose.gc") ? + "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug" : "-showversion"; for (int i=0; i<2; i++) { // i = 0 -- run without agent = no extra GCs diff --git a/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDumpTransformer.java b/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDumpTransformer.java index bbde62429c4..505524ebe91 100644 --- a/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDumpTransformer.java +++ b/test/hotspot/jtreg/runtime/appcds/javaldr/GCDuringDumpTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -28,13 +28,8 @@ import java.security.ProtectionDomain; public class GCDuringDumpTransformer implements ClassFileTransformer { - static int n = 0; public byte[] transform(ClassLoader loader, String name, Class classBeingRedefined, ProtectionDomain pd, byte[] buffer) throws IllegalClassFormatException { - n++; - - System.out.println("dump time loading: " + name + " in loader: " + loader); - System.out.println("making garbage: " + n); try { makeGarbage(); } catch (Throwable t) { @@ -43,7 +38,6 @@ public byte[] transform(ClassLoader loader, String name, Class classBeingRede Thread.sleep(200); // let GC to have a chance to run } catch (Throwable t2) {} } - System.out.println("making garbage: done"); return null; } diff --git a/test/hotspot/jtreg/runtime/appcds/javaldr/GCSharedStringsDuringDump.java b/test/hotspot/jtreg/runtime/appcds/javaldr/GCSharedStringsDuringDump.java index d3c28441d74..9b893680749 100644 --- a/test/hotspot/jtreg/runtime/appcds/javaldr/GCSharedStringsDuringDump.java +++ b/test/hotspot/jtreg/runtime/appcds/javaldr/GCSharedStringsDuringDump.java @@ -62,7 +62,8 @@ public static void main(String[] args) throws Throwable { String appJar = ClassFileInstaller.writeJar("GCSharedStringsDuringDumpApp.jar", appClasses); - String gcLog = "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug"; + String gcLog = Boolean.getBoolean("test.cds.verbose.gc") ? + "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug" : "-showversion"; String sharedArchiveCfgFile = System.getProperty("user.dir") + File.separator + "GCSharedStringDuringDump_gen.txt"; diff --git a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/AddOpens.java b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/AddOpens.java index 33f756fd011..8ac55234186 100644 --- a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/AddOpens.java +++ b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/AddOpens.java @@ -87,7 +87,6 @@ public static void main(String... args) throws Exception { // the class in the modular jar in the -cp won't be archived. OutputAnalyzer output = TestCommon.createArchive( destJar.toString(), appClasses, - "-Xlog:class+load=trace", "--module-path", moduleDir.toString(), "-m", TEST_MODULE1); TestCommon.checkDump(output); diff --git a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ExportModule.java b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ExportModule.java index 2cc653e1eca..2ceb64dc8df 100644 --- a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ExportModule.java +++ b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/ExportModule.java @@ -118,7 +118,6 @@ public static void main(String... args) throws Exception { // the module in the --module-path OutputAnalyzer output = TestCommon.createArchive( appJar.toString(), appClasses, - "-Xlog:class+load=trace", "--module-path", moduleDir.toString(), "--add-modules", TEST_MODULE2, MAIN_CLASS); TestCommon.checkDump(output); @@ -142,7 +141,6 @@ public static void main(String... args) throws Exception { // unnmaed. output = TestCommon.createArchive( appJar2.toString(), appClasses2, - "-Xlog:class+load=trace", "--module-path", moduleDir.toString(), "--add-modules", TEST_MODULE2, "--add-exports", "org.astro/org.astro=ALL-UNNAMED", diff --git a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java index 87e1993268a..9a9b21d5d80 100644 --- a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java +++ b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/JvmtiAddPath.java @@ -113,7 +113,6 @@ public static void main(String[] args) throws Exception { appJar, TestCommon.list("JvmtiApp", "ExtraClass", MAIN_CLASS), use_whitebox_jar, - "-Xlog:class+load=trace", modulePath); TestCommon.checkDump(output); @@ -143,7 +142,6 @@ public static void main(String[] args) throws Exception { output = TestCommon.createArchive( appJar, TestCommon.list("JvmtiApp", "ExtraClass"), use_whitebox_jar, - "-Xlog:class+load=trace", modulePath); TestCommon.checkDump(output); run(twoAppJars, modulePath, diff --git a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java index 86c6ece1be2..eb10af62796 100644 --- a/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java +++ b/test/hotspot/jtreg/runtime/appcds/jigsaw/modulepath/MainModuleOnly.java @@ -90,7 +90,6 @@ public static void main(String... args) throws Exception { // the class in the modular jar in the -cp won't be archived. OutputAnalyzer output = TestCommon.createArchive( destJar.toString(), appClasses, - "-Xlog:class+load=trace", "--module-path", moduleDir.toString(), "-m", TEST_MODULE1); TestCommon.checkDump(output); @@ -169,8 +168,7 @@ public static void main(String... args) throws Exception { // run with the archive and the jar with modified timestamp. // It should fail due to timestamp of the jar doesn't match the one // used during dump time. - TestCommon.run("-Xlog:class+load=trace", - "-cp", destJar.toString(), + TestCommon.run("-cp", destJar.toString(), "--module-path", moduleDir.toString(), "-m", TEST_MODULE1) .assertAbnormalExit( diff --git a/test/hotspot/jtreg/runtime/appcds/jvmti/transformRelatedClasses/TransformRelatedClassesAppCDS.java b/test/hotspot/jtreg/runtime/appcds/jvmti/transformRelatedClasses/TransformRelatedClassesAppCDS.java index 2f2aebe34f3..ae36383b955 100644 --- a/test/hotspot/jtreg/runtime/appcds/jvmti/transformRelatedClasses/TransformRelatedClassesAppCDS.java +++ b/test/hotspot/jtreg/runtime/appcds/jvmti/transformRelatedClasses/TransformRelatedClassesAppCDS.java @@ -188,7 +188,6 @@ private void runWithCustomLoader(ArrayList testTable) throws Exceptio TestCommon.run("-Xlog:class+load=info", "-cp", appJar, - "--add-opens=java.base/java.security=ALL-UNNAMED", agentParam, "CustomLoaderApp", customJar, loaderType, child) diff --git a/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java b/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java index 26164af4dc1..016b8b5b9d6 100644 --- a/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java +++ b/test/hotspot/jtreg/runtime/appcds/sharedStrings/IncompatibleOptions.java @@ -141,10 +141,10 @@ static void testExec(int testCaseNr, String collectorOption, String extraOption, // main class param, and fails with "Could not find or load main class" if (!extraOption.isEmpty()) { output = TestCommon.exec(appJar, "-XX:+UseCompressedOops", - collectorOption, extraOption, "HelloString"); + collectorOption, "-Xlog:cds", extraOption, "HelloString"); } else { output = TestCommon.exec(appJar, "-XX:+UseCompressedOops", - collectorOption, "HelloString"); + collectorOption, "-Xlog:cds", "HelloString"); } if (expectedWarning != null) diff --git a/test/hotspot/jtreg/runtime/logging/RedefineClasses.java b/test/hotspot/jtreg/runtime/logging/RedefineClasses.java new file mode 100644 index 00000000000..36ad159c3b0 --- /dev/null +++ b/test/hotspot/jtreg/runtime/logging/RedefineClasses.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, 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. + * + * 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 8197901 8209758 + * @summary Redefine classes with enabling logging to verify Klass:external_name() during GC. + * @comment This test is simplified version of runtime/RedefineTests/RedefineRunningMethods.java. + * @library /test/lib + * @modules java.compiler + * java.instrument + * jdk.jartool/sun.tools.jar + * @run main RedefineClassHelper + * @run main/othervm -Xmx256m -XX:MaxMetaspaceSize=64m -javaagent:redefineagent.jar -Xlog:all=trace:file=all.log RedefineClasses + */ + +// package access top-level class to avoid problem with RedefineClassHelper +// and nested types. +class RedefineClasses_B { + public static void test() { + } +} + +public class RedefineClasses { + static Object[] obj = new Object[20]; + public static String newB = + "class RedefineClasses_B {" + + " public static void test() { " + + " }" + + "}"; + + public static void main(String[] args) throws Exception { + RedefineClassHelper.redefineClass(RedefineClasses_B.class, newB); + RedefineClasses_B.test(); + for (int i = 0; i < 20 ; i++) { + obj[i] = new byte[10 * 1024 * 1024]; + System.gc(); + } + } +} diff --git a/test/hotspot/jtreg/serviceability/sa/LingeredAppWithNativeMethod.java b/test/hotspot/jtreg/serviceability/sa/LingeredAppWithNativeMethod.java new file mode 100644 index 00000000000..73629b79d92 --- /dev/null +++ b/test/hotspot/jtreg/serviceability/sa/LingeredAppWithNativeMethod.java @@ -0,0 +1,74 @@ + +/* + * Copyright (c) 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. + * + * 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.apps.LingeredApp; + +public class LingeredAppWithNativeMethod extends LingeredApp { + + public static final String THREAD_NAME = "NoFramePointerJNIFib"; + private static final int UPPER_BOUND = 55; + private static final int LOWER_BOUND = 40; + + static { + // JNI library compiled with no frame pointer info + System.loadLibrary("NoFramePointer"); + } + + public void callNative() { + // Call JNI code which does something compute + // intensive: fibonacci + // That is to ensure that the native bits run when + // jstack --mixed info is to be gathered. + // Results of fibonacci calculation from JNI are + // reported via callback(). That's where the process + // of calculating fibonacci restarts. + int num = (int) (Math.random() * UPPER_BOUND); + while (num < LOWER_BOUND) { + num = (int) (Math.random() * UPPER_BOUND); + } + System.out.print("fib(" + num + ") = "); + callJNI(this, num); + } + + // Called from JNI library libNoFramePointer + private void callback(long val) { + System.out.println(val); + // Call native again so as to increase chances of + // being currently in JNI code when jstack --mixed + // runs. + callNative(); + } + + public static native void callJNI(Object target, int num); + + public static void main(String[] args) { + LingeredAppWithNativeMethod app = new LingeredAppWithNativeMethod(); + Thread fibonacci = new Thread(() -> { + app.callNative(); + }); + fibonacci.setName(THREAD_NAME); + fibonacci.start(); + LingeredApp.main(args); + } +} diff --git a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java new file mode 100644 index 00000000000..d529becb346 --- /dev/null +++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java @@ -0,0 +1,187 @@ +/* + * Copyright (c) 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. + * + * 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.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import jdk.test.lib.JDKToolLauncher; +import jdk.test.lib.Utils; +import jdk.test.lib.apps.LingeredApp; +import jdk.test.lib.process.OutputAnalyzer; + +/** + * @test + * @bug 8208091 + * @requires (os.family == "linux") & (vm.hasSAandCanAttach) + * @library /test/lib + * @run main/othervm TestJhsdbJstackMixed + */ +public class TestJhsdbJstackMixed { + + private static final int MAX_ITERATIONS = 20; + private static final String NATIVE_FUNCTION_NAME = "fib"; + private static final String LINE_MATCHER_STR = ".*" + NATIVE_FUNCTION_NAME + + ".*"; + private static final Pattern LINE_PATTERN = Pattern + .compile(LINE_MATCHER_STR); + private static final String HEX_STR_PATTERN = "0x([a-fA-F0-9]+)"; + private static final String FIB_SPLIT_PATTERN = NATIVE_FUNCTION_NAME + + "\\s+\\+"; + private static final Pattern HEX_PATTERN = Pattern.compile(HEX_STR_PATTERN); + private static final int ADDRESS_ALIGNMENT_X86 = 4; + + /* + * UnmappedAddressException will be thrown iff: + * - The JNI code is being compiled with -fomit-frame-pointer AND + * - The JNI code is currently executing at address A = pc() + offset + * where A % ADDRESS_SIZE == 0. + * + * In the below example we have: pc() == f6401546, offset == 56, + * ADDRESS_SIZE == 4. Thus, A == F640159C which satisfies this condition. + * + * "NoFramePointerJNIFib" #11 prio=5 tid=0xa357bc00 nid=0x6de9 runnable [0xa365b000] + * java.lang.Thread.State: RUNNABLE + * JavaThread state: _thread_in_native + * 0xf6401546 fib + 0x56 + */ + private static boolean isFibAndAlignedAddress(List lines) { + List fibLines = findFibLines(lines); + System.out.println("DEBUG: " + fibLines); + // we're only interested in the first matched line. + if (fibLines.size() >= 1) { + String line = fibLines.get(0); + return isMatchLine(line); + } + return false; + } + + private static boolean isMatchLine(String line) { + String[] tokens = line.split(FIB_SPLIT_PATTERN); + if (tokens.length != 2) { + return false; // NOT exactly two tokens, ignore. + } + String pcRaw = tokens[0].trim(); + String offsetRaw = tokens[1].trim(); + Matcher matcher = HEX_PATTERN.matcher(pcRaw); + long pcVal = 3; + boolean pcMatched = matcher.matches(); + if (pcMatched) { + String pc = matcher.group(1); + pcVal = Long.parseUnsignedLong(pc, 16); + } + matcher = HEX_PATTERN.matcher(offsetRaw); + long offsetVal = 0; + boolean offsetMatched = matcher.matches(); + if (offsetMatched) { + String offset = matcher.group(1); + offsetVal = Long.parseUnsignedLong(offset, 16); + } + if (offsetMatched && pcMatched + && (pcVal + offsetVal) % ADDRESS_ALIGNMENT_X86 == 0) { + return true; + } + return false; + } + + private static List findFibLines(List lines) { + boolean startReached = false; + boolean endReached = false; + List interestingLines = new ArrayList<>(); + for (String line : lines) { + if (line.contains(LingeredAppWithNativeMethod.THREAD_NAME)) { + startReached = true; + } + if (startReached && line.contains("-------")) { + endReached = true; + } + if (startReached && !endReached) { + Matcher matcher = LINE_PATTERN.matcher(line); + if (matcher.matches()) { + interestingLines.add(line); + } + } + } + return interestingLines; + } + + private static void runJstackMixedInLoop(LingeredApp app) throws Exception { + for (int i = 0; i < MAX_ITERATIONS; i++) { + JDKToolLauncher launcher = JDKToolLauncher + .createUsingTestJDK("jhsdb"); + launcher.addToolArg("jstack"); + launcher.addToolArg("--mixed"); + launcher.addToolArg("--pid"); + launcher.addToolArg(Long.toString(app.getPid())); + + ProcessBuilder pb = new ProcessBuilder(); + pb.command(launcher.getCommand()); + Process jhsdb = pb.start(); + OutputAnalyzer out = new OutputAnalyzer(jhsdb); + + jhsdb.waitFor(); + + System.out.println(out.getStdout()); + System.err.println(out.getStderr()); + + out.shouldContain(LingeredAppWithNativeMethod.THREAD_NAME); + if (isFibAndAlignedAddress(out.asLines())) { + System.out.println("DEBUG: Test triggered interesting condition."); + out.shouldNotContain("sun.jvm.hotspot.debugger.UnmappedAddressException:"); + System.out.println("DEBUG: Test PASSED."); + return; // If we've reached here, all is well. + } + System.out.println("DEBUG: Iteration: " + (i + 1) + + " - Test didn't trigger interesting condition."); + out.shouldNotContain("sun.jvm.hotspot.debugger.UnmappedAddressException:"); + } + System.out.println("DEBUG: Test didn't trigger interesting condition " + + "but no UnmappedAddressException was thrown. PASS!"); + } + + public static void main(String... args) throws Exception { + + LingeredApp app = null; + + try { + List vmArgs = new ArrayList(Utils.getVmOptions()); + // Needed for LingeredApp to be able to resolve native library. + String libPath = System.getProperty("java.library.path"); + if (libPath != null) { + vmArgs.add("-Djava.library.path=" + libPath); + } + + app = new LingeredAppWithNativeMethod(); + LingeredApp.startApp(vmArgs, app); + System.out.println("Started LingeredApp with pid " + app.getPid()); + runJstackMixedInLoop(app); + System.out.println("Test Completed"); + } catch (Throwable e) { + e.printStackTrace(); + throw e; + } finally { + LingeredApp.stopApp(app); + } + } +} diff --git a/test/hotspot/jtreg/serviceability/sa/libNoFramePointer.c b/test/hotspot/jtreg/serviceability/sa/libNoFramePointer.c new file mode 100644 index 00000000000..8942244149d --- /dev/null +++ b/test/hotspot/jtreg/serviceability/sa/libNoFramePointer.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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. + * + * 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 + +static jlong fib(jint num) { + if (num == 0) { + return 0; + } + if (num <= 2) { + return 1; + } + return fib(num - 2) + fib(num -1); +} + +static void callCallback(JNIEnv *env, jclass cls, jobject target, jlong result) { + jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "(J)V"); + if (mid == NULL) { + jclass nsme = (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/NoSuchMethodException")); + if (nsme != NULL) { + (*env)->ThrowNew(env, nsme, "Can't find method callback()"); + } + return; + } + (*env)->CallVoidMethod(env, target, mid, result); +} + +static void calculateAndCallCallback(JNIEnv *env, jclass cls, jobject target, jint num) { + jlong result = -1; + result = fib(num); + callCallback(env, cls, target, result); +} + +JNIEXPORT void JNICALL +Java_LingeredAppWithNativeMethod_callJNI(JNIEnv *env, jclass cls, jobject target, jint num) { + calculateAndCallCallback(env, cls, target, num); +} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c index ecc7114202c..5229020717e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ThreadStart/threadstart003/threadstart003.c @@ -216,7 +216,7 @@ Java_nsk_jvmti_ThreadStart_threadstart003_check(JNIEnv *env, TranslateError(err), err); result = STATUS_FAILED; } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)WAIT_TIME); + err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, 0); if (err != JVMTI_ERROR_NONE) { printf("(RawMonitorWait) unexpected error: %s (%d)\n", TranslateError(err), err); @@ -235,7 +235,16 @@ Java_nsk_jvmti_ThreadStart_threadstart003_check(JNIEnv *env, TranslateError(err), err); result = STATUS_FAILED; } - err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)WAIT_TIME); + // Wait for up to 3 seconds for the thread end event + { + int i; + for (i = 0; i < 3 ; i++) { + err = (*jvmti)->RawMonitorWait(jvmti, wait_lock, (jlong)WAIT_TIME); + if (endsCount == endsExpected || err != JVMTI_ERROR_NONE) { + break; + } + } + } if (err != JVMTI_ERROR_NONE) { printf("(RawMonitorWait) unexpected error: %s (%d)\n", TranslateError(err), err); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c index ba4eda0fe77..284408a3b58 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/FollowReferences/followref003/followref003.c @@ -770,10 +770,13 @@ jint JNICALL heapReferenceCallback( break; case JVMTI_HEAP_REFERENCE_STACK_LOCAL: - thr_idx = registerThread(thr_id, thr_tag); - meth_idx = registerFrame(thr_id, depth, method, ref_kind); - if (meth_idx > 0) { - jint loc_idx = registerLocal(meth_idx, location, slot, tag); + // Skip local references from non-main (e.g. compiler) threads. + if (thr_tag == TARG_THREAD_TAG) { + thr_idx = registerThread(thr_id, thr_tag); + meth_idx = registerFrame(thr_id, depth, method, ref_kind); + if (meth_idx > 0) { + jint loc_idx = registerLocal(meth_idx, location, slot, tag); + } } /* This part is kind of hack. It has some expectations about stack layout */ if (thr_tag == TARG_THREAD_TAG && @@ -811,10 +814,13 @@ jint JNICALL heapReferenceCallback( nsk_jvmti_setFailStatus(); } } - /* Fall through */ + break; case JVMTI_HEAP_REFERENCE_JNI_LOCAL: - thr_idx = registerThread(thr_id, thr_tag); - meth_idx = registerFrame(thr_id, depth, method, ref_kind); + // Skip JNI local references from non-main (e.g. compiler) threads. + if (thr_tag == TARG_THREAD_TAG) { + thr_idx = registerThread(thr_id, thr_tag); + meth_idx = registerFrame(thr_id, depth, method, ref_kind); + } break; case JVMTI_REFERENCE_ARRAY_ELEMENT: diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 5bb12974772..a17e1193340 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -836,8 +836,6 @@ tools/pack200/CommandLineTests.java 8059906 generic- com/sun/jdi/BasicJDWPConnectionTest.java 8195703 generic-all -com/sun/jdi/BreakpointWithFullGC.java 8209605 generic-all - com/sun/jdi/RedefineImplementor.sh 8004127 generic-all com/sun/jdi/JdbExprTest.sh 8203393 solaris-all diff --git a/test/jdk/com/sun/crypto/provider/Cipher/PBE/PKCS12Cipher.java b/test/jdk/com/sun/crypto/provider/Cipher/PBE/PKCS12Cipher.java index 00ff89ade69..9f80b0ae152 100644 --- a/test/jdk/com/sun/crypto/provider/Cipher/PBE/PKCS12Cipher.java +++ b/test/jdk/com/sun/crypto/provider/Cipher/PBE/PKCS12Cipher.java @@ -106,7 +106,7 @@ class MyPBEKey implements PBEKey { this.salt = salt; this.iCount = iCount; } - public char[] getPassword() { return passwd; } + public char[] getPassword() { return passwd.clone(); } public byte[] getSalt() { return salt; } public int getIterationCount() { return iCount; } public String getAlgorithm() { return "PBE"; } diff --git a/test/jdk/com/sun/jdi/BreakpointWithFullGC.java b/test/jdk/com/sun/jdi/BreakpointWithFullGC.java index da79603214d..622ed3e8840 100644 --- a/test/jdk/com/sun/jdi/BreakpointWithFullGC.java +++ b/test/jdk/com/sun/jdi/BreakpointWithFullGC.java @@ -72,9 +72,8 @@ private BreakpointWithFullGC() { } private static final String DEBUGGEE_CLASS = BreakpointWithFullGCTarg.class.getName(); - // Hijacking the mode parameter to make sure we use a small amount - // of memory and can see what GC is doing. - private static final String[] DEBUGGEE_OPTIONS = {"-Xmx32m", "-verbose:gc"}; + // We don't specify "-Xmx" for debuggee as we have full GCs with any value. + private static final String[] DEBUGGEE_OPTIONS = {"-verbose:gc"}; @Override protected void runCases() { @@ -99,9 +98,6 @@ protected void runCases() { // make sure we hit the last breakpoint .stdoutShouldMatch("System\\..*end of test"); new OutputAnalyzer(jdb.getDebuggeeOutput()) - // make sure we had at least one full GC - // Prior to JDK9-B95, the pattern was 'Full GC' - .stdoutShouldContain("Pause Full (System.gc())") // check for error message due to thread ID change .stderrShouldNotContain("Exception in thread \"event-handler\" java.lang.NullPointerException"); } diff --git a/test/jdk/com/sun/jdi/lib/jdb/Jdb.java b/test/jdk/com/sun/jdi/lib/jdb/Jdb.java index fa72ee06721..aeb029f568e 100644 --- a/test/jdk/com/sun/jdi/lib/jdb/Jdb.java +++ b/test/jdk/com/sun/jdi/lib/jdb/Jdb.java @@ -104,26 +104,31 @@ public Jdb(LaunchOptions options) { } // launch jdb - ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jdb")); - pb.command().add("-connect"); - pb.command().add("com.sun.jdi.SocketAttach:port=" + debuggeeListen[1]); - System.out.println("Launching jdb:" + pb.command().stream().collect(Collectors.joining(" "))); try { - jdb = pb.start(); - } catch (IOException ex) { - throw new RuntimeException("failed to launch pdb", ex); - } - StreamPumper stdout = new StreamPumper(jdb.getInputStream()); - StreamPumper stderr = new StreamPumper(jdb.getErrorStream()); - - stdout.addPump(new StreamPumper.StreamPump(outputHandler)); - stderr.addPump(new StreamPumper.StreamPump(outputHandler)); + ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jdb")); + pb.command().add("-connect"); + pb.command().add("com.sun.jdi.SocketAttach:port=" + debuggeeListen[1]); + System.out.println("Launching jdb:" + pb.command().stream().collect(Collectors.joining(" "))); + try { + jdb = pb.start(); + } catch (IOException ex) { + throw new RuntimeException("failed to launch pdb", ex); + } + StreamPumper stdout = new StreamPumper(jdb.getInputStream()); + StreamPumper stderr = new StreamPumper(jdb.getErrorStream()); - stdout.process(); - stderr.process(); + stdout.addPump(new StreamPumper.StreamPump(outputHandler)); + stderr.addPump(new StreamPumper.StreamPump(outputHandler)); - inputWriter = new PrintWriter(jdb.getOutputStream(), true); + stdout.process(); + stderr.process(); + inputWriter = new PrintWriter(jdb.getOutputStream(), true); + } catch (Throwable ex) { + // terminate debuggee if something went wrong + debuggee.destroy(); + throw ex; + } } private final Process jdb; @@ -357,7 +362,8 @@ public synchronized void write(byte b[], int off, int len) throws IOException { // returned data becomes invalid after {@reset}. public synchronized List get() { if (updated()) { - String[] newLines = outStream.toString().split(lineSeparator); + // we don't want to discard empty lines + String[] newLines = outStream.toString().split("\\R", -1); if (!cachedData.isEmpty()) { // concat the last line if previous data had no EOL newLines[0] = cachedData.remove(cachedData.size()-1) + newLines[0]; diff --git a/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java b/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java index 93c5d58ae27..0d6eb54582b 100644 --- a/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java +++ b/test/jdk/com/sun/jdi/lib/jdb/JdbTest.java @@ -63,7 +63,9 @@ protected void setup() { protected abstract void runCases(); protected void shutdown() { - jdb.shutdown(); + if (jdb != null) { + jdb.shutdown(); + } } protected static final String lineSeparator = System.getProperty("line.separator"); diff --git a/test/jdk/sun/security/krb5/auto/SpnegoUnknownMech.java b/test/jdk/sun/security/krb5/auto/SpnegoUnknownMech.java new file mode 100644 index 00000000000..8be56b2f7d1 --- /dev/null +++ b/test/jdk/sun/security/krb5/auto/SpnegoUnknownMech.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 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. + * + * 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 8186186 8209829 + * @library /test/lib + * @compile -XDignore.symbol.file SpnegoUnknownMech.java + * @run main jdk.test.lib.FileInstaller TestHosts TestHosts + * @run main/othervm/fail -Djdk.net.hosts.file=TestHosts SpnegoUnknownMech + */ + +import sun.security.jgss.GSSUtil; + +public class SpnegoUnknownMech { + + public static void main(String[] args) throws Exception { + + new OneKDC(null).writeJAASConf(); + + Context c, s; + c = Context.fromJAAS("client"); + s = Context.fromJAAS("server"); + + c.startAsClient(OneKDC.SERVER, GSSUtil.GSS_SPNEGO_MECH_OID); + s.startAsServer(GSSUtil.GSS_SPNEGO_MECH_OID); + + byte[] init = c.take(new byte[0]); + // Modify the krb5 mech OID inside NegTokenInit to something else + init[0x20] = 10; + s.take(init); + + s.dispose(); + c.dispose(); + } +} diff --git a/test/lib/jdk/test/lib/Utils.java b/test/lib/jdk/test/lib/Utils.java index 8368ab717f6..dea36051c22 100644 --- a/test/lib/jdk/test/lib/Utils.java +++ b/test/lib/jdk/test/lib/Utils.java @@ -612,7 +612,7 @@ public static URLClassLoader getTestClassPathURLClassLoader(ClassLoader parent) * @param runnable what we run * @param expectedException expected exception */ - public static void runAndCheckException(Runnable runnable, Class expectedException) { + public static void runAndCheckException(ThrowingRunnable runnable, Class expectedException) { runAndCheckException(runnable, t -> { if (t == null) { if (expectedException != null) { @@ -635,13 +635,14 @@ public static void runAndCheckException(Runnable runnable, Class checkException) { + public static void runAndCheckException(ThrowingRunnable runnable, Consumer checkException) { + Throwable throwable = null; try { runnable.run(); - checkException.accept(null); } catch (Throwable t) { - checkException.accept(t); + throwable = t; } + checkException.accept(throwable); } /** diff --git a/test/lib/jdk/test/lib/cds/CDSTestUtils.java b/test/lib/jdk/test/lib/cds/CDSTestUtils.java index 6b60ef624dc..d3e694950ad 100644 --- a/test/lib/jdk/test/lib/cds/CDSTestUtils.java +++ b/test/lib/jdk/test/lib/cds/CDSTestUtils.java @@ -36,6 +36,11 @@ // This class contains common test utilities for testing CDS public class CDSTestUtils { + public static final String MSG_RANGE_NOT_WITHIN_HEAP = + "UseSharedSpaces: Unable to allocate region, range is not within java heap."; + public static final String MSG_RANGE_ALREADT_IN_USE = + "Unable to allocate region, java heap range is already in use."; + public interface Checker { public void check(OutputAnalyzer output) throws Exception; } @@ -195,11 +200,19 @@ public Result assertAbnormalExit(String... matches) throws Exception { } } - // Specify this property to copy sdandard output of the child test process to - // the parent/main stdout of the test. - // By default such output is logged into a file, and is copied into the main stdout. - public static final boolean CopyChildStdoutToMainStdout = - Boolean.valueOf(System.getProperty("test.cds.copy.child.stdout", "true")); + // A number to be included in the filename of the stdout and the stderr output file. + static int logCounter = 0; + + private static int getNextLogCounter() { + return logCounter++; + } + + // By default, stdout of child processes are logged in files such as + // -0000-exec.stdout. If you want to also include the stdout + // inside jtr files, you can override this in the jtreg command line like + // "jtreg -Dtest.cds.copy.child.stdout=true ...." + public static final boolean copyChildStdoutToMainStdout = + Boolean.getBoolean("test.cds.copy.child.stdout"); // This property is passed to child test processes public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0"); @@ -544,13 +557,17 @@ public static File getSourceFile(String name) { public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception { long started = System.currentTimeMillis(); OutputAnalyzer output = new OutputAnalyzer(pb.start()); + String outputFileNamePrefix = + getTestName() + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName; - writeFile(getOutputFile(logName + ".stdout"), output.getStdout()); - writeFile(getOutputFile(logName + ".stderr"), output.getStderr()); + writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout()); + writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr()); System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]"); + System.out.println("[logging stdout to " + outputFileNamePrefix + ".stdout]"); + System.out.println("[logging stderr to " + outputFileNamePrefix + ".stderr]"); System.out.println("[STDERR]\n" + output.getStderr()); - if (CopyChildStdoutToMainStdout) + if (copyChildStdoutToMainStdout) System.out.println("[STDOUT]\n" + output.getStdout()); return output;