A DESCRIPTION OF THE PROBLEM :
This pertains to a comment in c1_GraphBuilder.cpp:
void GraphBuilder::load_constant() {
ciConstant con = stream()->get_constant();
if (con.basic_type() == T_ILLEGAL) {
// FIXME: an unresolved Dynamic constant can get here,
// and that should not terminate the whole compilation.
BAILOUT("could not resolve a constant");
The code I'm generating utilizes dynamic constants, but the code which references them isn't always reached. This leads to terrible performance because HotSpot never compiles the code, and instead it's only interpreted.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
To reproduce, generate a method which doesn't reach a dynamic constant. Run with -XX:+PrintCompilation and observe the message, "could not resolve a constant".
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the code to compile even when the dynamic constant wasn't reached.
ACTUAL -
org.cojen.maker.ClassMaker-0::test (10 bytes) COMPILE SKIPPED: could not resolve a constant (retry at different tier)
---------- BEGIN SOURCE ----------
This test depends on the open source Cojen/Maker project, because it's much easier for generating Java bytecode than anything else.
import org.cojen.maker.*;
public class Condy {
public static void main(String[] args) throws Exception {
Object a = new Object();
Object b = new Object();
var cm = ClassMaker.begin().public_();
var mm = cm.addMethod(Object.class, "test", int.class).public_().static_();
Label other = mm.label();
mm.param(0).ifNe(0, other);
mm.return_(mm.var(Object.class).setExact(a));
other.here();
// Never reached, and so the dynamic constant which yields 'b' never resolves.
mm.return_(mm.var(Object.class).setExact(b));
var method = cm.finish().getMethod("test", int.class);
while (true) {
var result = method.invoke(null, 0); // pass 0 to never reach the 'b' case
if (result == a) {
x++;
}
}
}
static volatile int x;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Forcibly resolve all dynamic constants in a static initializer and then only reference them via private static final fields. This effectively defeats the entire purpose of the dynamic constant feature, because the constants aren't dynamically generated.
FREQUENCY : always