comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiTypeProfile.java @ 5335:439ca5ecc7dc

types profiles are now sorted in descending order of each profiled type's probability
author Doug Simon <doug.simon@oracle.com>
date Wed, 02 May 2012 14:39:45 +0200
parents 12c63380e7ff
children 4c3d953f8131
comparison
equal deleted inserted replaced
5334:ecc2b68344de 5335:439ca5ecc7dc
31 */ 31 */
32 public final class RiTypeProfile implements Serializable { 32 public final class RiTypeProfile implements Serializable {
33 33
34 private static final long serialVersionUID = -6877016333706838441L; 34 private static final long serialVersionUID = -6877016333706838441L;
35 35
36 private final RiResolvedType[] types; 36 /**
37 private final double notRecordedProbability; 37 * A profiled type that has a probability. Profiled types are naturally sorted in
38 private final double[] probabilities; 38 * descending order of their probabilities.
39 */
40 public static class ProfiledType implements Comparable<ProfiledType> {
41 public final RiResolvedType type;
42 public final double probability;
39 43
40 public RiTypeProfile(RiResolvedType[] types, double notRecordedProbability, double[] probabilites) { 44 public ProfiledType(RiResolvedType type, double probability) {
41 this.types = types; 45 this.type = type;
42 this.notRecordedProbability = notRecordedProbability; 46 this.probability = probability;
43 this.probabilities = probabilites; 47 }
48
49 @Override
50 public int compareTo(ProfiledType o) {
51 if (probability > o.probability) {
52 return -1;
53 } else if (probability < o.probability) {
54 return 1;
55 }
56 return 0;
57 }
44 } 58 }
45 59
60 private final double notRecordedProbability;
61 private final ProfiledType[] ptypes;
62
46 /** 63 /**
47 * The estimated probabilities of the different receivers. This array needs to have the same length as the array returned by 64 * Determines if an array of profiled types are sorted in descending order of their probabilities.
48 * {@link RiTypeProfile#types}.
49 */ 65 */
50 public double[] getProbabilities() { 66 public static boolean isSorted(ProfiledType[] ptypes) {
51 return probabilities; 67 for (int i = 1; i < ptypes.length; i++) {
68 if (ptypes[i - 1].probability < ptypes[i].probability) {
69 return false;
70 }
71 }
72 return true;
73 }
74
75 public RiTypeProfile(ProfiledType[] ptypes, double notRecordedProbability) {
76 this.ptypes = ptypes;
77 this.notRecordedProbability = notRecordedProbability;
78 assert isSorted(ptypes);
52 } 79 }
53 80
54 /** 81 /**
55 * Returns the estimated probability of all types that could not be recorded due to profiling limitations. 82 * Returns the estimated probability of all types that could not be recorded due to profiling limitations.
56 * @return double value >= 0.0 and <= 1.0 83 * @return double value >= 0.0 and <= 1.0
58 public double getNotRecordedProbability() { 85 public double getNotRecordedProbability() {
59 return notRecordedProbability; 86 return notRecordedProbability;
60 } 87 }
61 88
62 /** 89 /**
63 * A list of receivers for which the runtime has recorded probability information. This array needs to have the same 90 * A list of types for which the runtime has recorded probability information.
64 * length as {@link RiTypeProfile#probabilities}.
65 */ 91 */
66 public RiResolvedType[] getTypes() { 92 public ProfiledType[] getTypes() {
67 return types; 93 return ptypes;
68 } 94 }
69 } 95 }