From 0d8fd571458be8799e9a62940e0f458250752cf3 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Wed, 21 Jun 2023 04:55:43 +0000 Subject: [PATCH 01/19] 8310265: (process) jspawnhelper should not use argv[0] Reviewed-by: simonis, rriggs --- .../unix/native/jspawnhelper/jspawnhelper.c | 4 ++-- src/java.base/unix/native/libjava/ProcessImpl_md.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c index 16845901589..5a583fda61f 100644 --- a/src/java.base/unix/native/jspawnhelper/jspawnhelper.c +++ b/src/java.base/unix/native/jspawnhelper/jspawnhelper.c @@ -136,14 +136,14 @@ void initChildStuff (int fdin, int fdout, ChildStuff *c) { int main(int argc, char *argv[]) { ChildStuff c; struct stat buf; - /* argv[0] contains the fd number to read all the child info */ + /* argv[1] contains the fd number to read all the child info */ int r, fdinr, fdinw, fdout; sigset_t unblock_signals; #ifdef DEBUG jtregSimulateCrash(0, 4); #endif - r = sscanf (argv[argc-1], "%d:%d:%d", &fdinr, &fdinw, &fdout); + r = sscanf (argv[1], "%d:%d:%d", &fdinr, &fdinw, &fdout); if (r == 3 && fcntl(fdinr, F_GETFD) != -1 && fcntl(fdinw, F_GETFD) != -1) { fstat(fdinr, &buf); if (!S_ISFIFO(buf.st_mode)) diff --git a/src/java.base/unix/native/libjava/ProcessImpl_md.c b/src/java.base/unix/native/libjava/ProcessImpl_md.c index 66c44956b21..04a1e5cf6b5 100644 --- a/src/java.base/unix/native/libjava/ProcessImpl_md.c +++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c @@ -488,16 +488,20 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) pid_t resultPid; int i, offset, rval, bufsize, magic; char *buf, buf1[(3 * 11) + 3]; // "%d:%d:%d\0" - char *hlpargs[2]; + char *hlpargs[3]; SpawnInfo sp; /* need to tell helper which fd is for receiving the childstuff * and which fd to send response back on */ snprintf(buf1, sizeof(buf1), "%d:%d:%d", c->childenv[0], c->childenv[1], c->fail[1]); - /* put the fd string as argument to the helper cmd */ - hlpargs[0] = buf1; - hlpargs[1] = 0; + /* NULL-terminated argv array. + * argv[0] contains path to jspawnhelper, to follow conventions. + * argv[1] contains the fd string as argument to jspawnhelper + */ + hlpargs[0] = (char*)helperpath; + hlpargs[1] = buf1; + hlpargs[2] = NULL; /* Following items are sent down the pipe to the helper * after it is spawned. From b8f5e3d93280bf99c6e7a3a9ddb34d84c1d2e32f Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Wed, 21 Jun 2023 06:40:50 +0000 Subject: [PATCH 02/19] 8308606: C2 SuperWord: remove alignment checks when not required Reviewed-by: fgao, kvn, pli --- .../superword/TestDependencyOffsets.java | 76 ++--- .../runner/LoopArrayIndexComputeTest.java | 89 ++++- .../bench/vm/compiler/VectorAlignment.java | 315 ++++++++++++++++++ 3 files changed, 432 insertions(+), 48 deletions(-) create mode 100644 test/micro/org/openjdk/bench/vm/compiler/VectorAlignment.java diff --git a/test/hotspot/jtreg/compiler/loopopts/superword/TestDependencyOffsets.java b/test/hotspot/jtreg/compiler/loopopts/superword/TestDependencyOffsets.java index 9130571a406..14033f9712a 100644 --- a/test/hotspot/jtreg/compiler/loopopts/superword/TestDependencyOffsets.java +++ b/test/hotspot/jtreg/compiler/loopopts/superword/TestDependencyOffsets.java @@ -25,10 +25,9 @@ * Summary: * Test SuperWord vectorization with different access offsets * and various MaxVectorSize values, and +- AlignVector. - * Note: CompileCommand Option Vectorize is enabled. * * Note: this test is auto-generated. Please modify / generate with script: - * https://bugs.openjdk.org/browse/JDK-8298935 + * https://bugs.openjdk.org/browse/JDK-8308606 * * Types: int, long, short, char, byte, float, double * Offsets: 0, -1, 1, -2, 2, -3, 3, -4, 4, -7, 7, -8, 8, -14, 14, -16, 16, -18, 18, -20, 20, -31, 31, -32, 32, -63, 63, -64, 64, -65, 65, -128, 128, -129, 129, -192, 192 @@ -91,7 +90,7 @@ /* * @test id=vanilla-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @library /test/lib / @@ -100,7 +99,7 @@ /* * @test id=vanilla-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @library /test/lib / @@ -109,7 +108,7 @@ /* * @test id=sse4-v016-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -120,7 +119,7 @@ /* * @test id=sse4-v016-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -131,7 +130,7 @@ /* * @test id=sse4-v008-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -142,7 +141,7 @@ /* * @test id=sse4-v008-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -153,7 +152,7 @@ /* * @test id=sse4-v004-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -164,7 +163,7 @@ /* * @test id=sse4-v004-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -175,7 +174,7 @@ /* * @test id=sse4-v002-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -186,7 +185,7 @@ /* * @test id=sse4-v002-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -197,7 +196,7 @@ /* * @test id=avx1-v032-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -208,7 +207,7 @@ /* * @test id=avx1-v032-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -219,7 +218,7 @@ /* * @test id=avx1-v016-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -230,7 +229,7 @@ /* * @test id=avx1-v016-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -241,7 +240,7 @@ /* * @test id=avx2-v032-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -252,7 +251,7 @@ /* * @test id=avx2-v032-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -263,7 +262,7 @@ /* * @test id=avx2-v016-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -274,7 +273,7 @@ /* * @test id=avx2-v016-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -285,7 +284,7 @@ /* * @test id=avx512-v064-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -296,7 +295,7 @@ /* * @test id=avx512-v064-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -307,7 +306,7 @@ /* * @test id=avx512-v032-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -318,7 +317,7 @@ /* * @test id=avx512-v032-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -329,7 +328,7 @@ /* * @test id=avx512bw-v064-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -340,7 +339,7 @@ /* * @test id=avx512bw-v064-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -351,7 +350,7 @@ /* * @test id=avx512bw-v032-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -362,7 +361,7 @@ /* * @test id=avx512bw-v032-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64") @@ -373,7 +372,7 @@ /* * @test id=vec-v064-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -383,7 +382,7 @@ /* * @test id=vec-v064-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -393,7 +392,7 @@ /* * @test id=vec-v032-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -403,7 +402,7 @@ /* * @test id=vec-v032-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -413,7 +412,7 @@ /* * @test id=vec-v016-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -423,7 +422,7 @@ /* * @test id=vec-v016-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -433,7 +432,7 @@ /* * @test id=vec-v008-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -443,7 +442,7 @@ /* * @test id=vec-v008-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -453,7 +452,7 @@ /* * @test id=vec-v004-A - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -463,7 +462,7 @@ /* * @test id=vec-v004-U - * @bug 8298935 + * @bug 8298935 8308606 * @summary Test SuperWord: vector size, offsets, dependencies, alignment. * @requires vm.compiler2.enabled * @requires (os.arch!="x86" & os.arch!="i386" & os.arch!="amd64" & os.arch!="x86_64") @@ -1262,7 +1261,6 @@ public class TestDependencyOffsets { public static void main(String args[]) { TestFramework framework = new TestFramework(TestDependencyOffsets.class); framework.addFlags("-XX:-TieredCompilation", - "-XX:CompileCommand=option,compiler.loopopts.superword.TestDependencyOffsets::test*,Vectorize", "-XX:CompileCommand=compileonly,compiler.loopopts.superword.TestDependencyOffsets::init", "-XX:CompileCommand=compileonly,compiler.loopopts.superword.TestDependencyOffsets::test*", "-XX:CompileCommand=compileonly,compiler.loopopts.superword.TestDependencyOffsets::verify", diff --git a/test/hotspot/jtreg/compiler/vectorization/runner/LoopArrayIndexComputeTest.java b/test/hotspot/jtreg/compiler/vectorization/runner/LoopArrayIndexComputeTest.java index e09c58d8dbd..cc35213e5db 100644 --- a/test/hotspot/jtreg/compiler/vectorization/runner/LoopArrayIndexComputeTest.java +++ b/test/hotspot/jtreg/compiler/vectorization/runner/LoopArrayIndexComputeTest.java @@ -161,9 +161,11 @@ public int[] indexWithTwoInvariants() { } @Test - // Note that this case cannot be vectorized due to data dependence. - @IR(failOn = {IRNode.STORE_VECTOR}) - public int[] indexWithDifferentConstants() { + // No true dependency in read-forward case. + @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, + applyIf = {"AlignVector", "false"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + public int[] indexWithDifferentConstantsPos() { int[] res = new int[SIZE]; for (int i = 0; i < SIZE / 4; i++) { res[i] = ints[i + 1]; @@ -171,6 +173,17 @@ public int[] indexWithDifferentConstants() { return res; } + @Test + // Note that this case cannot be vectorized due to data dependence. + @IR(failOn = {IRNode.STORE_VECTOR}) + public int[] indexWithDifferentConstantsNeg() { + int[] res = new int[SIZE]; + for (int i = 1; i < SIZE / 4; i++) { + res[i] = ints[i - 1]; + } + return res; + } + @Test // Note that this case cannot be vectorized due to data dependence. @IR(failOn = {IRNode.STORE_VECTOR}) @@ -246,10 +259,13 @@ public int[] sameArrayWithDifferentIndex() { } // ---------------- Subword Type Arrays ---------------- + @Test - // Note that this case cannot be vectorized due to data dependence. - @IR(failOn = {IRNode.STORE_VECTOR}) - public short[] shortArrayWithDependence() { + // No true dependency in read-forward case. + @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, + applyIf = {"AlignVector", "false"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + public short[] shortArrayWithDependencePos() { short[] res = new short[SIZE]; System.arraycopy(shorts, 0, res, 0, SIZE); for (int i = 0; i < SIZE / 2; i++) { @@ -261,7 +277,21 @@ public short[] shortArrayWithDependence() { @Test // Note that this case cannot be vectorized due to data dependence. @IR(failOn = {IRNode.STORE_VECTOR}) - public char[] charArrayWithDependence() { + public short[] shortArrayWithDependenceNeg() { + short[] res = new short[SIZE]; + System.arraycopy(shorts, 0, res, 0, SIZE); + for (int i = 1; i < SIZE / 2; i++) { + res[i] *= shorts[i - 1]; + } + return res; + } + + @Test + // No true dependency in read-forward case. + @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, + applyIf = {"AlignVector", "false"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + public char[] charArrayWithDependencePos() { char[] res = new char[SIZE]; System.arraycopy(chars, 0, res, 0, SIZE); for (int i = 0; i < SIZE / 2; i++) { @@ -273,7 +303,21 @@ public char[] charArrayWithDependence() { @Test // Note that this case cannot be vectorized due to data dependence. @IR(failOn = {IRNode.STORE_VECTOR}) - public byte[] byteArrayWithDependence() { + public char[] charArrayWithDependenceNeg() { + char[] res = new char[SIZE]; + System.arraycopy(chars, 0, res, 0, SIZE); + for (int i = 2; i < SIZE / 2; i++) { + res[i] *= chars[i - 2]; + } + return res; + } + + @Test + // No true dependency in read-forward case. + @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, + applyIf = {"AlignVector", "false"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + public byte[] byteArrayWithDependencePos() { byte[] res = new byte[SIZE]; System.arraycopy(bytes, 0, res, 0, SIZE); for (int i = 0; i < SIZE / 2; i++) { @@ -282,10 +326,25 @@ public byte[] byteArrayWithDependence() { return res; } + @Test // Note that this case cannot be vectorized due to data dependence. @IR(failOn = {IRNode.STORE_VECTOR}) - public boolean[] booleanArrayWithDependence() { + public byte[] byteArrayWithDependenceNeg() { + byte[] res = new byte[SIZE]; + System.arraycopy(bytes, 0, res, 0, SIZE); + for (int i = 3; i < SIZE / 2; i++) { + res[i] *= bytes[i - 3]; + } + return res; + } + + @Test + // No true dependency in read-forward case. + @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, + applyIf = {"AlignVector", "false"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + public boolean[] booleanArrayWithDependencePos() { boolean[] res = new boolean[SIZE]; System.arraycopy(booleans, 0, res, 0, SIZE); for (int i = 0; i < SIZE / 2; i++) { @@ -294,6 +353,18 @@ public boolean[] booleanArrayWithDependence() { return res; } + @Test + // Note that this case cannot be vectorized due to data dependence. + @IR(failOn = {IRNode.STORE_VECTOR}) + public boolean[] booleanArrayWithDependenceNeg() { + boolean[] res = new boolean[SIZE]; + System.arraycopy(booleans, 0, res, 0, SIZE); + for (int i = 4; i < SIZE / 2; i++) { + res[i] |= booleans[i - 4]; + } + return res; + } + // ---------------- Multiple Operations ---------------- @Test @IR(applyIfCPUFeatureOr = {"asimd", "true", "sse2", "true"}, diff --git a/test/micro/org/openjdk/bench/vm/compiler/VectorAlignment.java b/test/micro/org/openjdk/bench/vm/compiler/VectorAlignment.java new file mode 100644 index 00000000000..7fff4952c8e --- /dev/null +++ b/test/micro/org/openjdk/bench/vm/compiler/VectorAlignment.java @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2023, 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 org.openjdk.bench.vm.compiler; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.*; + +import java.util.concurrent.TimeUnit; +import java.util.Random; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Thread) +@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS) +@Fork(value = 1) +public abstract class VectorAlignment { + @Param({/*"512", "1024", */ "2048"}) + public int COUNT; + + private int[] aI; + private int[] bI; + private int[] rI; + + private long[] aL; + private long[] bL; + private long[] rL; + + private short[] aS; + private short[] bS; + private short[] rS; + + private char[] aC; + private char[] bC; + private char[] rC; + + private byte[] aB; + private byte[] bB; + private byte[] rB; + + private float[] aF; + private float[] bF; + private float[] rF; + + private double[] aD; + private double[] bD; + private double[] rD; + + + @Param("0") + private int seed; + private Random r = new Random(seed); + + @Setup + public void init() { + aI = new int[COUNT]; + bI = new int[COUNT]; + rI = new int[COUNT]; + + aL = new long[COUNT]; + bL = new long[COUNT]; + rL = new long[COUNT]; + + aS = new short[COUNT]; + bS = new short[COUNT]; + rS = new short[COUNT]; + + aC = new char[COUNT]; + bC = new char[COUNT]; + rC = new char[COUNT]; + + aB = new byte[COUNT]; + bB = new byte[COUNT]; + rB = new byte[COUNT]; + + aF = new float[COUNT]; + bF = new float[COUNT]; + rF = new float[COUNT]; + + aD = new double[COUNT]; + bD = new double[COUNT]; + rD = new double[COUNT]; + + + for (int i = 0; i < COUNT; i++) { + aI[i] = r.nextInt(); + bI[i] = r.nextInt(); + + aL[i] = r.nextLong(); + bL[i] = r.nextLong(); + + aS[i] = (short) r.nextInt(); + bS[i] = (short) r.nextInt(); + + aC[i] = (char) r.nextInt(); + bC[i] = (char) r.nextInt(); + + aB[i] = (byte) r.nextInt(); + bB[i] = (byte) r.nextInt(); + + aF[i] = r.nextFloat(); + bF[i] = r.nextFloat(); + + aD[i] = r.nextDouble(); + bD[i] = r.nextDouble(); + } + } + + @Benchmark + // Control: should always vectorize with SuperWord + public void bench000I_control() { + for (int i = 0; i < COUNT; i++) { + // Have multiple MUL operations to make loop compute bound (more compute than load/store) + rI[i] = aI[i] * aI[i] * aI[i] * aI[i]; + } + } + + @Benchmark + public void bench000L_control() { + for (int i = 0; i < COUNT; i++) { + rL[i] = aL[i] * aL[i] * aL[i] * aL[i]; + } + } + + @Benchmark + public void bench000S_control() { + for (int i = 0; i < COUNT; i++) { + rS[i] = (short)(aS[i] * aS[i] * aS[i] * aS[i]); + } + } + + @Benchmark + public void bench000C_control() { + for (int i = 0; i < COUNT; i++) { + rC[i] = (char)(aC[i] * aC[i] * aC[i] * aC[i]); + } + } + + @Benchmark + public void bench000B_control() { + for (int i = 0; i < COUNT; i++) { + rB[i] = (byte)(aB[i] * aB[i] * aB[i] * aB[i]); + } + } + + @Benchmark + public void bench000F_control() { + for (int i = 0; i < COUNT; i++) { + rF[i] = aF[i] * aF[i] * aF[i] * aF[i]; + } + } + + @Benchmark + public void bench000D_control() { + for (int i = 0; i < COUNT; i++) { + rD[i] = aD[i] * aD[i] * aD[i] * aD[i]; + } + } + + @Benchmark + // Control: should always vectorize with SuperWord + public void bench001_control() { + for (int i = 0; i < COUNT; i++) { + // Have multiple MUL operations to make loop compute bound (more compute than load/store) + rI[i] = aI[i] * aI[i] * aI[i] * aI[i] + bI[i]; + } + } + + @Benchmark + // Vectorizes without AlignVector + public void bench100I_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rI[i] = aI[i+1] * aI[i+1] * aI[i+1] * aI[i+1]; + } + } + + @Benchmark + public void bench100L_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rL[i] = aL[i+1] * aL[i+1] * aL[i+1] * aL[i+1]; + } + } + + @Benchmark + public void bench100S_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rS[i] = (short)(aS[i+1] * aS[i+1] * aS[i+1] * aS[i+1]); + } + } + + @Benchmark + public void bench100C_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rC[i] = (char)(aC[i+1] * aC[i+1] * aC[i+1] * aC[i+1]); + } + } + + + @Benchmark + public void bench100B_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rB[i] = (byte)(aB[i+1] * aB[i+1] * aB[i+1] * aB[i+1]); + } + } + + @Benchmark + public void bench100F_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rF[i] = aF[i+1] * aF[i+1] * aF[i+1] * aF[i+1]; + } + } + + @Benchmark + public void bench100D_misaligned_load() { + for (int i = 0; i < COUNT-1; i++) { + rD[i] = aD[i+1] * aD[i+1] * aD[i+1] * aD[i+1]; + } + } + + @Benchmark + // Only without "Vectorize" (confused by hand-unrolling) + public void bench200_hand_unrolled_aligned() { + for (int i = 0; i < COUNT-10; i+=2) { + rI[i+0] = aI[i+0] * aI[i+0] * aI[i+0] * aI[i+0]; + rI[i+1] = aI[i+1] * aI[i+1] * aI[i+1] * aI[i+1]; + } + } + + @Benchmark + // Only with "Vectorize", without we get issues with modulo computation of alignment for bI + public void bench300_multiple_misaligned_loads() { + for (int i = 0; i < COUNT-10; i++) { + rI[i] = aI[i] * aI[i] * aI[i] * aI[i] + bI[i+1]; + } + } + + @Benchmark + // Only with "Vectorize", without we may confuse aI[5] with aI[4+1] and pack loads in wrong pack + public void bench301_multiple_misaligned_loads() { + for (int i = 0; i < COUNT-10; i++) { + rI[i] = aI[i] * aI[i] * aI[i] * aI[i] + aI[i+1]; + } + } + + @Benchmark + // Only with "Vectorize", without we get mix of aI[i] and a[i-2] + public void bench302_multiple_misaligned_loads_and_stores() { + for (int i = 2; i < COUNT; i++) { + rI[i - 2] = aI[i-2] * aI[i-2] * aI[i-2] * aI[i-2]; // can do this for all iterations + rI[i] = aI[i] + 3; // before doing this second line + } + } + + @Benchmark + // Currently does not vectorize: + // hand-unrolled confuses Vectorize -> adjacent loads not from same original node (not even same line) + // multiple unaligned loads confuses non-Vectorize: aI[5+1] confused with aI[4+2] (plus modulo alignment issue) + public void bench400_hand_unrolled_misaligned() { + for (int i = 0; i < COUNT-10; i+=2) { + rI[i+0] = aI[i+1] * aI[i+1] * aI[i+1] * aI[i+1] + aI[i]; + rI[i+1] = aI[i+2] * aI[i+2] * aI[i+2] * aI[i+2] + aI[i+1]; + } + } + + @Benchmark + // Currently does not vectorize: + // hand-unrolled confuses Vectorize -> adjacent loads not from same original node (not even same line) + // non-Vectorize: plus modulo alignment issue + public void bench401_hand_unrolled_misaligned() { + for (int i = 0; i < COUNT-10; i+=2) { + rI[i+0] = aI[i+1] * aI[i+1] * aI[i+1] * aI[i+1] + bI[i]; + rI[i+1] = aI[i+2] * aI[i+2] * aI[i+2] * aI[i+2] + bI[i+1]; + } + } + + @Fork(value = 1, jvmArgsPrepend = { + "-XX:+UseSuperWord", "-XX:CompileCommand=Option,*::*,Vectorize" + }) + public static class VectorAlignmentSuperWordWithVectorize extends VectorAlignment {} + + @Fork(value = 1, jvmArgsPrepend = { + "-XX:+UseSuperWord", "-XX:+AlignVector" + }) + public static class VectorAlignmentSuperWordAlignVector extends VectorAlignment {} + + @Fork(value = 1, jvmArgsPrepend = { + "-XX:+UseSuperWord" + }) + public static class VectorAlignmentSuperWord extends VectorAlignment {} + + @Fork(value = 1, jvmArgsPrepend = { + "-XX:-UseSuperWord" + }) + public static class VectorAlignmentNoSuperWord extends VectorAlignment {} +} From 5e53bb4c165ec3e80af4ee93f0ba1b3cbafb25af Mon Sep 17 00:00:00 2001 From: Julian Waters Date: Wed, 21 Jun 2023 06:43:03 +0000 Subject: [PATCH 03/19] 8307145: windowsaccessbridge.dll erroneously includes private methods in its C API Reviewed-by: djelinski --- .../native/libwindowsaccessbridge/WinAccessBridge.DEF | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.DEF b/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.DEF index 659a5882c7c..d9dafebb635 100644 --- a/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.DEF +++ b/src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.DEF @@ -28,11 +28,6 @@ ;DESCRIPTION 'WINDOWSACCESSBRIDGE.DLL' EXPORTS - addJavaEventNotification - removeJavaEventNotification - addAccessibilityEventNotification - removeAccessibilityEventNotification - Windows_run getAccessibleTableInfo From 9f7ec13417a99bfa391e0489983cd5a04103d40e Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Wed, 21 Jun 2023 06:49:24 +0000 Subject: [PATCH 04/19] 8310321: make JDKOPT_CHECK_CODESIGN_PARAMS more verbose Reviewed-by: erikj --- make/autoconf/jdk-options.m4 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4 index f08cc6ddd41..f56081223a6 100644 --- a/make/autoconf/jdk-options.m4 +++ b/make/autoconf/jdk-options.m4 @@ -822,6 +822,9 @@ AC_DEFUN([JDKOPT_CHECK_CODESIGN_PARAMS], $RM "$CODESIGN_TESTFILE" $TOUCH "$CODESIGN_TESTFILE" CODESIGN_SUCCESS=false + + $ECHO "check codesign, calling $CODESIGN $PARAMS $CODESIGN_TESTFILE" >&AS_MESSAGE_LOG_FD + eval \"$CODESIGN\" $PARAMS \"$CODESIGN_TESTFILE\" 2>&AS_MESSAGE_LOG_FD \ >&AS_MESSAGE_LOG_FD && CODESIGN_SUCCESS=true $RM "$CODESIGN_TESTFILE" From bc9a172d7931ab2a55f9d009134dbc35b922ab82 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Wed, 21 Jun 2023 07:05:41 +0000 Subject: [PATCH 05/19] 8310143: RandomCommandsTest fails due to unexpected VM exit code after JDK-8282797 Reviewed-by: rcastanedalo, chagedorn --- .../compilercontrol/jcmd/StressAddJcmdBase.java | 2 +- .../compiler/compilercontrol/share/MultiCommand.java | 7 +++++-- .../compilercontrol/share/scenario/Executor.java | 12 ++++-------- .../compilercontrol/share/scenario/Scenario.java | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddJcmdBase.java b/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddJcmdBase.java index cfd9e1c4bb0..a8c57bc408a 100644 --- a/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddJcmdBase.java +++ b/test/hotspot/jtreg/compiler/compilercontrol/jcmd/StressAddJcmdBase.java @@ -116,7 +116,7 @@ private enum JcmdCommand { private class TimeLimitedExecutor extends Executor { public TimeLimitedExecutor() { /* There are no need to check the state */ - super(true, VM_OPTIONS, null, null); + super(VM_OPTIONS, null, null); } @Override diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java b/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java index b043414b76a..3fceae41146 100644 --- a/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java +++ b/test/hotspot/jtreg/compiler/compilercontrol/share/MultiCommand.java @@ -56,6 +56,7 @@ public static AbstractTestBase generateRandomTest(boolean validOnly) { List testCases = new ArrayList<>(); for (Command cmd : commands) { + boolean isValid = true; String argument = null; if (validOnly && cmd == Command.NONEXISTENT) { @@ -67,6 +68,7 @@ public static AbstractTestBase generateRandomTest(boolean validOnly) { argument = Utils.getRandomElement(VALID_INTRINSIC_SAMPLES); } else { argument = Utils.getRandomElement(INVALID_INTRINSIC_SAMPLES); + isValid = false; } } @@ -78,12 +80,13 @@ public static AbstractTestBase generateRandomTest(boolean validOnly) { md = AbstractTestBase.getValidMethodDescriptor(exec); } else { md = AbstractTestBase.METHOD_GEN.generateRandomDescriptor(exec); + isValid &= md.isValid(); } CompileCommand cc; if (cmd == Command.INTRINSIC) { - cc = cmdGen.generateCompileCommand(cmd, true, md, null, argument); + cc = cmdGen.generateCompileCommand(cmd, isValid, md, null, argument); } else { - cc = cmdGen.generateCompileCommand(cmd, true, md, null); + cc = cmdGen.generateCompileCommand(cmd, isValid, md, null); } testCases.add(cc); } diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java index 8a868e89ee6..0111d1e90a1 100644 --- a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java +++ b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Executor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,6 @@ import java.util.Map; public class Executor { - private final boolean isValid; private final List vmOptions; private final Map states; private final List jcmdCommands; @@ -57,16 +56,13 @@ public class Executor { /** * Constructor * - * @param isValid shows that the input given to the VM is valid and - * VM shouldn't fail * @param vmOptions a list of VM input options * @param states a state map, or null for the non-checking execution * @param jcmdCommands a list of diagnostic commands to be preformed * on test VM */ - public Executor(boolean isValid, List vmOptions, - Map states, List jcmdCommands) { - this.isValid = isValid; + public Executor(List vmOptions, Map states, + List jcmdCommands) { if (vmOptions == null) { this.vmOptions = new ArrayList<>(); } else { @@ -77,7 +73,7 @@ public Executor(boolean isValid, List vmOptions, } /** - * Executes separate VM a gets an OutputAnalyzer instance with the results + * Executes separate VM and gets an OutputAnalyzer instance with the results * of execution */ public List execute() { diff --git a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Scenario.java b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Scenario.java index b277ae888b2..ad168f62eda 100644 --- a/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Scenario.java +++ b/test/hotspot/jtreg/compiler/compilercontrol/share/scenario/Scenario.java @@ -104,7 +104,7 @@ private Scenario(boolean isValid, jcmdExecCommands.add(JcmdType.PRINT.command); } jcmdProcessor = new PrintDirectivesProcessor(directives); - executor = new Executor(isValid, vmopts, states, jcmdExecCommands); + executor = new Executor(vmopts, states, jcmdExecCommands); } /** From 1634cb554d052ff4bfa5cf9794b4cd5834e7fc8b Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 21 Jun 2023 09:15:48 +0000 Subject: [PATCH 06/19] 8302865: Illegal bytecode for break from if with instanceof pattern matching condition Reviewed-by: vromero --- .../com/sun/tools/javac/comp/Attr.java | 68 +++++++++++++------ .../com/sun/tools/javac/comp/Flow.java | 53 +++------------ .../tools/javac/patterns/BindingsTest1.java | 61 +++++++++++++++++ .../tools/javac/patterns/BindingsTest2.java | 57 ++++++++++++++++ .../tools/javac/patterns/BindingsTest2.out | 13 ++-- .../tools/javac/patterns/BreakAndLoops.java | 11 +++ 6 files changed, 195 insertions(+), 68 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index fc646cc746e..1412c3644dd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1447,12 +1447,7 @@ public void visitBlock(JCBlock tree) { public void visitDoLoop(JCDoWhileLoop tree) { attribStat(tree.body, env.dup(tree)); attribExpr(tree.cond, env, syms.booleanType); - if (!breaksOutOf(tree, tree.body)) { - //include condition's body when false after the while, if cannot get out of the loop - MatchBindings condBindings = matchBindings; - condBindings.bindingsWhenFalse.forEach(env.info.scope::enter); - condBindings.bindingsWhenFalse.forEach(BindingSymbol::preserveBinding); - } + handleLoopConditionBindings(matchBindings, tree, tree.body); result = null; } @@ -1466,19 +1461,10 @@ public void visitWhileLoop(JCWhileLoop tree) { } finally { whileEnv.info.scope.leave(); } - if (!breaksOutOf(tree, tree.body)) { - //include condition's bindings when false after the while, if cannot get out of the loop - condBindings.bindingsWhenFalse.forEach(env.info.scope::enter); - condBindings.bindingsWhenFalse.forEach(BindingSymbol::preserveBinding); - } + handleLoopConditionBindings(condBindings, tree, tree.body); result = null; } - private boolean breaksOutOf(JCTree loop, JCTree body) { - preFlow(body); - return flow.breaksOutOf(env, loop, body, make); - } - public void visitForLoop(JCForLoop tree) { Env loopEnv = env.dup(env.tree, env.info.dup(env.info.scope.dup())); @@ -1503,11 +1489,50 @@ public void visitForLoop(JCForLoop tree) { finally { loopEnv.info.scope.leave(); } - if (!breaksOutOf(tree, tree.body)) { - //include condition's body when false after the while, if cannot get out of the loop - condBindings.bindingsWhenFalse.forEach(env.info.scope::enter); - condBindings.bindingsWhenFalse.forEach(BindingSymbol::preserveBinding); + handleLoopConditionBindings(condBindings, tree, tree.body); + } + + /** + * Include condition's bindings when false after the loop, if cannot get out of the loop + */ + private void handleLoopConditionBindings(MatchBindings condBindings, + JCStatement loop, + JCStatement loopBody) { + if (condBindings.bindingsWhenFalse.nonEmpty() && + !breaksTo(env, loop, loopBody)) { + addBindings2Scope(loop, condBindings.bindingsWhenFalse); + } + } + + private boolean breaksTo(Env env, JCTree loop, JCTree body) { + preFlow(body); + return flow.breaksToTree(env, loop, body, make); + } + + /** + * Add given bindings to the current scope, unless there's a break to + * an immediately enclosing labeled statement. + */ + private void addBindings2Scope(JCStatement introducingStatement, + List bindings) { + if (bindings.isEmpty()) { + return ; + } + + var searchEnv = env; + while (searchEnv.tree instanceof JCLabeledStatement labeled && + labeled.body == introducingStatement) { + if (breaksTo(env, labeled, labeled.body)) { + //breaking to an immediately enclosing labeled statement + return ; + } + searchEnv = searchEnv.next; + introducingStatement = labeled; } + + //include condition's body when false after the while, if cannot get out of the loop + bindings.forEach(env.info.scope::enter); + bindings.forEach(BindingSymbol::preserveBinding); } public void visitForeachLoop(JCEnhancedForLoop tree) { @@ -2242,8 +2267,7 @@ public void visitIf(JCIf tree) { afterIfBindings = condBindings.bindingsWhenFalse; } - afterIfBindings.forEach(env.info.scope::enter); - afterIfBindings.forEach(BindingSymbol::preserveBinding); + addBindings2Scope(tree, afterIfBindings); result = null; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index 6651e961985..c2b02650693 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -287,7 +287,7 @@ public boolean aliveAfter(Env env, JCTree that, TreeMaker make) { } } - public boolean breaksOutOf(Env env, JCTree loop, JCTree body, TreeMaker make) { + public boolean breaksToTree(Env env, JCTree breakTo, JCTree body, TreeMaker make) { //we need to disable diagnostics temporarily; the problem is that if //"that" contains e.g. an unreachable statement, an error //message will be reported and will cause compilation to skip the flow analysis @@ -295,10 +295,10 @@ public boolean breaksOutOf(Env env, JCTree loop, JCTree body, TreeM //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { - SnippetBreakAnalyzer analyzer = new SnippetBreakAnalyzer(); + SnippetBreakToAnalyzer analyzer = new SnippetBreakToAnalyzer(breakTo); analyzer.analyzeTree(env, body, make); - return analyzer.breaksOut(); + return analyzer.breaksTo(); } finally { log.popDiagnosticHandler(diagHandler); } @@ -1909,52 +1909,21 @@ public boolean isAlive() { } } - class SnippetBreakAnalyzer extends AliveAnalyzer { - private final Set seenTrees = new HashSet<>(); - private boolean breaksOut; + class SnippetBreakToAnalyzer extends AliveAnalyzer { + private final JCTree breakTo; + private boolean breaksTo; - public SnippetBreakAnalyzer() { - } - - @Override - public void visitLabelled(JCTree.JCLabeledStatement tree) { - seenTrees.add(tree); - super.visitLabelled(tree); - } - - @Override - public void visitWhileLoop(JCTree.JCWhileLoop tree) { - seenTrees.add(tree); - super.visitWhileLoop(tree); - } - - @Override - public void visitForLoop(JCTree.JCForLoop tree) { - seenTrees.add(tree); - super.visitForLoop(tree); - } - - @Override - public void visitForeachLoop(JCTree.JCEnhancedForLoop tree) { - seenTrees.add(tree); - super.visitForeachLoop(tree); - } - - @Override - public void visitDoLoop(JCTree.JCDoWhileLoop tree) { - seenTrees.add(tree); - super.visitDoLoop(tree); + public SnippetBreakToAnalyzer(JCTree breakTo) { + this.breakTo = breakTo; } @Override public void visitBreak(JCBreak tree) { - breaksOut |= (super.alive == Liveness.ALIVE && - !seenTrees.contains(tree.target)); - super.visitBreak(tree); + breaksTo |= breakTo == tree.target && super.alive == Liveness.ALIVE; } - public boolean breaksOut() { - return breaksOut; + public boolean breaksTo() { + return breaksTo; } } diff --git a/test/langtools/tools/javac/patterns/BindingsTest1.java b/test/langtools/tools/javac/patterns/BindingsTest1.java index 1c6df9de87f..d9693fc4c67 100644 --- a/test/langtools/tools/javac/patterns/BindingsTest1.java +++ b/test/langtools/tools/javac/patterns/BindingsTest1.java @@ -231,6 +231,67 @@ public void run() { throw new AssertionError(); } + { + L: { + while (!(o1 instanceof String s)) { + break L; + } + + s.length(); + } + } + + { + L: { + for (; !(o1 instanceof String s); ) { + break L; + } + + s.length(); + } + } + + { + int j = 0; + L: while (j++ < 2) + if (!(o1 instanceof String s)) { + break L; + } + } + + { + int j = 0; + L: for (; j++ < 2; ) + if (!(o1 instanceof String s)) { + break L; + } + } + + { + //"s" in the outter scope does not flow out of the if, but + //variables inside a lambda or anonymous or local class may: + L: if (!(o1 instanceof String s)) { + Runnable r = () -> { + NESTED: { + if (!(o1 instanceof String n)) { + break NESTED; + } + + n.length(); + } + }; + break L; + } + } + + switch (0) { + case 0: + if (!(o1 instanceof String s)) { + break; + } + s.length(); + } + //binding in an anonymous class: if (!(invokeOnce("") instanceof String s)) { throw new AssertionError(); diff --git a/test/langtools/tools/javac/patterns/BindingsTest2.java b/test/langtools/tools/javac/patterns/BindingsTest2.java index b9bd372ddc8..c4b1f4d958c 100644 --- a/test/langtools/tools/javac/patterns/BindingsTest2.java +++ b/test/langtools/tools/javac/patterns/BindingsTest2.java @@ -247,5 +247,62 @@ public static void meth() { s = ""; } } + { + LBL1: LBL2: if (!(o1 instanceof String s)) { + break LBL1; + } + + System.err.println(s); + } + { + LBL1: LBL2: if (!(o1 instanceof String s)) { + break LBL2; + } + + System.err.println(s); + } + { + LBL1: LBL2: if (o1 instanceof String s) { + } else { + break LBL1; + } + + System.err.println(s); + } + { + LBL1: LBL2: if (o1 instanceof String s) { + } else { + break LBL2; + } + + System.err.println(s); + } + { + switch (0) { + case 0: + if (!(o1 instanceof String s)) { + break; + } + } + s.length(); + } + + { + int j = 0; + L: while (j++ < 2) + if (!(o1 instanceof String s)) { + break L; + } + s.length(); + } + + { + int j = 0; + L: for (; j++ < 2; ) + if (!(o1 instanceof String s)) { + break L; + } + s.length(); + } } } diff --git a/test/langtools/tools/javac/patterns/BindingsTest2.out b/test/langtools/tools/javac/patterns/BindingsTest2.out index b42dededfdf..0695c3c9b41 100644 --- a/test/langtools/tools/javac/patterns/BindingsTest2.out +++ b/test/langtools/tools/javac/patterns/BindingsTest2.out @@ -43,11 +43,16 @@ BindingsTest2.java:179:13: compiler.err.cant.resolve.location: kindname.variable BindingsTest2.java:196:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:204:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:212:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) -BindingsTest2.java:221:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) -BindingsTest2.java:231:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) -BindingsTest2.java:241:17: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:247:17: compiler.err.cant.assign.val.to.var: final, s +BindingsTest2.java:255:32: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:262:32: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:270:32: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:278:32: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:287:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:296:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) +BindingsTest2.java:305:13: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, BindingsTest2, null) BindingsTest2.java:135:17: compiler.err.unreachable.stmt BindingsTest2.java:160:17: compiler.err.unreachable.stmt BindingsTest2.java:185:17: compiler.err.unreachable.stmt -52 errors +BindingsTest2.java:241:17: compiler.err.unreachable.stmt +57 errors \ No newline at end of file diff --git a/test/langtools/tools/javac/patterns/BreakAndLoops.java b/test/langtools/tools/javac/patterns/BreakAndLoops.java index 0c19fcbf35d..31ad8908f53 100644 --- a/test/langtools/tools/javac/patterns/BreakAndLoops.java +++ b/test/langtools/tools/javac/patterns/BreakAndLoops.java @@ -104,6 +104,17 @@ protected void doWork() throws Throwable { shouldPass = true; } else if (innerLoop.supportsAnonymousBreak && brk == Break.BREAK) { shouldPass = true; + } else if (outterLabel == OutterLabel.LABEL && brk == Break.BREAK_LABEL && outterLoop != OutterLoop.NONE) { + shouldPass = switch(mainLoop) { + case WHILE, FOR -> true; + case DO_WHILE -> switch (innerLoop) { + case WHILE, FOR, FOR_EACH -> true; + //the statement following the do-while is unreachable: + case BLOCK, DO_WHILE, NONE -> { + yield false; + } + }; + }; } else { shouldPass = false; } From 41b14abc8ce0915bf9a65808adddf7059e680948 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 21 Jun 2023 09:16:12 +0000 Subject: [PATCH 07/19] 8310133: Effectivelly final condition not enforced in guards for binding variables from the same case Reviewed-by: vromero --- .../share/classes/com/sun/tools/javac/comp/Flow.java | 7 ++++++- test/langtools/tools/javac/patterns/GuardsErrors.java | 5 ++++- test/langtools/tools/javac/patterns/GuardsErrors.out | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index c2b02650693..ff77c9cdf18 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -3202,7 +3202,7 @@ void markDead() { void checkEffectivelyFinal(DiagnosticPosition pos, VarSymbol sym) { if (currentTree != null && sym.owner.kind == MTH && - sym.pos < currentTree.getStartPosition()) { + sym.pos < getCurrentTreeStartPosition()) { switch (currentTree.getTag()) { case CLASSDEF: case CASE: @@ -3214,6 +3214,11 @@ void checkEffectivelyFinal(DiagnosticPosition pos, VarSymbol sym) { } } + int getCurrentTreeStartPosition() { + return currentTree instanceof JCCase cse ? cse.guard.getStartPosition() + : currentTree.getStartPosition(); + } + @SuppressWarnings("fallthrough") void letInit(JCTree tree) { tree = TreeInfo.skipParens(tree); diff --git a/test/langtools/tools/javac/patterns/GuardsErrors.java b/test/langtools/tools/javac/patterns/GuardsErrors.java index 788c46e4e14..3beb9d5741f 100644 --- a/test/langtools/tools/javac/patterns/GuardsErrors.java +++ b/test/langtools/tools/javac/patterns/GuardsErrors.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8262891 + * @bug 8262891 8310133 * @summary Check errors reported for guarded patterns. * @compile/fail/ref=GuardsErrors.out -XDrawDiagnostics GuardsErrors.java */ @@ -54,6 +54,9 @@ public boolean test() { return i == 2; } }.test() -> {} + case Integer v when v != null -> { + v = null; + } case Number v1 when v1 instanceof Integer v2 && (v2 = 0) == 0 -> {} default -> {} } diff --git a/test/langtools/tools/javac/patterns/GuardsErrors.out b/test/langtools/tools/javac/patterns/GuardsErrors.out index a87e4f1867c..2e42efc412f 100644 --- a/test/langtools/tools/javac/patterns/GuardsErrors.out +++ b/test/langtools/tools/javac/patterns/GuardsErrors.out @@ -2,5 +2,6 @@ GuardsErrors.java:36:38: compiler.err.cant.ref.non.effectively.final.var: check, GuardsErrors.java:47:34: compiler.err.cannot.assign.not.declared.guard: i1 GuardsErrors.java:48:33: compiler.err.cant.ref.non.effectively.final.var: i2, (compiler.misc.guard) GuardsErrors.java:49:35: compiler.err.cant.ref.non.effectively.final.var: i2, (compiler.misc.guard) -GuardsErrors.java:64:34: compiler.err.cannot.assign.not.declared.guard: f -5 errors +GuardsErrors.java:57:33: compiler.err.cant.ref.non.effectively.final.var: v, (compiler.misc.guard) +GuardsErrors.java:67:34: compiler.err.cannot.assign.not.declared.guard: f +6 errors From a19176d2d35833452623f7a4fb0a039f0b4b7804 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Wed, 21 Jun 2023 09:57:26 +0000 Subject: [PATCH 08/19] 8310369: UTIL_ARG_WITH fails when arg is disabled Reviewed-by: mikael --- make/autoconf/util.m4 | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/make/autoconf/util.m4 b/make/autoconf/util.m4 index 83349aea99d..349a04a089e 100644 --- a/make/autoconf/util.m4 +++ b/make/autoconf/util.m4 @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2023, 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 @@ -509,7 +509,7 @@ AC_DEFUN([UTIL_CHECK_TYPE_directory], FAILURE="Directory $1 does not exist or is not readable" fi - if test "[x]ARG_CHECK_FOR_FILES" != x; then + if test "[x]ARG_CHECK_FOR_FILES" != "x:"; then for file in ARG_CHECK_FOR_FILES; do found_files=$($ECHO $(ls $1/$file 2> /dev/null)) if test "x$found_files" = x; then @@ -781,25 +781,25 @@ UTIL_DEFUN_NAMED([UTIL_ARG_WITH], else AC_MSG_RESULT([$ARG_RESULT, $REASON]) fi - fi - # Verify value - # First use our dispatcher to verify that type requirements are satisfied - UTIL_CHECK_TYPE(ARG_TYPE, $ARG_RESULT) + # Verify value + # First use our dispatcher to verify that type requirements are satisfied + UTIL_CHECK_TYPE(ARG_TYPE, $ARG_RESULT) - if test "x$FAILURE" = x; then - # Execute custom verification payload, if present - RESULT="$ARG_RESULT" + if test "x$FAILURE" = x; then + # Execute custom verification payload, if present + RESULT="$ARG_RESULT" - ARG_CHECK_VALUE + ARG_CHECK_VALUE - ARG_RESULT="$RESULT" - fi + ARG_RESULT="$RESULT" + fi - if test "x$FAILURE" != x; then - AC_MSG_NOTICE([Invalid value for [--with-]ARG_NAME: "$ARG_RESULT"]) - AC_MSG_NOTICE([$FAILURE]) - AC_MSG_ERROR([Cannot continue]) + if test "x$FAILURE" != x; then + AC_MSG_NOTICE([Invalid value for [--with-]ARG_NAME: "$ARG_RESULT"]) + AC_MSG_NOTICE([$FAILURE]) + AC_MSG_ERROR([Cannot continue]) + fi fi # Execute result payloads, if present From 26a722661ba240320808e6f98b418f6bee2fc58b Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Wed, 21 Jun 2023 09:57:49 +0000 Subject: [PATCH 09/19] 8310376: Extend SetupTarget macro with DIR parameter Reviewed-by: mikael --- make/MainSupport.gmk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/make/MainSupport.gmk b/make/MainSupport.gmk index 34137c502d4..8c575423005 100644 --- a/make/MainSupport.gmk +++ b/make/MainSupport.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -38,11 +38,16 @@ _MAINSUPPORT_GMK := 1 # TARGET the makefile target # ARGS arguments to the makefile # DEPS the target(s) this new rule depends on +# DIR the directory of the makefile (defaults to $(TOPDIR)/make) # SetupTarget = $(NamedParamsMacroTemplate) define SetupTargetBody + ifeq ($$($1_DIR), ) + $1_DIR := $(TOPDIR)/make + endif + $1: - +($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f $$($1_MAKEFILE).gmk $$($1_TARGET) $$($1_ARGS)) + +($(CD) $$($1_DIR) && $(MAKE) $(MAKE_ARGS) -f $$($1_MAKEFILE).gmk $$($1_TARGET) $$($1_ARGS)) ALL_TARGETS += $1 From 4543fbb6f4841f5ec50908ec4bf6c9d651e8362b Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Wed, 21 Jun 2023 11:45:37 +0000 Subject: [PATCH 10/19] 8310297: assert(static_cast(result) == thing) with ctw Reviewed-by: iklam, dholmes --- .../ConstantPool/ByteFieldInitTest.java | 55 +++++++++++++++++++ .../ConstantPool/CompatByteFieldInit.jasm | 38 +++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 test/hotspot/jtreg/runtime/ConstantPool/ByteFieldInitTest.java create mode 100644 test/hotspot/jtreg/runtime/ConstantPool/CompatByteFieldInit.jasm diff --git a/test/hotspot/jtreg/runtime/ConstantPool/ByteFieldInitTest.java b/test/hotspot/jtreg/runtime/ConstantPool/ByteFieldInitTest.java new file mode 100644 index 00000000000..59f48342213 --- /dev/null +++ b/test/hotspot/jtreg/runtime/ConstantPool/ByteFieldInitTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, 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 8310297 + * @summary Negative fields shorter than an int may not be sign extended in cpool + * but should in static field initializers. javac gives an error for this but + * not other sources of bytecodes. With checked_cast<> this crashes. + * @compile CompatByteFieldInit.jasm + * @run main ByteFieldInitTest + */ + +import java.lang.reflect.Field; + +public class ByteFieldInitTest { + + final static byte b = -128; // compare with 0x80 + final static short s = -32768; // compare with 0x8000 + + public static void main(java.lang.String[] unused) throws Exception { + // javac is smart enough to complain about the other class's byte and short values when referred + // to directly. With checked_cast<> loading this class should fail. + Class c = Class.forName("CompatByteFieldInit"); + Field cb = c.getDeclaredField("b"); + Field cs = c.getDeclaredField("s"); + if (b != cb.getByte(null) || s != cs.getShort(null)) { + throw new RuntimeException("constant pool init not compatible " + cb.getByte(null) + " " + cs.getShort(null)); + } else { + System.out.println("Fields are same test passed"); + } + } +} + + diff --git a/test/hotspot/jtreg/runtime/ConstantPool/CompatByteFieldInit.jasm b/test/hotspot/jtreg/runtime/ConstantPool/CompatByteFieldInit.jasm new file mode 100644 index 00000000000..b2420a9ecc3 --- /dev/null +++ b/test/hotspot/jtreg/runtime/ConstantPool/CompatByteFieldInit.jasm @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, 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. + */ + + +super class CompatByteFieldInit + version 65:0 +{ + public static final Field b:B = int 0x80; + public static final Field s:S = int 0x8000; + + Method "":"()V" + stack 1 locals 1 + { + aload_0; + invokespecial Method java/lang/Object."":"()V"; + return; + } +} // end Class CompatByteFieldInit From 7856c967166d21aad8f4a8fe5379a12a73300ebc Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Wed, 21 Jun 2023 11:47:25 +0000 Subject: [PATCH 11/19] 8309296: jdk/jfr/event/runtime/TestAgentEvent.java fails due to "missing" dynamic JavaAgent Reviewed-by: mgronlun --- .../jdk/jfr/event/runtime/TestAgentEvent.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/test/jdk/jdk/jfr/event/runtime/TestAgentEvent.java b/test/jdk/jdk/jfr/event/runtime/TestAgentEvent.java index a457b417a90..3bba83ffbe4 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestAgentEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestAgentEvent.java @@ -27,6 +27,7 @@ import java.security.Timestamp; import java.time.Duration; import java.time.Instant; +import java.util.Comparator; import java.util.List; import com.sun.tools.attach.VirtualMachine; @@ -35,6 +36,7 @@ import jdk.jfr.consumer.RecordedClassLoader; import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.Event; +import jdk.jfr.StackTrace; import jdk.test.lib.Asserts; import jdk.test.lib.jfr.EventNames; import jdk.test.lib.jfr.Events; @@ -55,19 +57,22 @@ * jdk.jfr.event.runtime.JavaAgent * JavaAgent.jar * - * @run main/othervm -javaagent:JavaAgent.jar=foo=bar + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -javaagent:JavaAgent.jar=foo=bar * jdk.jfr.event.runtime.TestAgentEvent * testJavaStatic * - * @run main/othervm -Djdk.attach.allowAttachSelf=true + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -Djdk.attach.allowAttachSelf=true * jdk.jfr.event.runtime.TestAgentEvent * testJavaDynamic * - * @run main/othervm -agentlib:jdwp=transport=dt_socket,server=y,address=any,onjcmd=y + * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -agentlib:jdwp=transport=dt_socket,server=y,address=any,onjcmd=y * jdk.jfr.event.runtime.TestAgentEvent * testNativeStatic */ public final class TestAgentEvent { + @StackTrace(false) + static class RecordingInterval extends Event { + } private static final String JAVA_AGENT_JAR = "JavaAgent.jar"; public static void main(String[] args) throws Throwable { @@ -81,17 +86,22 @@ public static void main(String[] args) throws Throwable { private static void testJavaStatic() throws Throwable { try (Recording r = new Recording()) { - r.enable(EventNames.JavaAgent); + r.enable(EventNames.JavaAgent).with("period", "endChunk"); r.start(); + RecordingInterval intervalEvent = new RecordingInterval(); + intervalEvent.commit(); r.stop(); List events = Events.fromRecording(r); - RecordedEvent e = events.get(0); + events.sort(Comparator.comparing(RecordedEvent::getEndTime)); + RecordedEvent interval = events.getFirst(); + System.out.println(interval); + RecordedEvent e = events.get(1); System.out.println(e); Events.assertField(e, "name").equal(JAVA_AGENT_JAR); Events.assertField(e, "options").equal("foo=bar"); Events.assertField(e, "dynamic").equal(false); Instant initializationTime = e.getInstant("initializationTime"); - if (initializationTime.isAfter(r.getStartTime())) { + if (initializationTime.isAfter(interval.getStartTime())) { throw new Exception("Expected a static JavaAgent to be initialized before recording start"); } Events.assertField(e, "initializationDuration").atLeast(0L); @@ -100,17 +110,22 @@ private static void testJavaStatic() throws Throwable { private static void testNativeStatic() throws Throwable { try (Recording r = new Recording()) { - r.enable(EventNames.NativeAgent); + r.enable(EventNames.NativeAgent).with("period", "endChunk"); r.start(); + RecordingInterval intervalEvent = new RecordingInterval(); + intervalEvent.commit(); r.stop(); List events = Events.fromRecording(r); - RecordedEvent e = events.get(0); + events.sort(Comparator.comparing(RecordedEvent::getEndTime)); + RecordedEvent interval = events.getFirst(); + System.out.println(interval); + RecordedEvent e = events.get(1); System.out.println(e); Events.assertField(e, "name").equal("jdwp"); Events.assertField(e, "options").equal("transport=dt_socket,server=y,address=any,onjcmd=y"); Events.assertField(e, "dynamic").equal(false); Instant initializationTime = e.getInstant("initializationTime"); - if (initializationTime.isAfter(r.getStartTime())) { + if (initializationTime.isAfter(interval.getStartTime())) { throw new Exception("Expected a static NativeAgent to be initialized before recording start"); } Events.assertField(e, "initializationDuration").atLeast(0L); @@ -119,8 +134,10 @@ private static void testNativeStatic() throws Throwable { private static void testJavaDynamic() throws Throwable { try (Recording r = new Recording()) { - r.enable(EventNames.JavaAgent); + r.enable(EventNames.JavaAgent).with("period", "endChunk"); r.start(); + RecordingInterval intervalEvent = new RecordingInterval(); + intervalEvent.begin(); long pid = ProcessHandle.current().pid(); VirtualMachine vm = VirtualMachine.attach(Long.toString(pid)); vm.loadAgent(JAVA_AGENT_JAR, "bar=baz"); @@ -132,15 +149,19 @@ private static void testJavaDynamic() throws Throwable { vm.loadAgent(JAVA_AGENT_JAR, ""); vm.loadAgent(JAVA_AGENT_JAR, "="); vm.detach(); + intervalEvent.commit(); r.stop(); List events = Events.fromRecording(r); - for (RecordedEvent e : events) { + events.sort(Comparator.comparing(RecordedEvent::getEndTime)); + RecordedEvent interval = events.getFirst(); + System.out.println(interval); + for (RecordedEvent e : events.subList(1, events.size())) { System.out.println(e); Instant initializationTime = e.getInstant("initializationTime"); - if (initializationTime.isBefore(r.getStartTime())) { + if (initializationTime.isBefore(interval.getStartTime())) { throw new Exception("Expected a dynamic JavaAgent to be initialized after recording start"); } - if (initializationTime.isAfter(r.getStopTime())) { + if (initializationTime.isAfter(interval.getEndTime())) { throw new Exception("Expected a dynamic JavaAgent to be initialized before recording stop"); } Duration initializationDuration = e.getDuration("initializationDuration"); @@ -152,10 +173,10 @@ private static void testJavaDynamic() throws Throwable { } Events.assertField(e, "name").equal(JAVA_AGENT_JAR); } - Events.assertField(events.get(0), "options").equal("bar=baz"); - Events.assertField(events.get(1), "options").equal(null); - Events.assertField(events.get(2), "options").equal(""); - Events.assertField(events.get(3), "options").equal("="); + Events.assertField(events.get(1), "options").equal("bar=baz"); + Events.assertField(events.get(2), "options").equal(null); + Events.assertField(events.get(3), "options").equal(""); + Events.assertField(events.get(4), "options").equal("="); } } } From 7d094c78a8dd5cb46763391bb68e9c876d9f93c3 Mon Sep 17 00:00:00 2001 From: Damon Fenacci Date: Wed, 21 Jun 2023 12:27:02 +0000 Subject: [PATCH 12/19] 8264899: C1: -XX:AbortVMOnException does not work if all methods in the call stack are compiled with C1 and there are no exception handlers Reviewed-by: thartmann, amitkumar, fyang, mdoerr --- .../ErrorHandling/TestAbortVmOnException.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/hotspot/jtreg/runtime/ErrorHandling/TestAbortVmOnException.java diff --git a/test/hotspot/jtreg/runtime/ErrorHandling/TestAbortVmOnException.java b/test/hotspot/jtreg/runtime/ErrorHandling/TestAbortVmOnException.java new file mode 100644 index 00000000000..447b690fa02 --- /dev/null +++ b/test/hotspot/jtreg/runtime/ErrorHandling/TestAbortVmOnException.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023, 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 TestAbortVmOnException + * @summary Test -XX:AbortVMOnException=MyAbortException with C1 compilation + * @library /test/lib + * @run driver TestAbortVmOnException + * @bug 8264899 + */ + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +import java.io.IOException; + + +public class TestAbortVmOnException { + + public static void main(String[] args) throws Exception { + if (args.length == 1) { + if (args[0].equals("throwExceptionWithMessage")) { + throw new MyAbortException("MyExceptionMessage"); + } else { + throw new MyAbortException(); + } + } + // Run process throwing MyException + Process myExceptionThrowingProcess = runProcess( "MyAbortException", false, null); + parseOutput(myExceptionThrowingProcess, "fatal error: Saw MyAbortException, aborting"); + // Run process throwing MyException with message + Process myExceptionThrowingWithMessageProcess = runProcess( "MyAbortException", true, null); + parseOutput(myExceptionThrowingWithMessageProcess, "fatal error: Saw MyAbortException: MyExceptionMessage, aborting"); + // Run process throwing MyException with message and check message + Process myExceptionThrowingWithMessageCheckProcess = runProcess( "MyAbortException", true, "MyExceptionMessage"); + parseOutput(myExceptionThrowingWithMessageCheckProcess, "fatal error: Saw MyAbortException: MyExceptionMessage, aborting"); + System.out.println("PASSED"); + } + + private static Process runProcess(String exceptionName, boolean withMessage, String exceptionMessage) throws IOException { + if (exceptionMessage == null) { + return ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:AbortVMOnException=" + exceptionName, "-Xcomp", "-Xbatch", "-XX:TieredStopAtLevel=3", TestAbortVmOnException.class.getName(), + withMessage ? "throwExceptionWithMessage" : "throwException").start(); + } else { + return ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", + "-XX:AbortVMOnException=" + exceptionName, "-XX:AbortVMOnExceptionMessage=" + exceptionMessage, + "-Xcomp", "-Xbatch", "-XX:TieredStopAtLevel=3", TestAbortVmOnException.class.getName(), + withMessage ? "throwExceptionWithMessage" : "throwException").start(); + } + } + + private static void parseOutput(Process process, String expectedString) throws IOException { + OutputAnalyzer output = new OutputAnalyzer(process); + output.stdoutShouldNotBeEmpty(); + output.shouldContain(expectedString); + } + +} + +class MyAbortException extends RuntimeException { + public MyAbortException() { + super(); + } + + public MyAbortException(String message) { + super(message); + } +} From 1a58ac88cf5e688e53dcd0ac552f0ae5ceef02e7 Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Wed, 21 Jun 2023 15:07:42 +0000 Subject: [PATCH 13/19] 8310335: JFR: Modernize collections and switch statements Reviewed-by: mgronlun --- .../classes/jdk/jfr/ValueDescriptor.java | 2 +- .../jdk/jfr/consumer/RecordedObject.java | 276 ++++++------------ .../jfr/consumer/snippet-files/Snippets.java | 4 +- .../jfr/internal/EventInstrumentation.java | 2 +- .../classes/jdk/jfr/internal/FilePurger.java | 9 +- .../jdk/jfr/internal/MetadataReader.java | 4 +- .../jdk/jfr/internal/PlatformRecorder.java | 2 +- .../jdk/jfr/internal/PlatformRecording.java | 2 +- .../internal/consumer/CompositeParser.java | 4 +- .../jdk/jfr/internal/dcmd/ArgumentParser.java | 4 +- .../classes/jdk/jfr/internal/jfc/JFC.java | 23 +- .../jfr/internal/jfc/model/XmlElement.java | 4 +- .../jdk/jfr/internal/jfc/model/XmlNot.java | 4 +- .../jfr/internal/jfc/model/XmlSelection.java | 4 +- .../jdk/jfr/internal/jfc/model/XmlTest.java | 4 +- .../jdk/jfr/internal/query/FieldBuilder.java | 8 +- .../jdk/jfr/internal/query/TableRenderer.java | 2 +- .../jdk/jfr/internal/query/ViewFile.java | 3 +- .../jdk/jfr/internal/tool/Command.java | 2 +- .../jdk/jfr/internal/tool/Disassemble.java | 2 +- .../jdk/jfr/internal/tool/Filters.java | 2 +- .../jdk/jfr/internal/tool/PrettyWriter.java | 4 +- .../jdk/jfr/api/consumer/TestFieldAccess.java | 4 +- .../api/consumer/TestMethodGetModifiers.java | 4 +- .../jfr/api/consumer/TestRecordedEvent.java | 4 +- .../consumer/TestRecordedEventGetThread.java | 4 +- .../TestRecordedEventGetThreadOther.java | 4 +- .../jfr/api/consumer/TestRecordedFrame.java | 4 +- .../consumer/TestRecordedFullStackTrace.java | 4 +- .../TestRecordedInstantEventTimestamp.java | 4 +- .../TestRecordedMethodDescriptor.java | 4 +- .../jfr/api/consumer/TestRecordedObject.java | 4 +- .../api/consumer/TestSingleRecordedEvent.java | 4 +- .../jdk/jfr/api/consumer/TestToString.java | 4 +- .../consumer/TestValueDescriptorRecorded.java | 4 +- .../recordingstream/TestOnMetadata.java | 4 +- .../recordingstream/TestStoppedRecording.java | 4 +- .../jdk/jfr/api/event/TestEventDuration.java | 4 +- .../event/dynamic/TestDynamicAnnotations.java | 6 +- .../jfr/api/flightrecorder/TestSnapshot.java | 8 +- .../api/metadata/annotations/TestName.java | 4 +- .../eventtype/TestGetAnnotationElements.java | 6 +- .../metadata/eventtype/TestGetCategory.java | 4 +- .../metadata/eventtype/TestGetSettings.java | 4 +- .../valuedescriptor/TestConstructor.java | 4 +- .../test.jfr.main/test/jfr/main/MainTest.java | 4 +- .../destination/TestDestFileExist.java | 4 +- .../destination/TestDestInvalid.java | 4 +- .../destination/TestDestLongPath.java | 4 +- .../destination/TestDestReadOnly.java | 4 +- .../recording/destination/TestDestState.java | 4 +- .../destination/TestDestToDiskFalse.java | 4 +- .../destination/TestDestToDiskTrue.java | 4 +- .../destination/TestDestWithDuration.java | 4 +- .../api/recording/dump/TestDumpLongPath.java | 4 +- .../api/recording/event/TestChunkPeriod.java | 6 +- .../api/recording/misc/TestRecordingCopy.java | 4 +- .../event/compiler/TestCodeCacheConfig.java | 4 +- .../jfr/event/compiler/TestCodeCacheFull.java | 4 +- .../jfr/event/diagnostics/TestHeapDump.java | 2 +- .../jfr/event/gc/collection/TestSystemGC.java | 4 +- .../GCHeapConfigurationEventTester.java | 4 +- ...ungGenerationConfigurationEventTester.java | 4 +- .../TestGCConfigurationEvent.java | 4 +- ...figurationEventWithDefaultPauseTarget.java | 4 +- .../TestGCSurvivorConfigurationEvent.java | 4 +- .../TestGCTLABConfigurationEvent.java | 4 +- .../gc/detailed/StressAllocationGCEvents.java | 4 +- .../TestGCHeapMemoryPoolUsageEvent.java | 2 +- .../detailed/TestGCHeapMemoryUsageEvent.java | 2 +- .../event/gc/detailed/TestGCLockerEvent.java | 2 +- .../event/io/TestDeserializationEvent.java | 26 +- .../event/profiling/TestFullStackTrace.java | 6 +- .../runtime/TestActiveRecordingEvent.java | 2 +- .../TestClassLoadingStatisticsEvent.java | 4 +- .../event/runtime/TestClassRedefinition.java | 4 +- .../event/runtime/TestExceptionEvents.java | 4 +- .../runtime/TestNativeMemoryUsageEvents.java | 6 +- .../event/runtime/TestRedefineClasses.java | 4 +- .../event/runtime/TestRetransformClasses.java | 4 +- .../jfr/event/runtime/TestShutdownEvent.java | 4 +- test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java | 4 +- .../jdk/jdk/jfr/jcmd/TestJcmdDumpLimited.java | 6 +- .../jfr/jcmd/TestJcmdStartPathToGCRoots.java | 4 +- .../TestPredefinedConfigurationInvalid.java | 4 +- test/jdk/jdk/jfr/jmx/TestSnapshot.java | 6 +- test/jdk/jdk/jfr/jvm/TestDumpOnCrash.java | 4 +- .../jdk/jdk/jfr/jvm/TestPrimitiveClasses.java | 2 +- .../jdk/jfr/startupargs/StartupHelper.java | 4 +- .../jfr/startupargs/TestEventSettings.java | 4 +- .../threading/TestNestedVirtualThreads.java | 4 +- 91 files changed, 275 insertions(+), 400 deletions(-) diff --git a/src/jdk.jfr/share/classes/jdk/jfr/ValueDescriptor.java b/src/jdk.jfr/share/classes/jdk/jfr/ValueDescriptor.java index aeff81e41f5..b3c52d078e5 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/ValueDescriptor.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/ValueDescriptor.java @@ -251,7 +251,7 @@ public String getContentType() { */ public String getTypeName() { if (type.isSimpleType()) { - return type.getFields().get(0).getTypeName(); + return type.getFields().getFirst().getTypeName(); } return type.getName(); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java b/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java index bc9f443b5c3..7fa2250b77f 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordedObject.java @@ -464,7 +464,6 @@ public final char getChar(String name) { if (o instanceof Character c) { return c; } - throw newIllegalArgumentException(name, "char"); } @@ -495,23 +494,13 @@ public final char getChar(String name) { * @see #getValue(String) */ public final short getShort(String name) { - Object o = getValue(name, true); - if (o instanceof Short s) { - return s; - } - if (o instanceof Byte b) { - return b; - } - if (o instanceof UnsignedValue unsigned) { - Object u = unsigned.value(); - if (u instanceof Short s) { - return s; - } - if (u instanceof Byte b) { - return (short) Byte.toUnsignedInt(b); - } - } - throw newIllegalArgumentException(name, "short"); + return switch (getValue(name, true)) { + case Short s -> s; + case Byte b -> b; + case UnsignedValue(Short s) -> s; + case UnsignedValue(Byte b) -> (short) Byte.toUnsignedInt(b); + case null, default -> throw newIllegalArgumentException(name, "short"); + }; } /** @@ -542,32 +531,16 @@ public final short getShort(String name) { * @see #getValue(String) */ public final int getInt(String name) { - Object o = getValue(name, true); - if (o instanceof Integer i) { - return i; - } - if (o instanceof Short s) { - return s; - } - if (o instanceof Character c) { - return c; - } - if (o instanceof Byte b) { - return b; - } - if (o instanceof UnsignedValue unsigned) { - Object u = unsigned.value(); - if (u instanceof Integer i) { - return i; - } - if (u instanceof Short s) { - return Short.toUnsignedInt(s); - } - if (u instanceof Byte b) { - return Byte.toUnsignedInt(b); - } - } - throw newIllegalArgumentException(name, "int"); + return switch(getValue(name, true)) { + case Integer i -> i; + case Short s -> s; + case Character c -> c; + case Byte b -> b; + case UnsignedValue(Integer i) -> i; + case UnsignedValue(Short s) -> Short.toUnsignedInt(s); + case UnsignedValue(Byte b) -> Byte.toUnsignedInt(b); + case null, default -> throw newIllegalArgumentException(name, "short"); + }; } /** @@ -595,26 +568,15 @@ public final int getInt(String name) { * @see #getValue(String) */ public final float getFloat(String name) { - Object o = getValue(name); - if (o instanceof Float f) { - return f; - } - if (o instanceof Long l) { - return l; - } - if (o instanceof Integer i) { - return i; - } - if (o instanceof Short s) { - return s; - } - if (o instanceof Byte b) { - return b; - } - if (o instanceof Character c) { - return c; - } - throw newIllegalArgumentException(name, "float"); + return switch(getValue(name)) { + case Float f -> f; + case Long l -> l; + case Integer i -> i; + case Short s -> s; + case Character c -> c; + case Byte b -> b; + case null, default -> throw newIllegalArgumentException(name, "float"); + }; } /** @@ -645,35 +607,17 @@ public final float getFloat(String name) { * @see #getValue(String) */ public final long getLong(String name) { - Object o = getValue(name, true); - if (o instanceof Long l) { - return l; - } - if (o instanceof Integer i) { - return i; - } - if (o instanceof Short s) { - return s; - } - if (o instanceof Character c) { - return c; - } - if (o instanceof Byte b) { - return b.longValue(); - } - if (o instanceof UnsignedValue unsigned) { - Object u = unsigned.value(); - if (u instanceof Integer i) { - return Integer.toUnsignedLong(i); - } - if (u instanceof Short s) { - return Short.toUnsignedLong(s); - } - if (u instanceof Byte b) { - return Byte.toUnsignedLong(b); - } - } - throw newIllegalArgumentException(name, "long"); + return switch(getValue(name, true)) { + case Long l -> l; + case Integer i -> i; + case Short s -> s; + case Character c -> c; + case Byte b -> b; + case UnsignedValue(Integer i) -> Integer.toUnsignedLong(i); + case UnsignedValue(Short s) -> Short.toUnsignedLong(s); + case UnsignedValue(Byte b) -> Byte.toUnsignedLong(b); + case null, default -> throw newIllegalArgumentException(name, "long"); + }; } /** @@ -701,29 +645,16 @@ public final long getLong(String name) { * @see #getValue(String) */ public final double getDouble(String name) { - Object o = getValue(name); - if (o instanceof Double d) { - return d.doubleValue(); - } - if (o instanceof Float f) { - return f.doubleValue(); - } - if (o instanceof Long l) { - return l.doubleValue(); - } - if (o instanceof Integer i) { - return i.doubleValue(); - } - if (o instanceof Short s) { - return s.doubleValue(); - } - if (o instanceof Byte b) { - return b.doubleValue(); - } - if (o instanceof Character c) { - return c; - } - throw newIllegalArgumentException(name, "double"); + return switch(getValue(name)) { + case Double d -> d; + case Float f -> f; + case Long l -> l.doubleValue(); + case Integer i -> i.doubleValue(); + case Short s -> s.doubleValue(); + case Character c -> c; + case Byte b -> b.doubleValue(); + case null, default -> throw newIllegalArgumentException(name, "double"); + }; } /** @@ -777,35 +708,17 @@ public final String getString(String name) { * @see #getValue(String) */ public final Duration getDuration(String name) { - Object o = getValue(name); - if (o instanceof Long l) { - return getDuration(l, name); - } - if (o instanceof Integer i) { - return getDuration(i, name); - } - if (o instanceof Short s) { - return getDuration(s, name); - } - if (o instanceof Character c) { - return getDuration(c, name); - } - if (o instanceof Byte b) { - return getDuration(b, name); - } - if (o instanceof UnsignedValue unsigned) { - Object u = unsigned.value(); - if (u instanceof Integer i) { - return getDuration(Integer.toUnsignedLong(i), name); - } - if (u instanceof Short s) { - return getDuration(Short.toUnsignedLong(s), name); - } - if (u instanceof Byte b) { - return getDuration(Short.toUnsignedLong(b), name); - } - } - throw newIllegalArgumentException(name, "java.time.Duration"); + return switch (getValue(name, true)) { + case Long l -> getDuration(l, name); + case Integer i -> getDuration(i,name); + case Short s -> getDuration(s, name); + case Character c -> getDuration(c, name); + case Byte b -> getDuration(b, name); + case UnsignedValue(Integer i) -> getDuration(Integer.toUnsignedLong(i), name); + case UnsignedValue(Short s) -> getDuration(Short.toUnsignedLong(s), name); + case UnsignedValue(Byte b) -> getDuration(Short.toUnsignedLong(b), name); + case null, default -> throw newIllegalArgumentException(name, "java.time.Duration"); + }; } private Duration getDuration(long timespan, String name) { @@ -821,19 +734,14 @@ private Duration getDuration(long timespan, String name) { } Timespan ts = v.getAnnotation(Timespan.class); if (ts != null) { - switch (ts.value()) { - case Timespan.MICROSECONDS: - return Duration.ofNanos(1000 * timespan); - case Timespan.SECONDS: - return Duration.ofSeconds(timespan); - case Timespan.MILLISECONDS: - return Duration.ofMillis(timespan); - case Timespan.NANOSECONDS: - return Duration.ofNanos(timespan); - case Timespan.TICKS: - return Duration.ofNanos(objectContext.convertTimespan(timespan)); - } - throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value()); + return switch (ts.value()) { + case Timespan.MICROSECONDS -> Duration.ofNanos(1000 * timespan); + case Timespan.SECONDS -> Duration.ofSeconds(timespan); + case Timespan.MILLISECONDS -> Duration.ofMillis(timespan); + case Timespan.NANOSECONDS -> Duration.ofNanos(timespan); + case Timespan.TICKS -> Duration.ofNanos(objectContext.convertTimespan(timespan)); + default -> throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value()); + }; } throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan"); } @@ -862,35 +770,17 @@ private Duration getDuration(long timespan, String name) { * @see #getValue(String) */ public final Instant getInstant(String name) { - Object o = getValue(name, true); - if (o instanceof Long l) { - return getInstant(l, name); - } - if (o instanceof Integer i) { - return getInstant(i, name); - } - if (o instanceof Short s) { - return getInstant(s, name); - } - if (o instanceof Character c) { - return getInstant(c, name); - } - if (o instanceof Byte b) { - return getInstant(b, name); - } - if (o instanceof UnsignedValue unsigned) { - Object u = unsigned.value(); - if (u instanceof Integer i) { - return getInstant(Integer.toUnsignedLong(i), name); - } - if (u instanceof Short s) { - return getInstant(Short.toUnsignedLong(s), name); - } - if (u instanceof Byte b) { - return getInstant(Short.toUnsignedLong(b), name); - } - } - throw newIllegalArgumentException(name, "java.time.Instant"); + return switch (getValue(name, true)) { + case Long l -> getInstant(l, name); + case Integer i -> getInstant(i, name); + case Short s -> getInstant(s, name); + case Character c -> getInstant(c, name); + case Byte b -> getInstant(b, name); + case UnsignedValue(Integer i) -> getInstant(Integer.toUnsignedLong(i), name); + case UnsignedValue(Short s) -> getInstant(Short.toUnsignedLong(s), name); + case UnsignedValue(Byte b) -> getInstant(Short.toUnsignedLong(b), name); + case null, default -> throw newIllegalArgumentException(name, "java.time.Instant"); + }; } private Instant getInstant(long timestamp, String name) { @@ -900,13 +790,11 @@ private Instant getInstant(long timestamp, String name) { if (timestamp == Long.MIN_VALUE) { return Instant.MIN; } - switch (ts.value()) { - case Timestamp.MILLISECONDS_SINCE_EPOCH: - return Instant.ofEpochMilli(timestamp); - case Timestamp.TICKS: - return Instant.ofEpochSecond(0, objectContext.convertTimestamp(timestamp)); - } - throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value()); + return switch (ts.value()) { + case Timestamp.MILLISECONDS_SINCE_EPOCH -> Instant.ofEpochMilli(timestamp); + case Timestamp.TICKS -> Instant.ofEpochSecond(0, objectContext.convertTimestamp(timestamp)); + default -> throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value()); + }; } throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp"); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/consumer/snippet-files/Snippets.java b/src/jdk.jfr/share/classes/jdk/jfr/consumer/snippet-files/Snippets.java index 0b0ff55e65e..1aa45fa52c6 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/snippet-files/Snippets.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/snippet-files/Snippets.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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 @@ -54,7 +54,7 @@ public static void main(String[] args) throws IOException { .filter(e -> e.getEventType().getName().equals("jdk.ExecutionSample")) .map(e -> e.getStackTrace()) .filter(s -> s != null) - .map(s -> s.getFrames().get(0)) + .map(s -> s.getFrames().getFirst()) .filter(f -> f.isJavaFrame()) .map(f -> f.getMethod()) .collect( diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java index 5bc25bb744e..9c3770c8fad 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java @@ -227,7 +227,7 @@ private static List buildSettingInfos(Class superClass, ClassNod for (AnnotationNode nameCandidate : m.visibleAnnotations) { if (ANNOTATION_NAME_DESCRIPTOR.equals(nameCandidate.desc)) { List values = nameCandidate.values; - if (values.size() == 1 && values.get(0)instanceof String s) { + if (values.size() == 1 && values.getFirst() instanceof String s) { name = Utils.validJavaIdentifier(s, name); } } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/FilePurger.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/FilePurger.java index 1e9f68c47ca..ca5bfed73f1 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/FilePurger.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/FilePurger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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,7 +28,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.Set; +import java.util.SequencedSet; import jdk.jfr.internal.SecuritySupport.SafePath; @@ -36,7 +36,7 @@ // so they can a later staged be removed. final class FilePurger { - private static final Set paths = new LinkedHashSet<>(); + private static final SequencedSet paths = new LinkedHashSet<>(); public static synchronized void add(SafePath p) { paths.add(p); @@ -58,8 +58,7 @@ public static synchronized void purge() { } private static void removeOldest() { - SafePath oldest = paths.iterator().next(); - paths.remove(oldest); + paths.removeFirst(); } private static boolean delete(SafePath p) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java index 13b81ca85d6..81f4c79fba4 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataReader.java @@ -75,12 +75,12 @@ public MetadataReader(RecordingInput input) throws IOException { } descriptor = new MetadataDescriptor(); Element root = createElement(); - Element metadata = root.elements("metadata").get(0); + Element metadata = root.elements("metadata").getFirst(); declareTypes(metadata); defineTypes(metadata); annotateTypes(metadata); buildEvenTypes(); - Element time = root.elements("region").get(0); + Element time = root.elements("region").getFirst(); descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1); descriptor.dst = time.attribute(MetadataDescriptor.ATTRIBUTE_DST, 0L); descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, ""); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java index 891b6e72ac3..2ce2bd8d722 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java @@ -100,7 +100,7 @@ private static Timer createTimer() { jvm.exclude(t); t.start(); t.join(); - return result.get(0); + return result.getFirst(); } catch (InterruptedException e) { throw new IllegalStateException("Not able to create timer task. " + e.getMessage(), e); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java index 6e5f461320a..9b31a9006e0 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java @@ -797,7 +797,7 @@ private static List reduceFromBeginning(Long maxSize, List 1) { - sj.add(conflictedOptions.remove(0)); + sj.add(conflictedOptions.removeFirst()); } sb.append(sj); sb.append(" and"); } sb.append(" "); - sb.append(conflictedOptions.remove(0)); + sb.append(conflictedOptions.removeFirst()); sb.append(" can only be specified once."); throw new IllegalArgumentException(sb.toString()); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/JFC.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/JFC.java index 213fe6c4c25..6d7cccfb2a6 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/JFC.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/JFC.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -303,18 +303,13 @@ public static String formatException(String prefix, Exception e, String input) { } private static String exceptionToVerb(Exception e) { - if (e instanceof FileNotFoundException || e instanceof NoSuchFileException) { - return "find"; - } - if (e instanceof ParseException) { - return "parse"; - } - if (e instanceof JFCModelException) { - return "use"; - } - if (e instanceof AccessDeniedException) { - return "access"; - } - return "open"; // InvalidPath, IOException + return switch (e) { + case FileNotFoundException f -> "find"; + case NoSuchFileException n -> "find"; + case ParseException p -> "parse"; + case JFCModelException j -> "use"; + case AccessDeniedException a -> "access"; + default -> "open"; // InvalidPath, IOException + }; } } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlElement.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlElement.java index 90d5101d032..d05516ed229 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlElement.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -175,7 +175,7 @@ protected Result evaluate() { if (producers.size() != 1) { throw new Error("Unsure how to evaluate multiple producers " + getClass()); } - return producers.get(0).evaluate(); + return producers.getFirst().evaluate(); } protected void validateAttributes() throws JFCModelException { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlNot.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlNot.java index b375bfcf838..3e0bef58e42 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlNot.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlNot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,7 @@ protected void validateChildConstraints() throws JFCModelException { protected Result evaluate() { List producers = getProducers(); if (!producers.isEmpty()) { - Result r = producers.get(0).evaluate(); + Result r = producers.getFirst().evaluate(); if (!r.isNull()) { return r.isTrue() ? Result.FALSE : Result.TRUE; } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlSelection.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlSelection.java index c451119fb1a..32a4eca60c5 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlSelection.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlSelection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -121,6 +121,6 @@ private XmlOption getSelected() { return optionElement; } } - return options.isEmpty() ? null : options.get(0); + return options.isEmpty() ? null : options.getFirst(); } } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlTest.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlTest.java index 7da80dc1d60..ed17e00e307 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlTest.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/jfc/model/XmlTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -71,7 +71,7 @@ protected Result evaluate() { Result ret = Result.NULL; List producers = getProducers(); if (!producers.isEmpty()) { - XmlElement producer = producers.get(0); + XmlElement producer = producers.getFirst(); Result r = producer.evaluate(); if (!r.isNull()) { ret = getValue().equals(r.value()) ? Result.TRUE : Result.FALSE; diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldBuilder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldBuilder.java index 2105936b6cf..454ec180530 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldBuilder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldBuilder.java @@ -254,15 +254,11 @@ private void configureTime() { private void configureNumericTypes() { switch (descriptor.getTypeName()) { - case "int": - case "long": - case "short": - case "byte": + case "int", "long", "short", "byte": field.integralType = true; field.alignLeft = false; break; - case "float": - case "double": + case "float", "double": field.fractionalType = true; field.alignLeft = false; break; diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableRenderer.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableRenderer.java index b494d6b6dc8..dd9497d344f 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableRenderer.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableRenderer.java @@ -331,7 +331,7 @@ private void printRow() { for (TableCell cell : tableCells) { maxHeight = Math.max(cell.getHeight(), maxHeight); } - TableCell lastCell = tableCells.get(tableCells.size() - 1); + TableCell lastCell = tableCells.getLast(); for (int rowIndex = 0; rowIndex < maxHeight; rowIndex++) { for (TableCell cell : tableCells) { if (rowIndex < cell.getHeight()) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/ViewFile.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/ViewFile.java index dc8aa75e490..96eb1fbdea8 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/ViewFile.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/ViewFile.java @@ -110,8 +110,7 @@ private List parse(String text) throws ParseException { String key = tokenizer.next(); tokenizer.expect("="); String value = tokenizer.next(); - ViewConfiguration view = views.get(views.size() - 1); - view.properties().put(key, value); + views.getLast().properties().put(key, value); } } return views; diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Command.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Command.java index 032e4d1982b..974e8846aa4 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Command.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Command.java @@ -122,7 +122,7 @@ private static String buildAlias(Command c) { StringBuilder sb = new StringBuilder(); if (aliases.size() == 1) { sb.append(" (alias "); - sb.append(aliases.get(0)); + sb.append(aliases.getFirst()); sb.append(")"); return sb.toString(); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Disassemble.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Disassemble.java index edcaf228d78..06616771cf9 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Disassemble.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Disassemble.java @@ -181,7 +181,7 @@ private List findChunkSizes(Path p) throws IOException { private List combineChunkSizes(List sizes, int maxChunks, long maxSize) { List reduced = new ArrayList(); int chunks = 1; - long fileSize = sizes.get(0); + long fileSize = sizes.getFirst(); for (int i = 1; i < sizes.size(); i++) { long size = sizes.get(i); if (fileSize + size > maxSize || chunks == maxChunks) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Filters.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Filters.java index 7020e0daaa0..e63fd34f8b8 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Filters.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Filters.java @@ -96,7 +96,7 @@ public static Predicate matchAny(List> filters) { return t -> true; } if (filters.size() == 1) { - return filters.get(0); + return filters.getFirst(); } return t -> { for (Predicate p : filters) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java index 26cf7f66ce0..89a8faba686 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java @@ -418,7 +418,7 @@ void printObject(RecordedObject object, long arraySize) { if (clazz != null) { String className = clazz.getName(); if (className!= null && className.startsWith("[")) { - className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").get(0); + className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").getFirst(); } print(className); String description = object.getString("description"); @@ -484,7 +484,7 @@ private void printClass(RecordedClass clazz, String postFix) { } String className = clazz.getName(); if (className.startsWith("[")) { - className = decodeDescriptors(className, "").get(0); + className = decodeDescriptors(className, "").getFirst(); } println(className + " (classLoader = " + classLoaderName + ")" + postFix); } diff --git a/test/jdk/jdk/jfr/api/consumer/TestFieldAccess.java b/test/jdk/jdk/jfr/api/consumer/TestFieldAccess.java index fa3e8e028cc..3a35ca6d751 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestFieldAccess.java +++ b/test/jdk/jdk/jfr/api/consumer/TestFieldAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,7 +65,7 @@ public static void main(String[] args) throws Throwable { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); testHasField(event); testGetField(event, myEvent); } diff --git a/test/jdk/jdk/jfr/api/consumer/TestMethodGetModifiers.java b/test/jdk/jdk/jfr/api/consumer/TestMethodGetModifiers.java index 2b6e50c51e5..9b5505c55de 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestMethodGetModifiers.java +++ b/test/jdk/jdk/jfr/api/consumer/TestMethodGetModifiers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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,7 +57,7 @@ public static void main(String[] args) throws Throwable { List recordedEvents = Events.fromRecording(recording); Events.hasEvents(recordedEvents); - RecordedEvent recordedEvent = recordedEvents.get(0); + RecordedEvent recordedEvent = recordedEvents.getFirst(); System.out.println(recordedEvent); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedEvent.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedEvent.java index 6f23845f161..9223d2ef5ad 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedEvent.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,7 +66,7 @@ public static void main(String[] args) throws Throwable { List events = Events.fromRecording(r); Events.hasEvents(events); Asserts.assertEquals(events.size(), 1); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); List descriptors = event.getFields(); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThread.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThread.java index 657170cacfe..d3d581bc374 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThread.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThread.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,7 +56,7 @@ public static void main(String[] args) throws Throwable { List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); RecordedThread recordedThread = event.getThread(); Asserts.assertNotNull(recordedThread); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java index 29e925ba07d..daaec8c0557 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedEventGetThreadOther.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -85,7 +85,7 @@ public static void main(String[] args) throws Exception { List events = RecordingFile.readAllEvents(dumpFilePath); Asserts.assertEquals(events.size(), 1); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); RecordedThread recordedThread = event.getThread(); Asserts.assertNotNull(recordedThread); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedFrame.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedFrame.java index a543c2560aa..611ed0e688f 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedFrame.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedFrame.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -68,7 +68,7 @@ static void test() throws IOException { List recordedEvents = Events.fromRecording(recording); Events.hasEvents(recordedEvents); - RecordedEvent recordedEvent = recordedEvents.get(0); + RecordedEvent recordedEvent = recordedEvents.getFirst(); RecordedStackTrace stacktrace = recordedEvent.getStackTrace(); List frames = stacktrace.getFrames(); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java index 6993fe31001..18fcb300382 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedFullStackTrace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -151,7 +151,7 @@ private static void checkEvent(RecordedEvent event, int expectedDepth) throws Th boolean isTruncateExpected = expectedDepth > MAX_DEPTH; Asserts.assertEquals(isTruncated, isTruncateExpected, "Wrong value for isTruncated. Expected:" + isTruncateExpected); - String firstMethod = frames.get(frames.size() - 1).getMethod().getName(); + String firstMethod = frames.getLast().getMethod().getName(); boolean isFullTrace = "run".equals(firstMethod); String msg = String.format("Wrong values for isTruncated=%b, isFullTrace=%b", isTruncated, isFullTrace); Asserts.assertTrue(isTruncated != isFullTrace, msg); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedInstantEventTimestamp.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedInstantEventTimestamp.java index ae2162c2466..8c37fe8743b 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedInstantEventTimestamp.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedInstantEventTimestamp.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,7 +50,7 @@ public static void main(String[] args) throws Throwable { List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); Asserts.assertEquals(event.getStartTime(), event.getEndTime()); } } diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java index 47b8831d2e4..884697c26a5 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,7 +65,7 @@ public static void main(String[] args) throws Exception { List recordedEvents = Events.fromRecording(recording); assertEquals(1, recordedEvents.size(), "Expected one event"); - RecordedEvent recordedEvent = recordedEvents.get(0); + RecordedEvent recordedEvent = recordedEvents.getFirst(); RecordedStackTrace stacktrace = recordedEvent.getStackTrace(); List frames = stacktrace.getFrames(); diff --git a/test/jdk/jdk/jfr/api/consumer/TestRecordedObject.java b/test/jdk/jdk/jfr/api/consumer/TestRecordedObject.java index af7b5dfbf90..17878ff7e6c 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestRecordedObject.java +++ b/test/jdk/jdk/jfr/api/consumer/TestRecordedObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -392,7 +392,7 @@ private static RecordedObject makeRecordedObject() throws IOException { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - return events.get(0); + return events.getFirst(); } } diff --git a/test/jdk/jdk/jfr/api/consumer/TestSingleRecordedEvent.java b/test/jdk/jdk/jfr/api/consumer/TestSingleRecordedEvent.java index 34572e09ad5..f8bd63b915a 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestSingleRecordedEvent.java +++ b/test/jdk/jdk/jfr/api/consumer/TestSingleRecordedEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ public static void main(String[] args) throws Throwable { // Should be 1 event only Asserts.assertEquals(events.size(), 1); - RecordedEvent recordedEvent = events.get(0); + RecordedEvent recordedEvent = events.getFirst(); Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription"); } } diff --git a/test/jdk/jdk/jfr/api/consumer/TestToString.java b/test/jdk/jdk/jfr/api/consumer/TestToString.java index 309d9d8ecf7..3c363176624 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestToString.java +++ b/test/jdk/jdk/jfr/api/consumer/TestToString.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -61,7 +61,7 @@ public static void main(String[] args) throws Throwable { recording.stop(); List events = Events.fromRecording(recording); Events.hasEvents(events); - RecordedEvent e = events.get(0); + RecordedEvent e = events.getFirst(); String toString = e.toString(); System.out.println(toString); Asserts.assertTrue(toString.contains("hello, world"), "Missing String field value in RecordedEvent#toString()"); diff --git a/test/jdk/jdk/jfr/api/consumer/TestValueDescriptorRecorded.java b/test/jdk/jdk/jfr/api/consumer/TestValueDescriptorRecorded.java index 1569fac7a8d..4fc90c10cf1 100644 --- a/test/jdk/jdk/jfr/api/consumer/TestValueDescriptorRecorded.java +++ b/test/jdk/jdk/jfr/api/consumer/TestValueDescriptorRecorded.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -61,7 +61,7 @@ public static void main(String[] args) throws Throwable { List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent recordedEvent = events.get(0); + RecordedEvent recordedEvent = events.getFirst(); for (ValueDescriptor desc : recordedEvent.getFields()) { if ("myValue".equals(desc.getName())) { Asserts.assertEquals(desc.getLabel(), "myLabel"); diff --git a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestOnMetadata.java b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestOnMetadata.java index fe4637144f4..79ca6634454 100644 --- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestOnMetadata.java +++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestOnMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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 @@ -67,7 +67,7 @@ private static void testUnmodifiable() throws Exception { AtomicBoolean fail = new AtomicBoolean(); try (RecordingStream r = new RecordingStream()) { r.onMetadata(m -> { - EventType t = FlightRecorder.getFlightRecorder().getEventTypes().get(0); + EventType t = FlightRecorder.getFlightRecorder().getEventTypes().getFirst(); try { m.getEventTypes().add(t); System.out.println("Should not be able to modify getEventTypes()"); diff --git a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestStoppedRecording.java b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestStoppedRecording.java index 6daff7b339b..c0593f4d97b 100644 --- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestStoppedRecording.java +++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestStoppedRecording.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -47,7 +47,7 @@ public static void main(String... args) throws Exception { CountDownLatch latch = new CountDownLatch(1); try (RecordingStream rs = new RecordingStream()) { rs.onEvent(e -> { - FlightRecorder.getFlightRecorder().getRecordings().get(0).stop(); + FlightRecorder.getFlightRecorder().getRecordings().getFirst().stop(); }); rs.onClose(() -> { latch.countDown(); diff --git a/test/jdk/jdk/jfr/api/event/TestEventDuration.java b/test/jdk/jdk/jfr/api/event/TestEventDuration.java index 15633bbf23a..f043ee26c53 100644 --- a/test/jdk/jdk/jfr/api/event/TestEventDuration.java +++ b/test/jdk/jdk/jfr/api/event/TestEventDuration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -55,7 +55,7 @@ public static void main(String[] args) throws Exception { r.stop(); List events = Events.fromRecording(r); - if (events.get(0).getDuration().toNanos() < 1) { + if (events.getFirst().getDuration().toNanos() < 1) { throw new AssertionError("Expected a duration"); } } diff --git a/test/jdk/jdk/jfr/api/event/dynamic/TestDynamicAnnotations.java b/test/jdk/jdk/jfr/api/event/dynamic/TestDynamicAnnotations.java index 4d5290a2e5a..18fb3cc5865 100644 --- a/test/jdk/jdk/jfr/api/event/dynamic/TestDynamicAnnotations.java +++ b/test/jdk/jdk/jfr/api/event/dynamic/TestDynamicAnnotations.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -138,7 +138,7 @@ public static void testECID() throws Exception { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - Events.assertField(events.get(0), "ecid").equal(ecidValue); + Events.assertField(events.getFirst(), "ecid").equal(ecidValue); } EventType type = f.getEventType(); ECID e = type.getAnnotation(ECID.class); @@ -175,7 +175,7 @@ public static void testArray() throws Exception { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent re = events.get(0); + RecordedEvent re = events.getFirst(); Array arrayAnnotation = re.getEventType().getAnnotation(Array.class); if (arrayAnnotation== null) { throw new Exception("Missing array annotation"); diff --git a/test/jdk/jdk/jfr/api/flightrecorder/TestSnapshot.java b/test/jdk/jdk/jfr/api/flightrecorder/TestSnapshot.java index cdf582cfbe9..fbb41b7f157 100644 --- a/test/jdk/jdk/jfr/api/flightrecorder/TestSnapshot.java +++ b/test/jdk/jdk/jfr/api/flightrecorder/TestSnapshot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -72,7 +72,7 @@ private static void testMultiple() throws IOException { } try (Recording snapshot = recorder.takeSnapshot()) { Asserts.assertEquals(snapshot.getSize(), size); - Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), recordings.get(0).getStartTime()); + Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), recordings.getFirst().getStartTime()); Asserts.assertLessThanOrEqual(snapshot.getStopTime(), recordings.get(RECORDING_COUNT - 1).getStopTime()); Asserts.assertGreaterThanOrEqual(snapshot.getDuration(), Duration.ZERO); assertStaticOptions(snapshot); @@ -122,7 +122,7 @@ private static void testOngoing(boolean disk) throws IOException { List events = Events.fromRecording(snapshot); Events.hasEvents(events); Asserts.assertEquals(events.size(), 1); - Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName()); + Asserts.assertEquals(events.getFirst().getEventType().getName(), SimpleEvent.class.getName()); } r.stop(); @@ -162,7 +162,7 @@ private static void testStopped() throws IOException { List events = Events.fromRecording(snapshot); Events.hasEvents(events); Asserts.assertEquals(events.size(), 1); - Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName()); + Asserts.assertEquals(events.getFirst().getEventType().getName(), SimpleEvent.class.getName()); } } } diff --git a/test/jdk/jdk/jfr/api/metadata/annotations/TestName.java b/test/jdk/jdk/jfr/api/metadata/annotations/TestName.java index ee0d38a58e1..411f5da67e1 100644 --- a/test/jdk/jdk/jfr/api/metadata/annotations/TestName.java +++ b/test/jdk/jdk/jfr/api/metadata/annotations/TestName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -269,7 +269,7 @@ private static void assertIllegalSettingName(Class eventClass) private static void assertIllegalFieldName(Class eventClass) throws Exception { EventType type = EventType.getEventType(eventClass); if (type.getField("field") == null) { - String illegal = type.getFields().get(type.getFields().size() - 1).getName(); + String illegal = type.getFields().getLast().getName(); throw new Exception("Expected default field name 'field' for event " + type.getName() + ", not illegal name " + illegal); } } diff --git a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetAnnotationElements.java b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetAnnotationElements.java index 213246a8486..34b84779d3e 100644 --- a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetAnnotationElements.java +++ b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetAnnotationElements.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -98,12 +98,12 @@ public static void main(String[] args) throws Throwable { EventFactory f = EventFactory.create(eventAnnotations, fields); EventType type = f.getEventType(); - List aes = type.getAnnotationElements().get(0).getAnnotationElements(); + List aes = type.getAnnotationElements().getFirst().getAnnotationElements(); Asserts.assertEquals(0, aes.size()); EventType et = EventType.getEventType(MyEvent.class); ValueDescriptor field = et.getField("transactionRate"); - aes = field.getAnnotationElements().get(0).getAnnotationElements(); + aes = field.getAnnotationElements().getFirst().getAnnotationElements(); Asserts.assertEquals(3, aes.size()); assertContainsAnnotation(aes, Description.class); assertContainsAnnotation(aes, Label.class); diff --git a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetCategory.java b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetCategory.java index 5a9dbd809e1..ec92be1eb4e 100644 --- a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetCategory.java +++ b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetCategory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,7 @@ public static void main(String[] args) throws Throwable { List noCategory = EventType.getEventType(NoCategory.class).getCategoryNames(); System.out.println("noCategory=" + noCategory); Asserts.assertEquals(noCategory.size(), 1, "Wrong default category"); - Asserts.assertEquals(noCategory.get(0), "Uncategorized", "Wrong default category"); + Asserts.assertEquals(noCategory.getFirst(), "Uncategorized", "Wrong default category"); List withCategory = EventType.getEventType(WithCategory.class).getCategoryNames(); Asserts.assertEquals(withCategory.size(), 4, "Wrong category"); diff --git a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetSettings.java b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetSettings.java index faca325c810..f47d451edfb 100644 --- a/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetSettings.java +++ b/test/jdk/jdk/jfr/api/metadata/eventtype/TestGetSettings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,7 +46,7 @@ public static void main(String[] args) throws Throwable { // test immutability try { - settings.add(settings.get(0)); + settings.add(settings.getFirst()); Asserts.fail("Should not be able to modify list returned by getSettings()"); } catch (UnsupportedOperationException uoe) { // OK, as expected diff --git a/test/jdk/jdk/jfr/api/metadata/valuedescriptor/TestConstructor.java b/test/jdk/jdk/jfr/api/metadata/valuedescriptor/TestConstructor.java index a3add739be0..056f216d677 100644 --- a/test/jdk/jdk/jfr/api/metadata/valuedescriptor/TestConstructor.java +++ b/test/jdk/jdk/jfr/api/metadata/valuedescriptor/TestConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -59,7 +59,7 @@ public static void main(String[] args) throws Throwable { // Get labelA from getAnnotations() list Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1"); - final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0); + final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().getFirst(); Asserts.assertNotNull(outAnnotation, "outAnnotation was null"); System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value")); Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA"); diff --git a/test/jdk/jdk/jfr/api/modules/src_mods/test.jfr.main/test/jfr/main/MainTest.java b/test/jdk/jdk/jfr/api/modules/src_mods/test.jfr.main/test/jfr/main/MainTest.java index ff063856f0c..b850807875d 100644 --- a/test/jdk/jdk/jfr/api/modules/src_mods/test.jfr.main/test/jfr/main/MainTest.java +++ b/test/jdk/jdk/jfr/api/modules/src_mods/test.jfr.main/test/jfr/main/MainTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -94,7 +94,7 @@ private static void assertMetadata(List events) { private static void assertMetaAnnotation(List aes) { assertEquals(aes.size(), 1, "@ModularizedAnnotation should only have one meta-annotation"); - AnnotationElement ae = aes.get(0); + AnnotationElement ae = aes.getFirst(); assertEquals(ae.getTypeName(), ModularizedAnnotation.class.getName(), "Incorrect meta-annotation"); } diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestFileExist.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestFileExist.java index 944653bf124..42f5e277ced 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestFileExist.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestFileExist.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -59,7 +59,7 @@ public static void main(String[] args) throws Throwable { r.stop(); List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No events found"); - System.out.println(events.iterator().next()); + System.out.println(events.getFirst()); r.close(); } diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestInvalid.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestInvalid.java index 13a700fe95f..93e2709c222 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestInvalid.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestInvalid.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -92,7 +92,7 @@ public static void main(String[] args) throws Throwable { Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s in %s%n", events.get(0).getEventType().getName(), dest.toString()); + System.out.printf("Found event %s in %s%n", events.getFirst().getEventType().getName(), dest.toString()); } private static void verifyException(VoidFunction f, String msg, Class exceptionClass) throws Throwable { diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestLongPath.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestLongPath.java index f5eb200b1ed..9ab67cfc02e 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestLongPath.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestLongPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ public static void main(String[] args) throws Throwable { Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); } } diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestReadOnly.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestReadOnly.java index 464c089cb6e..8c4a132cb71 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestReadOnly.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestReadOnly.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -72,7 +72,7 @@ public static void main(String[] args) throws Throwable { Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s in %s%n", events.get(0).getEventType().getName(), dest.toString()); + System.out.printf("Found event %s in %s%n", events.getFirst().getEventType().getName(), dest.toString()); } private static void verifyException(VoidFunction f, String msg) throws Throwable { diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestState.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestState.java index 8d0ac868e6a..99ded47f5ea 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestState.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestState.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -70,7 +70,7 @@ public static void main(String[] args) throws Throwable { Asserts.assertTrue(Files.exists(runningDest), "No recording file: " + runningDest); List events = RecordingFile.readAllEvents(runningDest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); r.close(); } diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskFalse.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskFalse.java index cf6de33aa97..4930916a1d9 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskFalse.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskFalse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,7 +66,7 @@ public static void main(String[] args) throws Throwable { List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have been released at stop"); // getDestination() should return null after recording have been written to file. diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskTrue.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskTrue.java index b4b5f6b560e..3684c6e65e8 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskTrue.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestToDiskTrue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -61,7 +61,7 @@ public static void main(String[] args) throws Throwable { Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize()); assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have be released at stop"); Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes"); diff --git a/test/jdk/jdk/jfr/api/recording/destination/TestDestWithDuration.java b/test/jdk/jdk/jfr/api/recording/destination/TestDestWithDuration.java index d51060c959d..ba305a18c2a 100644 --- a/test/jdk/jdk/jfr/api/recording/destination/TestDestWithDuration.java +++ b/test/jdk/jdk/jfr/api/recording/destination/TestDestWithDuration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -68,7 +68,7 @@ public static void main(String[] args) throws Throwable { List events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); } } diff --git a/test/jdk/jdk/jfr/api/recording/dump/TestDumpLongPath.java b/test/jdk/jdk/jfr/api/recording/dump/TestDumpLongPath.java index 2c73aee18f3..a1d2f714f4e 100644 --- a/test/jdk/jdk/jfr/api/recording/dump/TestDumpLongPath.java +++ b/test/jdk/jdk/jfr/api/recording/dump/TestDumpLongPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path); List events = RecordingFile.readAllEvents(path); Asserts.assertFalse(events.isEmpty(), "No events found"); - String foundEventPath = events.get(0).getEventType().getName(); + String foundEventPath = events.getFirst().getEventType().getName(); System.out.printf("Found event: %s%n", foundEventPath); Asserts.assertEquals(foundEventPath, eventPath, "Wrong event"); } diff --git a/test/jdk/jdk/jfr/api/recording/event/TestChunkPeriod.java b/test/jdk/jdk/jfr/api/recording/event/TestChunkPeriod.java index 64c024cfa4f..71ffa1f3a9f 100644 --- a/test/jdk/jdk/jfr/api/recording/event/TestChunkPeriod.java +++ b/test/jdk/jdk/jfr/api/recording/event/TestChunkPeriod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -68,7 +68,7 @@ private static void testBeginChunk() throws IOException { r.stop(); List events = Events.fromRecording(r); Asserts.assertEquals(events.size(), 1, "Expected one event with beginChunk"); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); Asserts.assertGreaterThanOrEqual(event.getStartTime(), beforeStart); Asserts.assertGreaterThanOrEqual(afterStart, event.getStartTime()); r.close(); @@ -83,7 +83,7 @@ private static void testEndChunk() throws IOException { Instant afterStop = Instant.now().plus(MARGIN_OF_ERROR); List events = Events.fromRecording(r); Asserts.assertEquals(events.size(), 1, "Expected one event with endChunk"); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); Asserts.assertGreaterThanOrEqual(event.getStartTime(), beforeStop); Asserts.assertGreaterThanOrEqual(afterStop, event.getStartTime()); r.close(); diff --git a/test/jdk/jdk/jfr/api/recording/misc/TestRecordingCopy.java b/test/jdk/jdk/jfr/api/recording/misc/TestRecordingCopy.java index dd11040b30a..8d539ed68c4 100644 --- a/test/jdk/jdk/jfr/api/recording/misc/TestRecordingCopy.java +++ b/test/jdk/jdk/jfr/api/recording/misc/TestRecordingCopy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,7 +126,7 @@ private static void assertCopy(Recording recording, Recording original) throws E Events.hasEvents(recordedEvents); Asserts.assertEquals(1, recordedEvents.size(), "Expected exactly one event"); - RecordedEvent re = recordedEvents.get(0); + RecordedEvent re = recordedEvents.getFirst(); Asserts.assertEquals(EVENT_ID, re.getValue("id")); } diff --git a/test/jdk/jdk/jfr/event/compiler/TestCodeCacheConfig.java b/test/jdk/jdk/jfr/event/compiler/TestCodeCacheConfig.java index 99431ed8248..cfc2115d68b 100644 --- a/test/jdk/jdk/jfr/event/compiler/TestCodeCacheConfig.java +++ b/test/jdk/jdk/jfr/event/compiler/TestCodeCacheConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { List events = Events.fromRecording(recording); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); long initialSize = (long) event.getValue("initialSize"); long reservedSize = (long) event.getValue("reservedSize"); long nonNMethodSize = (long) event.getValue("nonNMethodSize"); diff --git a/test/jdk/jdk/jfr/event/compiler/TestCodeCacheFull.java b/test/jdk/jdk/jfr/event/compiler/TestCodeCacheFull.java index 70cdb7c31da..ba72d251372 100644 --- a/test/jdk/jdk/jfr/event/compiler/TestCodeCacheFull.java +++ b/test/jdk/jdk/jfr/event/compiler/TestCodeCacheFull.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -67,7 +67,7 @@ private static void testWithBlobType(BlobType btype, long availableSize) throws List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); String codeBlobType = Events.assertField(event, "codeBlobType").notNull().getValue(); BlobType blobType = blobTypeFromName(codeBlobType); diff --git a/test/jdk/jdk/jfr/event/diagnostics/TestHeapDump.java b/test/jdk/jdk/jfr/event/diagnostics/TestHeapDump.java index 4cbb0826fa0..20577d8257d 100644 --- a/test/jdk/jdk/jfr/event/diagnostics/TestHeapDump.java +++ b/test/jdk/jdk/jfr/event/diagnostics/TestHeapDump.java @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { if (events.size() != 1) { throw new Exception("Expected one event, got " + events.size()); } - RecordedEvent e = events.get(0); + RecordedEvent e = events.getFirst(); Events.assertField(e, "destination").equal(path.toString()); Events.assertField(e, "gcBeforeDump").equal(true); Events.assertField(e, "onOutOfMemoryError").equal(false); diff --git a/test/jdk/jdk/jfr/event/gc/collection/TestSystemGC.java b/test/jdk/jdk/jfr/event/gc/collection/TestSystemGC.java index 05b6aa45b8c..81c5be964fc 100644 --- a/test/jdk/jdk/jfr/event/gc/collection/TestSystemGC.java +++ b/test/jdk/jdk/jfr/event/gc/collection/TestSystemGC.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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 @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { Asserts.assertEquals(3, events.size(), "Expected 3 SystemGC events"); - RecordedEvent event1 = events.get(0); + RecordedEvent event1 = events.getFirst(); Events.assertFrame(event1, System.class, "gc"); Events.assertEventThread(event1, Thread.currentThread()); Events.assertField(event1, "invokedConcurrent").isEqual(concurrent); diff --git a/test/jdk/jdk/jfr/event/gc/configuration/GCHeapConfigurationEventTester.java b/test/jdk/jdk/jfr/event/gc/configuration/GCHeapConfigurationEventTester.java index ff554d659b4..1bbd8fcfa38 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/GCHeapConfigurationEventTester.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/GCHeapConfigurationEventTester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,7 +42,7 @@ public void run() throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - EventVerifier v = createVerifier(events.get(0)); + EventVerifier v = createVerifier(events.getFirst()); v.verify(); } diff --git a/test/jdk/jdk/jfr/event/gc/configuration/GCYoungGenerationConfigurationEventTester.java b/test/jdk/jdk/jfr/event/gc/configuration/GCYoungGenerationConfigurationEventTester.java index 780b9094153..83dd9d735ac 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/GCYoungGenerationConfigurationEventTester.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/GCYoungGenerationConfigurationEventTester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,7 +41,7 @@ public void run() throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - EventVerifier v = createVerifier(events.get(0)); + EventVerifier v = createVerifier(events.getFirst()); v.verify(); } diff --git a/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEvent.java b/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEvent.java index c134c21ffdc..e459b0f2e7b 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEvent.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - GCConfigurationEventVerifier verifier = new GCConfigurationEventVerifier(events.get(0)); + GCConfigurationEventVerifier verifier = new GCConfigurationEventVerifier(events.getFirst()); verifier.verify(); } } diff --git a/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEventWithDefaultPauseTarget.java b/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEventWithDefaultPauseTarget.java index 868065791f2..c3a28030338 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEventWithDefaultPauseTarget.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/TestGCConfigurationEventWithDefaultPauseTarget.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - DefaultGCConfigurationVerifier verifier = new DefaultGCConfigurationVerifier(events.get(0)); + DefaultGCConfigurationVerifier verifier = new DefaultGCConfigurationVerifier(events.getFirst()); verifier.verify(); } } diff --git a/test/jdk/jdk/jfr/event/gc/configuration/TestGCSurvivorConfigurationEvent.java b/test/jdk/jdk/jfr/event/gc/configuration/TestGCSurvivorConfigurationEvent.java index 89dcd97cd4e..fde69412a7a 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/TestGCSurvivorConfigurationEvent.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/TestGCSurvivorConfigurationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - GCSurvivorConfigurationEventVerifier verifier = new GCSurvivorConfigurationEventVerifier(events.get(0)); + GCSurvivorConfigurationEventVerifier verifier = new GCSurvivorConfigurationEventVerifier(events.getFirst()); verifier.verify(); } } diff --git a/test/jdk/jdk/jfr/event/gc/configuration/TestGCTLABConfigurationEvent.java b/test/jdk/jdk/jfr/event/gc/configuration/TestGCTLABConfigurationEvent.java index e67897199a5..b69e4fb8490 100644 --- a/test/jdk/jdk/jfr/event/gc/configuration/TestGCTLABConfigurationEvent.java +++ b/test/jdk/jdk/jfr/event/gc/configuration/TestGCTLABConfigurationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); - GCTLABConfigurationEventVerifier verifier = new GCTLABConfigurationEventVerifier(events.get(0)); + GCTLABConfigurationEventVerifier verifier = new GCTLABConfigurationEventVerifier(events.getFirst()); verifier.verify(); } } diff --git a/test/jdk/jdk/jfr/event/gc/detailed/StressAllocationGCEvents.java b/test/jdk/jdk/jfr/event/gc/detailed/StressAllocationGCEvents.java index 257d35bd389..779ed704ea7 100644 --- a/test/jdk/jdk/jfr/event/gc/detailed/StressAllocationGCEvents.java +++ b/test/jdk/jdk/jfr/event/gc/detailed/StressAllocationGCEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -157,7 +157,7 @@ private void checkEvent(RecordedEvent event) throws Exception { List frames = stackTrace.getFrames(); //String[] stacktrace = StackTraceHelper.buildStackTraceFromFrames(frames); - if (!(frames.get(0).getMethod().getName().equals(DIVER_FRAME_NAME))) { + if (!(frames.getFirst().getMethod().getName().equals(DIVER_FRAME_NAME))) { System.out.println("Skip stacktrace check for: \n" + String.join("\n", threadName)); return; diff --git a/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryPoolUsageEvent.java b/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryPoolUsageEvent.java index 33c1b04dbca..6d5308408d6 100644 --- a/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryPoolUsageEvent.java +++ b/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryPoolUsageEvent.java @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception { System.out.println(events); assertFalse(events.isEmpty()); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); Events.assertField(event, "name").notNull(); Events.assertField(event, "used").atLeast(0L); Events.assertField(event, "committed").atLeast(0L); diff --git a/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryUsageEvent.java b/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryUsageEvent.java index 61aa079ca23..7f1d96a3993 100644 --- a/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryUsageEvent.java +++ b/test/jdk/jdk/jfr/event/gc/detailed/TestGCHeapMemoryUsageEvent.java @@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception { List events = Events.fromRecording(recording); System.out.println(events); assertFalse(events.isEmpty()); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); Events.assertField(event, "used").above(0L); Events.assertField(event, "committed").above(0L); Events.assertField(event, "max").above(0L); diff --git a/test/jdk/jdk/jfr/event/gc/detailed/TestGCLockerEvent.java b/test/jdk/jdk/jfr/event/gc/detailed/TestGCLockerEvent.java index d35309c1883..f0d9fa3f35a 100644 --- a/test/jdk/jdk/jfr/event/gc/detailed/TestGCLockerEvent.java +++ b/test/jdk/jdk/jfr/event/gc/detailed/TestGCLockerEvent.java @@ -88,7 +88,7 @@ public static void main(String[] args) throws Exception { // Verify recording var all = Events.fromRecording(recording); Events.hasEvents(all); - var event = all.get(0); + var event = all.getFirst(); assertTrue(Events.isEventType(event, EVENT_NAME)); Events.assertField(event, "lockCount").equal(CRITICAL_THREAD_COUNT); diff --git a/test/jdk/jdk/jfr/event/io/TestDeserializationEvent.java b/test/jdk/jdk/jfr/event/io/TestDeserializationEvent.java index c2b250c3e00..28b26165e2f 100644 --- a/test/jdk/jdk/jfr/event/io/TestDeserializationEvent.java +++ b/test/jdk/jdk/jfr/event/io/TestDeserializationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -175,9 +175,9 @@ public void testFilterDisallow(Status filterStatus, recording.stop(); List events = Events.fromRecording(recording); assertEquals(events.size(), 1); - assertEquals(events.get(0).getEventType().getName(), "jdk.Deserialization"); - assertFilterConfigured(true).accept(events.get(0)); - assertFilterStatus(expectedValue).accept(events.get(0)); + assertEquals(events.getFirst().getEventType().getName(), "jdk.Deserialization"); + assertFilterConfigured(true).accept(events.getFirst()); + assertFilterStatus(expectedValue).accept(events.getFirst()); } } @@ -202,9 +202,9 @@ public void testFilterAllowed(Status filterStatus, recording.stop(); List events = Events.fromRecording(recording); assertEquals(events.size(), 1); - assertEquals(events.get(0).getEventType().getName(), "jdk.Deserialization"); - assertFilterConfigured(true).accept(events.get(0)); - assertFilterStatus(expectedValue).accept(events.get(0)); + assertEquals(events.getFirst().getEventType().getName(), "jdk.Deserialization"); + assertFilterConfigured(true).accept(events.getFirst()); + assertFilterStatus(expectedValue).accept(events.getFirst()); } } @@ -224,10 +224,10 @@ public void testException() throws Exception { recording.stop(); List events = Events.fromRecording(recording); assertEquals(events.size(), 1); - assertEquals(events.get(0).getEventType().getName(), "jdk.Deserialization"); - assertFilterConfigured(true).accept(events.get(0)); - assertExceptionType(XYZException.class).accept(events.get(0)); - assertExceptionMessage("I am a bad filter!!!").accept(events.get(0)); + assertEquals(events.getFirst().getEventType().getName(), "jdk.Deserialization"); + assertFilterConfigured(true).accept(events.getFirst()); + assertExceptionType(XYZException.class).accept(events.getFirst()); + assertExceptionMessage("I am a bad filter!!!").accept(events.getFirst()); } } @@ -428,8 +428,8 @@ public void testRejectedClassNotInitialized() throws Exception { List events = Events.fromRecording(recording); assertEquals(events.size(), 1); assertEquals(events.get(0).getEventType().getName(), "jdk.Deserialization"); - assertFilterConfigured(true).accept(events.get(0)); - assertFilterStatus("REJECTED").accept(events.get(0)); + assertFilterConfigured(true).accept(events.getFirst()); + assertFilterStatus("REJECTED").accept(events.getFirst()); assertFalse(initializedFoo); assertType(Foo.class); } diff --git a/test/jdk/jdk/jfr/event/profiling/TestFullStackTrace.java b/test/jdk/jdk/jfr/event/profiling/TestFullStackTrace.java index b9f23ebed86..b7abbc0a587 100644 --- a/test/jdk/jdk/jfr/event/profiling/TestFullStackTrace.java +++ b/test/jdk/jdk/jfr/event/profiling/TestFullStackTrace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -121,7 +121,7 @@ private static boolean hasValidStackTraces(Recording recording, RecurseThread[] public static String getTopMethodName(RecordedEvent event) { List frames = event.getStackTrace().getFrames(); Asserts.assertFalse(frames.isEmpty(), "JavaFrames was empty"); - return frames.get(0).getMethod().getName(); + return frames.getFirst().getMethod().getName(); } private static void checkEvent(RecordedEvent event, int expectedDepth) throws Throwable { @@ -144,7 +144,7 @@ private static void checkEvent(RecordedEvent event, int expectedDepth) throws Th boolean isTruncateExpected = expectedDepth > MAX_DEPTH; Asserts.assertEquals(isTruncated, isTruncateExpected, "Wrong value for isTruncated. Expected:" + isTruncateExpected); - String firstMethod = frames.get(frames.size() - 1).getMethod().getName(); + String firstMethod = frames.getLast().getMethod().getName(); boolean isFullTrace = "run".equals(firstMethod); String msg = String.format("Wrong values for isTruncated=%b, isFullTrace=%b", isTruncated, isFullTrace); Asserts.assertTrue(isTruncated != isFullTrace, msg); diff --git a/test/jdk/jdk/jfr/event/runtime/TestActiveRecordingEvent.java b/test/jdk/jdk/jfr/event/runtime/TestActiveRecordingEvent.java index c929ff1d5e8..e786e8c933d 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestActiveRecordingEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestActiveRecordingEvent.java @@ -89,7 +89,7 @@ private static void testWithPath(Path path) throws Throwable { List events = Events.fromRecording(recording); Events.hasEvents(events); - RecordedEvent ev = events.get(0); + RecordedEvent ev = events.getFirst(); // Duration must be kept in milliseconds assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration")); diff --git a/test/jdk/jdk/jfr/event/runtime/TestClassLoadingStatisticsEvent.java b/test/jdk/jdk/jfr/event/runtime/TestClassLoadingStatisticsEvent.java index 31760614019..8bbbdcbc447 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestClassLoadingStatisticsEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestClassLoadingStatisticsEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -116,7 +116,7 @@ private static RecordedEvent getCurrentEvent() throws Throwable { recording.stop(); List events = Events.fromRecording(recording); Asserts.assertFalse(events.isEmpty(), "No events in recording"); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); return event; } diff --git a/test/jdk/jdk/jfr/event/runtime/TestClassRedefinition.java b/test/jdk/jdk/jfr/event/runtime/TestClassRedefinition.java index f3e24581b23..23c2f2cbc3a 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestClassRedefinition.java +++ b/test/jdk/jdk/jfr/event/runtime/TestClassRedefinition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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 @@ -81,7 +81,7 @@ public static void main(String[] args) throws Throwable { List events = RecordingFile.readAllEvents(DUMP_PATH); Asserts.assertEquals(events.size(), 2, "Expected exactly two ClassRedefinition event"); - RecordedEvent e1 = events.get(0); + RecordedEvent e1 = events.getFirst(); System.out.println(e1); RecordedEvent e2 = events.get(1); System.out.println(e2); diff --git a/test/jdk/jdk/jfr/event/runtime/TestExceptionEvents.java b/test/jdk/jdk/jfr/event/runtime/TestExceptionEvents.java index 5176e0e44db..46488f0221a 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestExceptionEvents.java +++ b/test/jdk/jdk/jfr/event/runtime/TestExceptionEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -102,7 +102,7 @@ class TestException extends Exception { RecordedStackTrace rs = e.getStackTrace(); RecordedClass rc = e.getValue("thrownClass"); List frames = rs.getFrames(); - RecordedFrame topFrame = frames.get(0); + RecordedFrame topFrame = frames.getFirst(); System.out.println(rc.getName() + " Top frame: " + topFrame.getMethod().getName()); if (!topFrame.getMethod().getName().equals("")) { throw new Exception("Expected name of top frame to be "); diff --git a/test/jdk/jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java b/test/jdk/jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java index 14165afb31e..179d0f50810 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java +++ b/test/jdk/jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2023, 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 @@ -150,8 +150,8 @@ private static void verifyHeapGrowth(List events) throws Exceptio .toList(); // Verify that the heap has grown between the first and last sample. - long firstSample = javaHeapCommitted.get(0); - long lastSample = javaHeapCommitted.get(javaHeapCommitted.size() - 1); + long firstSample = javaHeapCommitted.getFirst(); + long lastSample = javaHeapCommitted.getLast(); assertGreaterThan(lastSample, firstSample, "heap should have grown and NMT should show that"); } diff --git a/test/jdk/jdk/jfr/event/runtime/TestRedefineClasses.java b/test/jdk/jdk/jfr/event/runtime/TestRedefineClasses.java index 4331bae0d98..40fc583872f 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestRedefineClasses.java +++ b/test/jdk/jdk/jfr/event/runtime/TestRedefineClasses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -79,7 +79,7 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th public static void main(String[] args) throws Throwable { List events = RecordingFile.readAllEvents(DUMP_PATH); Asserts.assertEquals(events.size(), 1, "Expected one RedefineClasses event"); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); System.out.println(event); diff --git a/test/jdk/jdk/jfr/event/runtime/TestRetransformClasses.java b/test/jdk/jdk/jfr/event/runtime/TestRetransformClasses.java index 00242de5b2a..a02f97366c3 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestRetransformClasses.java +++ b/test/jdk/jdk/jfr/event/runtime/TestRetransformClasses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2023, 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 @@ -84,7 +84,7 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th public static void main(String[] args) throws Throwable { List events = RecordingFile.readAllEvents(DUMP_PATH); Asserts.assertEquals(events.size(), 1, "Expected one RetransformClasses event"); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); System.out.println(event); diff --git a/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java b/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java index 71b617ecd79..26d72578170 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -114,7 +114,7 @@ private static void runSubtest(int subTestIndex) throws Exception { .collect(Collectors.toList()); Asserts.assertEquals(filteredEvents.size(), 1); - RecordedEvent event = filteredEvents.get(0); + RecordedEvent event = filteredEvents.getFirst(); subTests[subTestIndex].verifyEvents(event, exitCode); } diff --git a/test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java b/test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java index aa76f501483..2780f396f05 100644 --- a/test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java +++ b/test/jdk/jdk/jfr/jcmd/TestJcmdConfigure.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -88,7 +88,7 @@ public static void main(String[] args) throws Exception { for (Exception e : testExceptions) { System.out.println("Error: " + e.getMessage()); } - throw testExceptions.get(0); + throw testExceptions.getFirst(); } } diff --git a/test/jdk/jdk/jfr/jcmd/TestJcmdDumpLimited.java b/test/jdk/jdk/jfr/jcmd/TestJcmdDumpLimited.java index cb05f49950a..ce4b11937c6 100644 --- a/test/jdk/jdk/jfr/jcmd/TestJcmdDumpLimited.java +++ b/test/jdk/jdk/jfr/jcmd/TestJcmdDumpLimited.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, 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 @@ -110,9 +110,7 @@ public static void main(String[] args) throws Exception { recs.add(new TestRecording(i, 100)); } int last = 0; - List reversed = new ArrayList<>(recs); - Collections.reverse(reversed); - for (TestRecording r : reversed) { + for (TestRecording r : recs.reversed()) { r.total = r.size + last; last += r.size; } diff --git a/test/jdk/jdk/jfr/jcmd/TestJcmdStartPathToGCRoots.java b/test/jdk/jdk/jfr/jcmd/TestJcmdStartPathToGCRoots.java index 31a458c2f8f..ff87d2b68a1 100644 --- a/test/jdk/jdk/jfr/jcmd/TestJcmdStartPathToGCRoots.java +++ b/test/jdk/jdk/jfr/jcmd/TestJcmdStartPathToGCRoots.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,7 +66,7 @@ private static void assertCutoff(String expected, String errorMessage) throws Ex } String settingName = EventNames.OldObjectSample + "#" + "cutoff"; - Recording r = recordings.get(0); + Recording r = recordings.getFirst(); String cutoff = r.getSettings().get(settingName); System.out.println(settingName + "=" + cutoff); if (!expected.equals(cutoff)) { diff --git a/test/jdk/jdk/jfr/jmx/TestPredefinedConfigurationInvalid.java b/test/jdk/jdk/jfr/jmx/TestPredefinedConfigurationInvalid.java index f5a2651ebed..d68bacbcbd0 100644 --- a/test/jdk/jdk/jfr/jmx/TestPredefinedConfigurationInvalid.java +++ b/test/jdk/jdk/jfr/jmx/TestPredefinedConfigurationInvalid.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,7 +48,7 @@ public static void main(String[] args) throws Throwable { setInvalidConfigName(recId, "invalidname"); // Verify we can set named config after failed attempts. - Configuration config = Configuration.getConfigurations().get(0); + Configuration config = Configuration.getConfigurations().getFirst(); bean.setPredefinedConfiguration(recId, config.getName()); JmxHelper.verifyMapEquals(bean.getRecordingSettings(recId), config.getSettings()); } diff --git a/test/jdk/jdk/jfr/jmx/TestSnapshot.java b/test/jdk/jdk/jfr/jmx/TestSnapshot.java index c6ca923d635..b4eb13216b5 100644 --- a/test/jdk/jdk/jfr/jmx/TestSnapshot.java +++ b/test/jdk/jdk/jfr/jmx/TestSnapshot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ private static void testStopped() throws IOException { r.close(); FlightRecorderMXBean mxBean = JmxHelper.getFlighteRecorderMXBean(); List recs = mxBean.getRecordings(); - JmxHelper.verifyEquals(recs.get(0), snapshot); + JmxHelper.verifyEquals(recs.getFirst(), snapshot); } } } @@ -67,7 +67,7 @@ private static void testEmpty() throws IOException { try (Recording snapshot = FlightRecorder.getFlightRecorder().takeSnapshot()) { FlightRecorderMXBean mxBean = JmxHelper.getFlighteRecorderMXBean(); List recs = mxBean.getRecordings(); - JmxHelper.verifyEquals(recs.get(0), snapshot); + JmxHelper.verifyEquals(recs.getFirst(), snapshot); } } } diff --git a/test/jdk/jdk/jfr/jvm/TestDumpOnCrash.java b/test/jdk/jdk/jfr/jvm/TestDumpOnCrash.java index f318961b57a..374e23ecb48 100644 --- a/test/jdk/jdk/jfr/jvm/TestDumpOnCrash.java +++ b/test/jdk/jdk/jfr/jvm/TestDumpOnCrash.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, 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 @@ -153,7 +153,7 @@ private static void verify(long pid, String dumppath, boolean expectDump) throws List events = RecordingFile.readAllEvents(file); Asserts.assertFalse(events.isEmpty(), "No event found"); - System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); + System.out.printf("Found event %s%n", events.getFirst().getEventType().getName()); Files.delete(file); } else { diff --git a/test/jdk/jdk/jfr/jvm/TestPrimitiveClasses.java b/test/jdk/jdk/jfr/jvm/TestPrimitiveClasses.java index 54c20f5bea8..bb0163bc925 100644 --- a/test/jdk/jdk/jfr/jvm/TestPrimitiveClasses.java +++ b/test/jdk/jdk/jfr/jvm/TestPrimitiveClasses.java @@ -62,7 +62,7 @@ public static void main(String[] args) throws Exception { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - RecordedEvent event = events.get(0); + RecordedEvent event = events.getFirst(); System.out.println(event); testField(event, "booleanClass", boolean.class); testField(event, "charClass", char.class); diff --git a/test/jdk/jdk/jfr/startupargs/StartupHelper.java b/test/jdk/jdk/jfr/startupargs/StartupHelper.java index c1ddcdce85f..01911cd8cc1 100644 --- a/test/jdk/jdk/jfr/startupargs/StartupHelper.java +++ b/test/jdk/jdk/jfr/startupargs/StartupHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, 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 @@ -60,7 +60,7 @@ public static List listFilesInDir(Path root) throws IOException { searchPaths.add(root); while (!searchPaths.isEmpty()) { - Path currRoot = searchPaths.remove(searchPaths.size() - 1); + Path currRoot = searchPaths.removeLast(); DirectoryStream contents = Files.newDirectoryStream(currRoot); for (Path path : contents) { paths.add(path); diff --git a/test/jdk/jdk/jfr/startupargs/TestEventSettings.java b/test/jdk/jdk/jfr/startupargs/TestEventSettings.java index 0961e472e3d..41e59523339 100644 --- a/test/jdk/jdk/jfr/startupargs/TestEventSettings.java +++ b/test/jdk/jdk/jfr/startupargs/TestEventSettings.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023, 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 @@ -84,7 +84,7 @@ private static void assertSetting(String key, String value) throws Exception { if (rs.size() != 1) { throw new Exception("Expected only one recording"); } - Map currentSettings = rs.get(0).getSettings(); + Map currentSettings = rs.getFirst().getSettings(); String s = currentSettings.get(key); if (!Objects.equals(s, value)) { System.out.println("Key:" + key); diff --git a/test/jdk/jdk/jfr/threading/TestNestedVirtualThreads.java b/test/jdk/jdk/jfr/threading/TestNestedVirtualThreads.java index 6d4dbb766e1..04799748159 100644 --- a/test/jdk/jdk/jfr/threading/TestNestedVirtualThreads.java +++ b/test/jdk/jdk/jfr/threading/TestNestedVirtualThreads.java @@ -70,8 +70,8 @@ public static void main(String... args) throws Exception { r.stop(); List events = Events.fromRecording(r); Events.hasEvents(events); - System.out.println(events.get(0)); - RecordedEvent e = events.get(0); + System.out.println(events.getFirst()); + RecordedEvent e = events.getFirst(); RecordedThread t = e.getThread(); Asserts.assertTrue(t.isVirtual()); Asserts.assertEquals(t.getJavaName(), ""); // vthreads default name is the empty string. From d31412bf57f70ecaa466c40647dde55f5d360d33 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Wed, 21 Jun 2023 17:18:15 +0000 Subject: [PATCH 14/19] 8310379: Relax prerequisites for java.base-jmod target Reviewed-by: mikael --- make/Main.gmk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/make/Main.gmk b/make/Main.gmk index e13e6f47386..6753b7dc558 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -971,7 +971,8 @@ else # When creating the BUILDJDK, we don't need to add hashes to java.base, thus # we don't need to depend on all other jmods ifneq ($(CREATING_BUILDJDK), true) - java.base-jmod: jrtfs-jar $(filter-out java.base-jmod, $(JMOD_TARGETS)) + java.base-jmod: jrtfs-jar $(filter-out java.base-jmod \ + $(addsuffix -jmod, $(call FindAllUpgradeableModules)), $(JMOD_TARGETS)) endif # If not already set, set the JVM target so that the JVM will be built. From 39b4c99eeae9042a0464e3164d3788b143847822 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 21 Jun 2023 18:00:14 +0000 Subject: [PATCH 15/19] 8309883: no `@since` info in com.sun.tools.javac package-info.java, Main.java Reviewed-by: iris, darcy --- src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java | 2 ++ .../share/classes/com/sun/tools/javac/package-info.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java index 07cae101a64..7e785322eb3 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/Main.java @@ -32,6 +32,8 @@ * compiler, javac. * See the {@code jdk.compiler} * module for details on replacement APIs. + * + * @since 1.5 */ public class Main { /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/package-info.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/package-info.java index fb2483cd726..c40577aa624 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/package-info.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/package-info.java @@ -27,5 +27,7 @@ * This package provides a legacy entry point for the javac tool. * See the {@code jdk.compiler} * module for details on replacement APIs. + * + * @since 1.5 */ package com.sun.tools.javac; From 58ec27ddb9fc40da0e84e812e472c80e65e2b7b3 Mon Sep 17 00:00:00 2001 From: Erik Joelsson Date: Wed, 21 Jun 2023 18:28:19 +0000 Subject: [PATCH 16/19] 8310384: Add hooks for custom image creation Reviewed-by: mikael, alanb --- make/Images.gmk | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/make/Images.gmk b/make/Images.gmk index 5b2f776155f..aeda1e2f0d6 100644 --- a/make/Images.gmk +++ b/make/Images.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2014, 2023, 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,6 +29,7 @@ include $(SPEC) include MakeBase.gmk include Execute.gmk include Modules.gmk +include Utils.gmk JDK_TARGETS := JRE_TARGETS := @@ -39,7 +40,7 @@ $(eval $(call IncludeCustomExtension, Images-pre.gmk)) ################################################################################ # All modules for the current target platform. -ALL_MODULES := $(call FindAllModules) +ALL_MODULES := $(call FindAllModules) $(EXTRA_MODULES) $(eval $(call ReadImportMetaData)) @@ -54,7 +55,10 @@ JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES)) BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release -JMODS := $(wildcard $(IMAGES_OUTPUTDIR)/jmods/*.jmod) +JMODS_DIRS := $(EXTRA_JMODS_DIR) $(IMAGES_OUTPUTDIR)/jmods + +JDK_JMODS := $(foreach m, $(JDK_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS))))) +JRE_JMODS := $(foreach m, $(JRE_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS))))) JLINK_ORDER_RESOURCES := **module-info.class JLINK_JLI_CLASSES := @@ -71,7 +75,7 @@ JLINK_ORDER_RESOURCES += \ # JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \ - --module-path $(IMAGES_OUTPUTDIR)/jmods \ + --module-path $(call PathList, $(JMODS_DIRS)) \ --endian $(OPENJDK_TARGET_CPU_ENDIAN) \ --release-info $(BASE_RELEASE_FILE) \ --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \ @@ -87,12 +91,15 @@ endif JLINK_DISABLE_WARNINGS := | ( $(GREP) -v -e "WARNING: Using incubator module" || test "$$?" = "1" ) +JDK_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk +JRE_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre + $(eval $(call SetupExecute, jlink_jdk, \ WARN := Creating jdk image, \ - DEPS := $(JMODS) $(BASE_RELEASE_FILE) \ - $(call DependOnVariable, JDK_MODULES_LIST), \ + DEPS := $(JDK_JMODS) $(BASE_RELEASE_FILE) \ + $(call DependOnVariable, JDK_MODULES_LIST, $(JDK_IMAGE_SUPPORT_DIR)/_jlink_jdk.vardeps), \ OUTPUT_DIR := $(JDK_IMAGE_DIR), \ - SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk, \ + SUPPORT_DIR := $(JDK_IMAGE_SUPPORT_DIR), \ PRE_COMMAND := $(RM) -r $(JDK_IMAGE_DIR), \ COMMAND := $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \ $(JLINK_JDK_EXTRA_OPTS) --output $(JDK_IMAGE_DIR) \ @@ -103,10 +110,10 @@ JLINK_JDK_TARGETS := $(jlink_jdk) $(eval $(call SetupExecute, jlink_jre, \ WARN := Creating legacy jre image, \ - DEPS := $(JMODS) $(BASE_RELEASE_FILE) \ - $(call DependOnVariable, JDK_MODULES_LIST), \ + DEPS := $(JRE_JMODS) $(BASE_RELEASE_FILE) \ + $(call DependOnVariable, JRE_MODULES_LIST, $(JRE_IMAGE_SUPPORT_DIR)/_jlink_jre.vardeps), \ OUTPUT_DIR := $(JRE_IMAGE_DIR), \ - SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre, \ + SUPPORT_DIR := $(JRE_IMAGE_SUPPORT_DIR), \ PRE_COMMAND := $(RM) -r $(JRE_IMAGE_DIR), \ COMMAND := $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \ $(JLINK_JRE_EXTRA_OPTS) --output $(JRE_IMAGE_DIR), \ @@ -142,7 +149,7 @@ define CreateCDSArchive INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \ DEPS := $$(jlink_jdk), \ OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \ - SUPPORT_DIR := $$(SUPPORT_OUTPUTDIR)/images/jdk, \ + SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \ COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \ -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \ -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \ @@ -155,7 +162,7 @@ define CreateCDSArchive INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \ DEPS := $$(jlink_jre), \ OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \ - SUPPORT_DIR := $$(SUPPORT_OUTPUTDIR)/images/jre, \ + SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \ COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \ -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \ -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \ From 1a122701c4ea139eecd3b1ae0d1c26ce16764bef Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 21 Jun 2023 19:56:51 +0000 Subject: [PATCH 17/19] 8310575: no `@since` for StandardDoclet Reviewed-by: darcy --- .../share/classes/jdk/javadoc/doclet/StandardDoclet.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/StandardDoclet.java b/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/StandardDoclet.java index dff6f3e34bd..82cac37012b 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/StandardDoclet.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/doclet/StandardDoclet.java @@ -65,6 +65,8 @@ * * @spec javadoc/doc-comment-spec.html Documentation Comment Specification for the Standard Doclet * @spec https://www.w3.org/TR/html52 HTML Standard + * + * @since 9 */ public class StandardDoclet implements Doclet { From f61b606bdc4dd39321b162dc18805507cf810b21 Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Wed, 21 Jun 2023 20:04:03 +0000 Subject: [PATCH 18/19] 8310512: Cleanup indentation in jfc files Reviewed-by: egahlin --- src/jdk.jfr/share/conf/jfr/default.jfc | 27 +++++++++++------------- src/jdk.jfr/share/conf/jfr/profile.jfc | 29 +++++++++++++------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/jdk.jfr/share/conf/jfr/default.jfc b/src/jdk.jfr/share/conf/jfr/default.jfc index 0ed815f2611..5743b64285b 100644 --- a/src/jdk.jfr/share/conf/jfr/default.jfc +++ b/src/jdk.jfr/share/conf/jfr/default.jfc @@ -735,8 +735,8 @@ - false - true + false + true @@ -745,13 +745,13 @@ - false - true + false + true - false - true + false + true @@ -760,13 +760,13 @@ - false - true + false + true - false - true + false + true @@ -918,8 +918,6 @@ - - @@ -929,7 +927,7 @@ carry the control attribute. --> - + @@ -974,7 +972,7 @@ - + @@ -1122,7 +1120,6 @@ 20 ms false - diff --git a/src/jdk.jfr/share/conf/jfr/profile.jfc b/src/jdk.jfr/share/conf/jfr/profile.jfc index ca24acb809c..816408a4baf 100644 --- a/src/jdk.jfr/share/conf/jfr/profile.jfc +++ b/src/jdk.jfr/share/conf/jfr/profile.jfc @@ -735,8 +735,8 @@ - false - true + false + true @@ -745,13 +745,13 @@ - false - true + false + true - false - true + false + true @@ -760,13 +760,13 @@ - false - true + false + true - false - true + false + true @@ -927,7 +927,7 @@ carry the control attribute. --> - + @@ -945,11 +945,11 @@ - + - + @@ -967,7 +967,7 @@ - + @@ -1120,7 +1120,6 @@ 10 ms false - From ebc1aaa12603f13075329a735017226edc7e0c26 Mon Sep 17 00:00:00 2001 From: "Daniel D. Daugherty" Date: Wed, 21 Jun 2023 21:07:04 +0000 Subject: [PATCH 19/19] 8310586: ProblemList java/lang/ScopedValue/StressStackOverflow.java#default with virtual threads on linux-all Reviewed-by: dholmes, mikael --- test/jdk/ProblemList-Virtual.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/jdk/ProblemList-Virtual.txt b/test/jdk/ProblemList-Virtual.txt index 428a8854cab..5765cc8c3a0 100644 --- a/test/jdk/ProblemList-Virtual.txt +++ b/test/jdk/ProblemList-Virtual.txt @@ -44,6 +44,8 @@ javax/management/remote/mandatory/loading/RMIDownloadTest.java 8308366 windows-x java/lang/instrument/NativeMethodPrefixAgent.java 8307169 generic-all +java/lang/ScopedValue/StressStackOverflow.java#default 8309646 linux-all + ########## ## Tests incompatible with virtual test thread factory. ## There is no goal to run all test with virtual test thread factory.