Skip to content

Commit 3d40f51

Browse files
committed
disable some String intrinsics that cannot work in libgraal
1 parent acd1fe8 commit 3d40f51

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
import jdk.graal.compiler.api.directives.GraalDirectives;
5555
import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
56+
import jdk.graal.compiler.core.common.LibGraalSupport;
5657
import jdk.graal.compiler.core.common.calc.Condition;
5758
import jdk.graal.compiler.core.common.calc.Condition.CanonicalizedCondition;
5859
import jdk.graal.compiler.core.common.calc.UnsignedMath;
@@ -349,30 +350,33 @@ private boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field,
349350

350351
private static void registerStringPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, boolean supportsStubBasedPlugins) {
351352
final Registration r = new Registration(plugins, String.class);
352-
r.register(new InvocationPlugin("hashCode", Receiver.class) {
353-
@Override
354-
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
355-
String s = asConstantObject(b, String.class, receiver.get(false));
356-
if (s != null) {
357-
b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
358-
return true;
353+
if (!LibGraalSupport.inLibGraalRuntime()) {
354+
// These intrinsics require converting constants to String objects in
355+
// the current heap which is not not supported on libgraal.
356+
r.register(new InvocationPlugin("hashCode", Receiver.class) {
357+
@Override
358+
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
359+
String s = asConstantObject(b, String.class, receiver.get(false));
360+
if (s != null) {
361+
b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
362+
return true;
363+
}
364+
return false;
359365
}
360-
return false;
361-
}
362-
});
363-
r.register(new InvocationPlugin("intern", Receiver.class) {
364-
@Override
365-
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
366-
String s = asConstantObject(b, String.class, receiver.get(false));
367-
if (s != null) {
368-
JavaConstant interned = snippetReflection.forObject(s.intern());
369-
b.addPush(JavaKind.Object, b.add(ConstantNode.forConstant(interned, b.getMetaAccess(), b.getGraph())));
370-
return true;
366+
});
367+
r.register(new InvocationPlugin("intern", Receiver.class) {
368+
@Override
369+
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
370+
String s = asConstantObject(b, String.class, receiver.get(false));
371+
if (s != null) {
372+
JavaConstant interned = snippetReflection.forObject(s.intern());
373+
b.addPush(JavaKind.Object, b.add(ConstantNode.forConstant(interned, b.getMetaAccess(), b.getGraph())));
374+
return true;
375+
}
376+
return false;
371377
}
372-
return false;
373-
}
374-
});
375-
378+
});
379+
}
376380
if (supportsStubBasedPlugins) {
377381
r.register(new StringEqualsInvocationPlugin());
378382
}

0 commit comments

Comments
 (0)