Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.max.criutils/src/com/oracle/max/criutils/TypeCheckHints.java @ 5541:b4c406861c33
More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 09 Jun 2012 16:52:12 +0200 |
parents | 426c605c9d3c |
children | b6617d13ea44 |
comparison
equal
deleted
inserted
replaced
5540:a891c53a295b | 5541:b4c406861c33 |
---|---|
25 import java.lang.reflect.*; | 25 import java.lang.reflect.*; |
26 import java.util.*; | 26 import java.util.*; |
27 | 27 |
28 import com.oracle.graal.api.code.*; | 28 import com.oracle.graal.api.code.*; |
29 import com.oracle.graal.api.meta.*; | 29 import com.oracle.graal.api.meta.*; |
30 import com.oracle.graal.api.meta.RiTypeProfile.*; | 30 import com.oracle.graal.api.meta.JavaTypeProfile.*; |
31 | 31 |
32 /** | 32 /** |
33 * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) | 33 * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) |
34 * based on the target type of the check and any profiling information available for the instruction. | 34 * based on the target type of the check and any profiling information available for the instruction. |
35 */ | 35 */ |
36 public class TypeCheckHints { | 36 public class TypeCheckHints { |
37 | 37 |
38 private static final RiResolvedType[] NO_TYPES = {}; | 38 private static final ResolvedJavaType[] NO_TYPES = {}; |
39 | 39 |
40 /** | 40 /** |
41 * If true, then {@link #types} contains the only possible type that could pass the type check | 41 * If true, then {@link #types} contains the only possible type that could pass the type check |
42 * because the target of the type check is a final class or has been speculated to be a final class. | 42 * because the target of the type check is a final class or has been speculated to be a final class. |
43 */ | 43 */ |
44 public final boolean exact; | 44 public final boolean exact; |
45 | 45 |
46 /** | 46 /** |
47 * The most likely types that the type check instruction will see. | 47 * The most likely types that the type check instruction will see. |
48 */ | 48 */ |
49 public final RiResolvedType[] types; | 49 public final ResolvedJavaType[] types; |
50 | 50 |
51 /** | 51 /** |
52 * Derives hint information for use when generating the code for a type check instruction. | 52 * Derives hint information for use when generating the code for a type check instruction. |
53 * | 53 * |
54 * @param type the target type of the type check | 54 * @param type the target type of the type check |
56 * @param assumptions the object in which speculations are recorded. This is null if speculations are not supported. | 56 * @param assumptions the object in which speculations are recorded. This is null if speculations are not supported. |
57 * @param minHintHitProbability if the probability that the type check will hit one the profiled types (up to | 57 * @param minHintHitProbability if the probability that the type check will hit one the profiled types (up to |
58 * {@code maxHints}) is below this value, then {@link #types} will be null | 58 * {@code maxHints}) is below this value, then {@link #types} will be null |
59 * @param maxHints the maximum length of {@link #types} | 59 * @param maxHints the maximum length of {@link #types} |
60 */ | 60 */ |
61 public TypeCheckHints(RiResolvedType type, RiTypeProfile profile, CiAssumptions assumptions, double minHintHitProbability, int maxHints) { | 61 public TypeCheckHints(ResolvedJavaType type, JavaTypeProfile profile, CiAssumptions assumptions, double minHintHitProbability, int maxHints) { |
62 if (type != null && isFinalClass(type)) { | 62 if (type != null && isFinalClass(type)) { |
63 types = new RiResolvedType[] {type}; | 63 types = new ResolvedJavaType[] {type}; |
64 exact = true; | 64 exact = true; |
65 } else { | 65 } else { |
66 RiResolvedType uniqueSubtype = type == null ? null : type.uniqueConcreteSubtype(); | 66 ResolvedJavaType uniqueSubtype = type == null ? null : type.uniqueConcreteSubtype(); |
67 if (uniqueSubtype != null) { | 67 if (uniqueSubtype != null) { |
68 types = new RiResolvedType[] {uniqueSubtype}; | 68 types = new ResolvedJavaType[] {uniqueSubtype}; |
69 if (assumptions != null) { | 69 if (assumptions != null) { |
70 assumptions.recordConcreteSubtype(type, uniqueSubtype); | 70 assumptions.recordConcreteSubtype(type, uniqueSubtype); |
71 exact = true; | 71 exact = true; |
72 } else { | 72 } else { |
73 exact = false; | 73 exact = false; |
74 } | 74 } |
75 } else { | 75 } else { |
76 exact = false; | 76 exact = false; |
77 RiResolvedType[] hintTypes = NO_TYPES; | 77 ResolvedJavaType[] hintTypes = NO_TYPES; |
78 RiTypeProfile typeProfile = profile; | 78 JavaTypeProfile typeProfile = profile; |
79 if (typeProfile != null) { | 79 if (typeProfile != null) { |
80 double notRecordedTypes = typeProfile.getNotRecordedProbability(); | 80 double notRecordedTypes = typeProfile.getNotRecordedProbability(); |
81 ProfiledType[] ptypes = typeProfile.getTypes(); | 81 ProfiledType[] ptypes = typeProfile.getTypes(); |
82 if (notRecordedTypes < (1D - minHintHitProbability) && ptypes != null && ptypes.length > 0) { | 82 if (notRecordedTypes < (1D - minHintHitProbability) && ptypes != null && ptypes.length > 0) { |
83 hintTypes = new RiResolvedType[ptypes.length]; | 83 hintTypes = new ResolvedJavaType[ptypes.length]; |
84 int hintCount = 0; | 84 int hintCount = 0; |
85 double totalHintProbability = 0.0d; | 85 double totalHintProbability = 0.0d; |
86 for (ProfiledType ptype : ptypes) { | 86 for (ProfiledType ptype : ptypes) { |
87 RiResolvedType hint = ptype.type; | 87 ResolvedJavaType hint = ptype.type; |
88 if (type != null && hint.isSubtypeOf(type)) { | 88 if (type != null && hint.isSubtypeOf(type)) { |
89 hintTypes[hintCount++] = hint; | 89 hintTypes[hintCount++] = hint; |
90 totalHintProbability += ptype.probability; | 90 totalHintProbability += ptype.probability; |
91 } | 91 } |
92 } | 92 } |
103 this.types = hintTypes; | 103 this.types = hintTypes; |
104 } | 104 } |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 public static boolean isFinalClass(RiResolvedType type) { | 108 public static boolean isFinalClass(ResolvedJavaType type) { |
109 return Modifier.isFinal(type.accessFlags()) || (type.isArrayClass() && Modifier.isFinal(type.componentType().accessFlags())); | 109 return Modifier.isFinal(type.accessFlags()) || (type.isArrayClass() && Modifier.isFinal(type.componentType().accessFlags())); |
110 } | 110 } |
111 } | 111 } |