124 registerObjectPlugins(plugins);
125 registerClassPlugins(plugins);
126 registerMathPlugins(plugins, allowDeoptimization);
127 registerUnsignedMathPlugins(plugins);
128 registerStringPlugins(plugins, bytecodeProvider, snippetReflection);
129 registerCharacterPlugins(plugins);
130 registerShortPlugins(plugins);
131 registerIntegerLongPlugins(plugins, JavaKind.Int);
132 registerIntegerLongPlugins(plugins, JavaKind.Long);
133 registerFloatPlugins(plugins);
134 registerDoublePlugins(plugins);
135 registerArraysPlugins(plugins, bytecodeProvider);
136 registerArrayPlugins(plugins, bytecodeProvider);
137 registerUnsafePlugins(plugins, bytecodeProvider);
138 registerEdgesPlugins(metaAccess, plugins);
139 registerGraalDirectivesPlugins(plugins);
140 registerBoxingPlugins(plugins);
141 registerJMHBlackholePlugins(plugins, bytecodeProvider);
142 registerJFRThrowablePlugins(plugins, bytecodeProvider);
143 registerMethodHandleImplPlugins(plugins, snippetReflection, bytecodeProvider);
144 }
145
146 private static final Field STRING_VALUE_FIELD;
147
148 static {
149 try {
150 STRING_VALUE_FIELD = String.class.getDeclaredField("value");
151 } catch (NoSuchFieldException e) {
152 throw new GraalError(e);
153 }
154 }
155
156 private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
157 final Registration r = new Registration(plugins, String.class, bytecodeProvider);
158 r.register1("hashCode", Receiver.class, new InvocationPlugin() {
159 @Override
160 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
161 if (receiver.isConstant()) {
162 String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
163 b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
893 } else if (falseCount == 0 || trueCount == 0) {
894 boolean expected = falseCount == 0;
895 LogicNode condition = b.addWithInputs(
896 IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)),
897 NodeView.DEFAULT));
898 b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
899 newResult = b.add(ConstantNode.forBoolean(expected));
900 } else {
901 // We cannot use BranchProbabilityNode here since there's no guarantee
902 // the result of MethodHandleImpl.profileBoolean() is used as the
903 // test in an `if` statement (as required by BranchProbabilityNode).
904 }
905 }
906 b.addPush(JavaKind.Boolean, newResult);
907 return true;
908 }
909 return false;
910 }
911 });
912 }
913 }
|
124 registerObjectPlugins(plugins);
125 registerClassPlugins(plugins);
126 registerMathPlugins(plugins, allowDeoptimization);
127 registerUnsignedMathPlugins(plugins);
128 registerStringPlugins(plugins, bytecodeProvider, snippetReflection);
129 registerCharacterPlugins(plugins);
130 registerShortPlugins(plugins);
131 registerIntegerLongPlugins(plugins, JavaKind.Int);
132 registerIntegerLongPlugins(plugins, JavaKind.Long);
133 registerFloatPlugins(plugins);
134 registerDoublePlugins(plugins);
135 registerArraysPlugins(plugins, bytecodeProvider);
136 registerArrayPlugins(plugins, bytecodeProvider);
137 registerUnsafePlugins(plugins, bytecodeProvider);
138 registerEdgesPlugins(metaAccess, plugins);
139 registerGraalDirectivesPlugins(plugins);
140 registerBoxingPlugins(plugins);
141 registerJMHBlackholePlugins(plugins, bytecodeProvider);
142 registerJFRThrowablePlugins(plugins, bytecodeProvider);
143 registerMethodHandleImplPlugins(plugins, snippetReflection, bytecodeProvider);
144 registerJcovCollectPlugins(plugins, bytecodeProvider);
145 }
146
147 private static final Field STRING_VALUE_FIELD;
148
149 static {
150 try {
151 STRING_VALUE_FIELD = String.class.getDeclaredField("value");
152 } catch (NoSuchFieldException e) {
153 throw new GraalError(e);
154 }
155 }
156
157 private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
158 final Registration r = new Registration(plugins, String.class, bytecodeProvider);
159 r.register1("hashCode", Receiver.class, new InvocationPlugin() {
160 @Override
161 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
162 if (receiver.isConstant()) {
163 String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
164 b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
894 } else if (falseCount == 0 || trueCount == 0) {
895 boolean expected = falseCount == 0;
896 LogicNode condition = b.addWithInputs(
897 IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)),
898 NodeView.DEFAULT));
899 b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
900 newResult = b.add(ConstantNode.forBoolean(expected));
901 } else {
902 // We cannot use BranchProbabilityNode here since there's no guarantee
903 // the result of MethodHandleImpl.profileBoolean() is used as the
904 // test in an `if` statement (as required by BranchProbabilityNode).
905 }
906 }
907 b.addPush(JavaKind.Boolean, newResult);
908 return true;
909 }
910 return false;
911 }
912 });
913 }
914
915 /**
916 * Registers a plugin to ignore {@code com.sun.tdk.jcov.runtime.Collect.hit} within an
917 * intrinsic.
918 */
919 private static void registerJcovCollectPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
920 Registration r = new Registration(plugins, "com.sun.tdk.jcov.runtime.Collect", bytecodeProvider);
921 r.register1("hit", int.class, new InvocationPlugin() {
922 @Override
923 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
924 if (b.parsingIntrinsic()) {
925 return true;
926 }
927 return false;
928 }
929 });
930 }
931 }
|