Mercurial > hg > truffle
comparison graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ArraySubstitutions.java @ 21925:64475dbf6aec
Move instantiation checks from methods substitutions to the lowering of DynamicNewInstanceNode and DynamicNewArrayNode, so that Unsafe.allocateInstance and Array.newInstance can be intrinsified to a single node.
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Wed, 10 Jun 2015 17:23:19 -0700 |
parents | 2c6802ac343c |
children |
comparison
equal
deleted
inserted
replaced
21907:f6fd9fb11816 | 21925:64475dbf6aec |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.graal.replacements; | 23 package com.oracle.graal.replacements; |
24 | 24 |
25 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; | |
26 | |
27 import com.oracle.graal.api.directives.*; | |
28 import com.oracle.graal.nodes.*; | 25 import com.oracle.graal.nodes.*; |
29 import com.oracle.graal.nodes.java.*; | 26 import com.oracle.graal.nodes.java.*; |
30 import com.oracle.jvmci.meta.*; | 27 import com.oracle.jvmci.meta.*; |
31 | 28 |
32 // JaCoCo Exclude | 29 // JaCoCo Exclude |
34 /** | 31 /** |
35 * Substitutions for {@link java.lang.reflect.Array} methods. | 32 * Substitutions for {@link java.lang.reflect.Array} methods. |
36 */ | 33 */ |
37 public class ArraySubstitutions { | 34 public class ArraySubstitutions { |
38 | 35 |
39 public static Object newInstance(Class<?> componentType, int length) throws NegativeArraySizeException { | |
40 // The error cases must be handled here since DynamicNewArrayNode can only deoptimize the | |
41 // caller in response to exceptions. | |
42 if (probability(SLOW_PATH_PROBABILITY, length < 0)) { | |
43 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | |
44 } | |
45 if (probability(SLOW_PATH_PROBABILITY, componentType == void.class)) { | |
46 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | |
47 } | |
48 return DynamicNewArrayNode.newArray(GraalDirectives.guardingNonNull(componentType), length); | |
49 } | |
50 | |
51 public static int getLength(Object array) { | 36 public static int getLength(Object array) { |
52 if (!array.getClass().isArray()) { | 37 if (!array.getClass().isArray()) { |
53 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); | 38 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); |
54 } | 39 } |
55 return ArrayLengthNode.arrayLength(array); | 40 return ArrayLengthNode.arrayLength(array); |