Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
// Cast from int value to narrow type
#define CHECKED_CAST(result, T, thing) \
result = static_cast<T>(thing); \
assert(static_cast<int>(result) == thing, "failed: %d != %d", static_cast<int>(result), thing);
guarantee(static_cast<int>(result) == thing, "failed: %d != %d", static_cast<int>(result), thing);
Copy link
Member Author

@dougxc dougxc Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not on a hot path and so can afford to be a guarantee. That said, I've no strong objection to leaving it as an assert.


//---------------------------------------------------------------------------------
// NMethod statistics
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/jvmci/jvmciCodeInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnTortugo this may be of interest to you.

} else {
CompileTask::print(tty, nm, "(hosted JVMCI compilation)");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}