diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index 01ace66f4dee4..56ba76a806e4f 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -112,7 +112,7 @@ // Cast from int value to narrow type #define CHECKED_CAST(result, T, thing) \ result = static_cast(thing); \ - assert(static_cast(result) == thing, "failed: %d != %d", static_cast(result), thing); + guarantee(static_cast(result) == thing, "failed: %d != %d", static_cast(result), thing); //--------------------------------------------------------------------------------- // NMethod statistics diff --git a/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp b/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp index 79aaacec8098b..3a9fbc54bf941 100644 --- a/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp +++ b/src/hotspot/share/jvmci/jvmciCodeInstaller.cpp @@ -825,7 +825,13 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler, // Since this compilation didn't pass through the broker it wasn't logged yet. if (PrintCompilation) { ttyLocker ttyl; - CompileTask::print(tty, nm, "(hosted JVMCI compilation)"); + if (name != nullptr) { + stringStream st; + st.print_cr("(hosted JVMCI compilation: %s)", name); + CompileTask::print(tty, nm, st.as_string()); + } else { + CompileTask::print(tty, nm, "(hosted JVMCI compilation)"); + } } } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/InstalledCode.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/InstalledCode.java index 489cca81c7bff..62c0b6091468e 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/InstalledCode.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/code/InstalledCode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2025, 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,24 @@ public class InstalledCode { protected final String name; + /** + * The maximum length of an InstalledCode name. This name is typically installed into + * the code cache so it should have a reasonable limit. + */ + public static final int MAX_NAME_LENGTH = 2048; + + /** + * @param name the name to be associated with the installed code. Can be null and + * must be no longer than {@link #MAX_NAME_LENGTH}. + * + * @throws IllegalArgumentException if {@code name.length >} {@link #MAX_NAME_LENGTH} + */ public InstalledCode(String name) { + if (name != null && name.length() > MAX_NAME_LENGTH) { + String msg = String.format("name length (%d) is greater than %d (name[0:%s] = %s)", + name.length(), MAX_NAME_LENGTH, MAX_NAME_LENGTH, name.substring(0, MAX_NAME_LENGTH)); + throw new IllegalArgumentException(msg); + } this.name = name; } diff --git a/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/InstalledCodeTest.java b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/InstalledCodeTest.java new file mode 100644 index 0000000000000..f7e68043da785 --- /dev/null +++ b/test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/InstalledCodeTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025, 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 8355034 + * @requires vm.jvmci + * @modules jdk.internal.vm.ci/jdk.vm.ci.code + * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.vm.ci.code.test.InstalledCodeTest + */ + +package jdk.vm.ci.code.test; + +import jdk.vm.ci.code.InstalledCode; +import org.junit.Assert; +import org.junit.Test; + +public class InstalledCodeTest { + + @Test + public void testNullName() { + new InstalledCode(null); + } + + @Test + public void testTooLongName() { + String longName = new String(new char[InstalledCode.MAX_NAME_LENGTH]).replace('\0', 'A'); + new InstalledCode(longName); + try { + String tooLongName = longName + "X"; + new InstalledCode(tooLongName); + } catch (IllegalArgumentException iae) { + // Threw IllegalArgumentException as expected. + return; + } + Assert.fail("expected IllegalArgumentException"); + } +}