annotate graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/JavaTypeProfile.java @ 9760:c76b43ed5089

Added infrastructure for recording invoked methods in the profiling information.
author Christian Haeubl <haeubl@ssw.jku.at>
date Fri, 17 May 2013 15:38:22 +0200
parents 708aea0e5a25
children 828f342cb275
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5541
diff changeset
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5369
diff changeset
23 package com.oracle.graal.api.meta;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
25 import java.util.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
27 import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType;
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
28 import com.oracle.graal.api.meta.ProfilingInfo.TriState;
8659
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
29
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
31 * This profile object represents the type profile at a specific BCI. The precision of the supplied
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
32 * values may vary, but a runtime that provides this information should be aware that it will be
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
33 * used to guide performance-critical decisions like speculative inlining, etc.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 */
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
35 public final class JavaTypeProfile extends AbstractJavaProfile<ProfiledType, ResolvedJavaType> {
5321
12c63380e7ff removed empty javadoc for generated serialVersionUID fields
Doug Simon <doug.simon@oracle.com>
parents: 4456
diff changeset
36
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
37 private static final long serialVersionUID = -6877016333706838441L;
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
38 private static final ProfiledType[] EMPTY_ARRAY = new ProfiledType[0];
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39
8659
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
40 private final TriState nullSeen;
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5321
diff changeset
41
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
42 public JavaTypeProfile(TriState nullSeen, double notRecordedProbability, ProfiledType[] pitems) {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
43 super(notRecordedProbability, pitems);
8659
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
44 this.nullSeen = nullSeen;
4456
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
45 }
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
46
f4c82dd4619e inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents: 4453
diff changeset
47 /**
8659
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
48 * Returns whether a null value was at the type check.
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
49 */
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
50 public TriState getNullSeen() {
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
51 return nullSeen;
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
52 }
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
53
bc7bb895e359 incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
54 /**
8909
06e08471949e expanded type check hints to support use of negative hints (i.e., profiled types that failed the corresponding type check)
Doug Simon <doug.simon@oracle.com>
parents: 8659
diff changeset
55 * A list of types for which the runtime has recorded probability information. Note that this
06e08471949e expanded type check hints to support use of negative hints (i.e., profiled types that failed the corresponding type check)
Doug Simon <doug.simon@oracle.com>
parents: 8659
diff changeset
56 * includes both positive and negative types where a positive type is a subtype of the checked
06e08471949e expanded type check hints to support use of negative hints (i.e., profiled types that failed the corresponding type check)
Doug Simon <doug.simon@oracle.com>
parents: 8659
diff changeset
57 * type and a negative type is not.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 */
5335
439ca5ecc7dc types profiles are now sorted in descending order of each profiled type's probability
Doug Simon <doug.simon@oracle.com>
parents: 5321
diff changeset
59 public ProfiledType[] getTypes() {
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
60 return getItems();
9366
f1170c277b7b Implement instanceof after instanceof swapping.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8909
diff changeset
61 }
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
62
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
63 public JavaTypeProfile restrict(JavaTypeProfile otherProfile) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
64 if (otherProfile.getNotRecordedProbability() > 0.0) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
65 // Not useful for restricting since there is an unknown set of types occuring.
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
66 return this;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
67 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
68
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
69 if (this.getNotRecordedProbability() > 0.0) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
70 // We are unrestricted, so the other profile is always a better estimate.
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
71 return otherProfile;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
72 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
73
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
74 ArrayList<ProfiledType> result = new ArrayList<>();
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
75 for (int i = 0; i < getItems().length; i++) {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
76 ProfiledType ptype = getItems()[i];
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
77 ResolvedJavaType type = ptype.getItem();
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
78 if (otherProfile.isIncluded(type)) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
79 result.add(ptype);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
80 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
81 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
82
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
83 TriState newNullSeen = (otherProfile.getNullSeen() == TriState.FALSE) ? TriState.FALSE : getNullSeen();
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
84 double newNotRecorded = getNotRecordedProbability();
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
85 return createAdjustedProfile(result, newNullSeen, newNotRecorded);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
86 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
87
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
88 public JavaTypeProfile restrict(ResolvedJavaType declaredType, boolean nonNull) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
89 ArrayList<ProfiledType> result = new ArrayList<>();
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
90 for (int i = 0; i < getItems().length; i++) {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
91 ProfiledType ptype = getItems()[i];
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
92 ResolvedJavaType type = ptype.getItem();
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
93 if (declaredType.isAssignableFrom(type)) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
94 result.add(ptype);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
95 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
96 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
97
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
98 TriState newNullSeen = (nonNull) ? TriState.FALSE : getNullSeen();
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
99 double newNotRecorded = this.getNotRecordedProbability();
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
100 // Assume for the types not recorded, the incompatibility rate is the same.
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
101 if (getItems().length != 0) {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
102 newNotRecorded *= ((double) result.size() / (double) getItems().length);
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
103 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
104 return createAdjustedProfile(result, newNullSeen, newNotRecorded);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
105 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
106
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
107 private JavaTypeProfile createAdjustedProfile(ArrayList<ProfiledType> result, TriState newNullSeen, double newNotRecorded) {
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
108 if (result.size() != this.getItems().length || newNotRecorded != getNotRecordedProbability() || newNullSeen != getNullSeen()) {
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
109 if (result.size() == 0) {
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
110 return new JavaTypeProfile(newNullSeen, 1.0, EMPTY_ARRAY);
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
111 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
112 double probabilitySum = 0.0;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
113 for (int i = 0; i < result.size(); i++) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
114 probabilitySum += result.get(i).getProbability();
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
115 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
116 probabilitySum += newNotRecorded;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
117
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
118 double factor = 1.0 / probabilitySum; // Normalize to 1.0
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
119 assert factor > 1.0;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
120 ProfiledType[] newResult = new ProfiledType[result.size()];
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
121 for (int i = 0; i < newResult.length; ++i) {
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
122 ProfiledType curType = result.get(i);
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
123 newResult[i] = new ProfiledType(curType.getItem(), Math.min(1.0, curType.getProbability() * factor));
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
124 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
125 double newNotRecordedTypeProbability = Math.min(1.0, newNotRecorded * factor);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
126 return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, newResult);
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
127 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
128 return this;
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
129 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
130
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
131 @Override
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
132 public boolean equals(Object other) {
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
133 return super.equals(other) && nullSeen.equals(((JavaTypeProfile) other).nullSeen);
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
134 }
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
135
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
136 @Override
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
137 public int hashCode() {
9760
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
138 return nullSeen.hashCode() + super.hashCode();
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
139 }
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
140
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
141 public static class ProfiledType extends AbstractProfiledItem<ResolvedJavaType> {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
142
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
143 private static final long serialVersionUID = 1481773321889860837L;
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
144
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
145 public ProfiledType(ResolvedJavaType item, double probability) {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
146 super(item, probability);
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
147 }
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
148
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
149 /**
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
150 * Returns the type for this profile entry.
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
151 */
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
152 public ResolvedJavaType getType() {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
153 return getItem();
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
154 }
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
155
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
156 @Override
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
157 public String toString() {
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
158 return "{" + item.getName() + ", " + probability + "}";
c76b43ed5089 Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9389
diff changeset
159 }
9389
708aea0e5a25 Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9366
diff changeset
160 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 }