|
53 | 53 |
|
54 | 54 | import jdk.graal.compiler.api.directives.GraalDirectives; |
55 | 55 | import jdk.graal.compiler.api.replacements.SnippetReflectionProvider; |
| 56 | +import jdk.graal.compiler.core.common.LibGraalSupport; |
56 | 57 | import jdk.graal.compiler.core.common.calc.Condition; |
57 | 58 | import jdk.graal.compiler.core.common.calc.Condition.CanonicalizedCondition; |
58 | 59 | import jdk.graal.compiler.core.common.calc.UnsignedMath; |
@@ -349,30 +350,33 @@ private boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, |
349 | 350 |
|
350 | 351 | private static void registerStringPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, boolean supportsStubBasedPlugins) { |
351 | 352 | 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; |
359 | 365 | } |
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; |
371 | 377 | } |
372 | | - return false; |
373 | | - } |
374 | | - }); |
375 | | - |
| 378 | + }); |
| 379 | + } |
376 | 380 | if (supportsStubBasedPlugins) { |
377 | 381 | r.register(new StringEqualsInvocationPlugin()); |
378 | 382 | } |
|
0 commit comments