195 throw new GraalError(e); 196 } 197 STRING_CODER_FIELD = coder; 198 } 199 200 private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) { 201 final Registration r = new Registration(plugins, String.class, bytecodeProvider); 202 r.register1("hashCode", Receiver.class, new InvocationPlugin() { 203 @Override 204 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { 205 if (receiver.isConstant()) { 206 String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant()); 207 if (s != null) { 208 b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode()))); 209 return true; 210 } 211 } 212 return false; 213 } 214 }); 215 216 if (Java8OrEarlier) { 217 r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class); 218 219 r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin()); 220 221 Registration sr = new Registration(plugins, StringSubstitutions.class); 222 sr.register1("getValue", String.class, new InvocationPlugin() { 223 @Override 224 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { 225 ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD); 226 b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), 227 b.getOptions(), b.getAssumptions(), value, field, false, false)); 228 return true; 229 } 230 }); 231 } else { 232 r.registerMethodSubstitution(JDK9StringSubstitutions.class, "equals", Receiver.class, Object.class); 233 Registration utf16sub = new Registration(plugins, StringUTF16Substitutions.class, bytecodeProvider); 234 utf16sub.register2("getCharDirect", byte[].class, int.class, new InvocationPlugin() { | 195 throw new GraalError(e); 196 } 197 STRING_CODER_FIELD = coder; 198 } 199 200 private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) { 201 final Registration r = new Registration(plugins, String.class, bytecodeProvider); 202 r.register1("hashCode", Receiver.class, new InvocationPlugin() { 203 @Override 204 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { 205 if (receiver.isConstant()) { 206 String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant()); 207 if (s != null) { 208 b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode()))); 209 return true; 210 } 211 } 212 return false; 213 } 214 }); 215 r.register1("intern", Receiver.class, new InvocationPlugin() { 216 @Override 217 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) { 218 if (receiver.isConstant()) { 219 String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant()); 220 if (s != null) { 221 JavaConstant interned = snippetReflection.forObject(s.intern()); 222 b.addPush(JavaKind.Object, b.add(ConstantNode.forConstant(interned, b.getMetaAccess(), b.getGraph()))); 223 return true; 224 } 225 } 226 return false; 227 } 228 }); 229 230 if (Java8OrEarlier) { 231 r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class); 232 233 r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin()); 234 235 Registration sr = new Registration(plugins, StringSubstitutions.class); 236 sr.register1("getValue", String.class, new InvocationPlugin() { 237 @Override 238 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) { 239 ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD); 240 b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), 241 b.getOptions(), b.getAssumptions(), value, field, false, false)); 242 return true; 243 } 244 }); 245 } else { 246 r.registerMethodSubstitution(JDK9StringSubstitutions.class, "equals", Receiver.class, Object.class); 247 Registration utf16sub = new Registration(plugins, StringUTF16Substitutions.class, bytecodeProvider); 248 utf16sub.register2("getCharDirect", byte[].class, int.class, new InvocationPlugin() { |