diff --git a/.github/workflows/continuous.yml b/.github/workflows/continuous.yml index 3cb5f4e3..5f6f2c78 100644 --- a/.github/workflows/continuous.yml +++ b/.github/workflows/continuous.yml @@ -31,14 +31,23 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Build run: ./gradlew build - - name: Upload build data + - name: Upload dist build data if: always() uses: actions/upload-artifact@v4 with: - name: build + name: dist-build retention-days: 1 path: | btrace-dist/build + btrace-instr/build/classes/traces + - name: Upload test trace data + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-trace + retention-days: 1 + path: | + btrace-instr/build/classes/traces - name: Archive test reports if: always() uses: actions/upload-artifact@v4 @@ -77,8 +86,13 @@ jobs: - name: Download build data uses: actions/download-artifact@v4 with: - name: build + name: dist-build path: btrace-dist/build + - name: Download test trace data + uses: actions/download-artifact@v4 + with: + name: test-trace + path: btrace-instr/build/classes/traces - name: Run tests run: | set +x diff --git a/btrace-instr/src/main/java/org/openjdk/btrace/instr/BTraceTransformer.java b/btrace-instr/src/main/java/org/openjdk/btrace/instr/BTraceTransformer.java index 81faa1da..6dd6c403 100644 --- a/btrace-instr/src/main/java/org/openjdk/btrace/instr/BTraceTransformer.java +++ b/btrace-instr/src/main/java/org/openjdk/btrace/instr/BTraceTransformer.java @@ -136,6 +136,8 @@ public byte[] transform( className = className != null ? className : ""; + // A special case for patching the Indy linking in order to be able to safely skip + // BTrace probes while linking is still in progress. if (className.equals("java/lang/invoke/MethodHandleNatives")) { byte[] transformed = null; try { diff --git a/btrace-instr/src/main/java/org/openjdk/btrace/instr/Instrumentor.java b/btrace-instr/src/main/java/org/openjdk/btrace/instr/Instrumentor.java index e893cad7..4bf36d58 100644 --- a/btrace-instr/src/main/java/org/openjdk/btrace/instr/Instrumentor.java +++ b/btrace-instr/src/main/java/org/openjdk/btrace/instr/Instrumentor.java @@ -41,6 +41,7 @@ import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.openjdk.btrace.core.BTraceRuntime; import org.openjdk.btrace.core.MethodID; diff --git a/btrace-instr/src/test/btrace/TraceAllTest.java b/btrace-instr/src/test/btrace/TraceAllTest.java index df28be79..d0299fa6 100644 --- a/btrace-instr/src/test/btrace/TraceAllTest.java +++ b/btrace-instr/src/test/btrace/TraceAllTest.java @@ -1,12 +1,13 @@ /* - * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, Jaroslav Bachorik . + * All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the Classpath exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. Copyright owner designates + * this particular file as subject to the "Classpath" exception as provided + * by the owner in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -17,10 +18,6 @@ * 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 traces; @@ -31,7 +28,6 @@ import java.util.concurrent.atomic.AtomicLong; - /** * * @author Jaroslav Bachorik diff --git a/integration-tests/src/test/btrace/TraceAllTest.java b/integration-tests/src/test/btrace/TraceAllTest.java new file mode 100644 index 00000000..d0299fa6 --- /dev/null +++ b/integration-tests/src/test/btrace/TraceAllTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, Jaroslav Bachorik . + * 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. Copyright owner designates + * this particular file as subject to the "Classpath" exception as provided + * by the owner in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package traces; + +import org.openjdk.btrace.core.annotations.*; +import org.openjdk.btrace.core.BTraceUtils; +import static org.openjdk.btrace.core.BTraceUtils.*; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * + * @author Jaroslav Bachorik + */ +@BTrace(trusted = false) +public class TraceAllTest { + + private static final AtomicLong hitCnt = BTraceUtils.newAtomicLong(0); + + @OnMethod(clazz = "/.*/") + public static void doall(@ProbeMethodName(fqn = true) String pmn) { + BTraceUtils.getAndIncrement(hitCnt); +// BTraceUtils.println("invoked: " + pmn); + } + + @OnTimer(500) + public static void doRecurrent() { + long cnt = BTraceUtils.get(hitCnt); + if (cnt > 0) { + println("[invocations=" + cnt + "]"); + } + } +} diff --git a/integration-tests/src/test/java/tests/BTraceFunctionalTests.java b/integration-tests/src/test/java/tests/BTraceFunctionalTests.java index 0d47463d..aef645a6 100644 --- a/integration-tests/src/test/java/tests/BTraceFunctionalTests.java +++ b/integration-tests/src/test/java/tests/BTraceFunctionalTests.java @@ -26,6 +26,7 @@ package tests; import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.io.File; import java.io.IOException; @@ -36,6 +37,7 @@ import jdk.jfr.EventType; import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.consumer.RecordingFile; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -176,13 +178,19 @@ public void validate(String stdout, String stderr, int retcode, String jfrFile) public void testTraceAll() throws Exception { String rtVersion = System.getProperty("java.runtime.version", ""); String testJavaHome = System.getenv().get("TEST_JAVA_HOME"); - - if (testJavaHome != null) { - Properties releaseProps = new Properties(); - releaseProps.load( - Files.newInputStream(new File(testJavaHome + File.separator + "release").toPath())); - rtVersion = releaseProps.getProperty("JAVA_VERSION").replace("\"", ""); + if (testJavaHome == null) { + testJavaHome = System.getenv("JAVA_HOME"); + if (testJavaHome == null) { + testJavaHome = System.getProperty("java.home"); + } } + + assumeFalse(testJavaHome == null); + + Properties releaseProps = new Properties(); + releaseProps.load( + Files.newInputStream(new File(testJavaHome + File.separator + "release").toPath())); + rtVersion = releaseProps.getProperty("JAVA_VERSION").replace("\"", ""); if (!isVersionSafeForTraceAll(rtVersion)) { System.err.println("Skipping test for JDK " + rtVersion); return;