8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.replacements;
26
27 import static java.util.FormattableFlags.ALTERNATE;
28 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
29 import static org.graalvm.compiler.debug.DebugContext.applyFormattingFlagsAndWidth;
30 import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets;
31 import static org.graalvm.compiler.graph.iterators.NodePredicates.isNotA;
32 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
33 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
34 import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required;
35 import static jdk.internal.vm.compiler.word.LocationIdentity.any;
36
37 import java.lang.reflect.Array;
38 import java.lang.reflect.Method;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.Formattable;
44 import java.util.Formatter;
45 import java.util.LinkedHashMap;
46 import java.util.List;
47 import java.util.Map;
195 Lazy(ResolvedJavaMethod method) {
196 int count = method.getSignature().getParameterCount(hasReceiver(method));
197 constantParameters = new boolean[count];
198 varargsParameters = new boolean[count];
199 nonNullParameters = new boolean[count];
200 int offset = hasReceiver(method) ? 1 : 0;
201 for (int i = offset; i < count; i++) {
202 constantParameters[i] = method.getParameterAnnotation(ConstantParameter.class, i - offset) != null;
203 varargsParameters[i] = method.getParameterAnnotation(VarargsParameter.class, i - offset) != null;
204 nonNullParameters[i] = method.getParameterAnnotation(NonNullParameter.class, i - offset) != null;
205
206 assert !constantParameters[i - offset] || !varargsParameters[i - offset] : "Parameter cannot be annotated with both @" + ConstantParameter.class.getSimpleName() + " and @" +
207 VarargsParameter.class.getSimpleName();
208 }
209 if (method.hasReceiver()) {
210 // Receiver must be constant.
211 assert !constantParameters[0];
212 constantParameters[0] = true;
213 }
214
215 // Retrieve the names only when assertions are turned on.
216 assert initNames(method, count);
217 }
218
219 final boolean[] constantParameters;
220 final boolean[] varargsParameters;
221 final boolean[] nonNullParameters;
222
223 /**
224 * The parameter names, taken from the local variables table. Only used for assertion
225 * checking, so use only within an assert statement.
226 */
227 String[] names;
228
229 private boolean initNames(ResolvedJavaMethod method, int parameterCount) {
230 names = new String[parameterCount];
231 int offset = 0;
232 if (method.hasReceiver()) {
233 names[0] = "this";
234 offset = 1;
235 }
236 Parameter[] params = method.getParameters();
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package org.graalvm.compiler.replacements;
26
27 import static java.util.FormattableFlags.ALTERNATE;
28 import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;
29 import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
30 import static org.graalvm.compiler.debug.DebugContext.applyFormattingFlagsAndWidth;
31 import static org.graalvm.compiler.debug.DebugOptions.DebugStubsAndSnippets;
32 import static org.graalvm.compiler.graph.iterators.NodePredicates.isNotA;
33 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
34 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
35 import static org.graalvm.compiler.phases.common.DeadCodeEliminationPhase.Optionality.Required;
36 import static jdk.internal.vm.compiler.word.LocationIdentity.any;
37
38 import java.lang.reflect.Array;
39 import java.lang.reflect.Method;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.Collections;
44 import java.util.Formattable;
45 import java.util.Formatter;
46 import java.util.LinkedHashMap;
47 import java.util.List;
48 import java.util.Map;
196 Lazy(ResolvedJavaMethod method) {
197 int count = method.getSignature().getParameterCount(hasReceiver(method));
198 constantParameters = new boolean[count];
199 varargsParameters = new boolean[count];
200 nonNullParameters = new boolean[count];
201 int offset = hasReceiver(method) ? 1 : 0;
202 for (int i = offset; i < count; i++) {
203 constantParameters[i] = method.getParameterAnnotation(ConstantParameter.class, i - offset) != null;
204 varargsParameters[i] = method.getParameterAnnotation(VarargsParameter.class, i - offset) != null;
205 nonNullParameters[i] = method.getParameterAnnotation(NonNullParameter.class, i - offset) != null;
206
207 assert !constantParameters[i - offset] || !varargsParameters[i - offset] : "Parameter cannot be annotated with both @" + ConstantParameter.class.getSimpleName() + " and @" +
208 VarargsParameter.class.getSimpleName();
209 }
210 if (method.hasReceiver()) {
211 // Receiver must be constant.
212 assert !constantParameters[0];
213 constantParameters[0] = true;
214 }
215
216 // Retrieve the names only when assertions are turned on. Parameter annotations are
217 // unsupported in the native image.
218 assert IS_IN_NATIVE_IMAGE || initNames(method, count);
219 }
220
221 final boolean[] constantParameters;
222 final boolean[] varargsParameters;
223 final boolean[] nonNullParameters;
224
225 /**
226 * The parameter names, taken from the local variables table. Only used for assertion
227 * checking, so use only within an assert statement.
228 */
229 String[] names;
230
231 private boolean initNames(ResolvedJavaMethod method, int parameterCount) {
232 names = new String[parameterCount];
233 int offset = 0;
234 if (method.hasReceiver()) {
235 names[0] = "this";
236 offset = 1;
237 }
238 Parameter[] params = method.getParameters();
|