Mercurial > hg > truffle
comparison graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ArraySubstitutions.java @ 20851:91a25b017111
converted @MethodSubstitutions for java.lang.reflect.Array to MethodSubstitutionPlugins
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 08 Apr 2015 10:50:06 +0200 |
parents | 14e703edb2ab |
children | 66d45b977e44 |
comparison
equal
deleted
inserted
replaced
20850:9d4a36560833 | 20851:91a25b017111 |
---|---|
23 package com.oracle.graal.replacements; | 23 package com.oracle.graal.replacements; |
24 | 24 |
25 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; | 25 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; |
26 | 26 |
27 import com.oracle.graal.api.meta.*; | 27 import com.oracle.graal.api.meta.*; |
28 import com.oracle.graal.api.replacements.*; | |
29 import com.oracle.graal.nodes.*; | 28 import com.oracle.graal.nodes.*; |
30 import com.oracle.graal.nodes.java.*; | 29 import com.oracle.graal.nodes.java.*; |
31 | 30 |
32 /** | 31 /** |
33 * Substitutions for {@link java.lang.reflect.Array} methods. | 32 * Substitutions for {@link java.lang.reflect.Array} methods. |
34 */ | 33 */ |
35 @ClassSubstitution(java.lang.reflect.Array.class) | |
36 public class ArraySubstitutions { | 34 public class ArraySubstitutions { |
37 | 35 |
38 @MethodSubstitution | |
39 public static Object newInstance(Class<?> componentType, int length) throws NegativeArraySizeException { | 36 public static Object newInstance(Class<?> componentType, int length) throws NegativeArraySizeException { |
40 // The error cases must be handled here since DynamicNewArrayNode can only deoptimize the | 37 // The error cases must be handled here since DynamicNewArrayNode can only deoptimize the |
41 // caller in response to exceptions. | 38 // caller in response to exceptions. |
42 if (probability(SLOW_PATH_PROBABILITY, length < 0)) { | 39 if (probability(SLOW_PATH_PROBABILITY, length < 0)) { |
43 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | 40 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
46 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | 43 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
47 } | 44 } |
48 return DynamicNewArrayNode.newArray(GuardingPiNode.asNonNullClass(componentType), length); | 45 return DynamicNewArrayNode.newArray(GuardingPiNode.asNonNullClass(componentType), length); |
49 } | 46 } |
50 | 47 |
51 @MethodSubstitution | |
52 public static int getLength(Object array) { | 48 public static int getLength(Object array) { |
53 if (!array.getClass().isArray()) { | 49 if (!array.getClass().isArray()) { |
54 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | 50 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
55 } | 51 } |
56 return ArrayLengthNode.arrayLength(array); | 52 return ArrayLengthNode.arrayLength(array); |