Mercurial > hg > graal-compiler
annotate graal/com.oracle.jvmci.meta/src/com/oracle/jvmci/meta/JavaTypeProfile.java @ 21562:47bebae7454f
Merge.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 28 May 2015 21:58:33 +0200 |
parents | 31fc2fce38f3 |
children |
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 */ |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21411
diff
changeset
|
23 package com.oracle.jvmci.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 |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21411
diff
changeset
|
27 import com.oracle.jvmci.meta.JavaTypeProfile.ProfiledType; |
8659
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
28 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
6539
diff
changeset
|
30 * 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
|
31 * 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
|
32 * 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
|
33 */ |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
34 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
|
35 |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
36 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
|
37 |
8659
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
38 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
|
39 |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
40 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
|
41 super(notRecordedProbability, pitems); |
8659
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
42 this.nullSeen = nullSeen; |
4456
f4c82dd4619e
inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4453
diff
changeset
|
43 } |
f4c82dd4619e
inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4453
diff
changeset
|
44 |
f4c82dd4619e
inlining bugfixes and cleanup
Christian Haeubl <christian.haeubl@oracle.com>
parents:
4453
diff
changeset
|
45 /** |
8659
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
46 * 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
|
47 */ |
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
48 public TriState getNullSeen() { |
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
49 return nullSeen; |
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
50 } |
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
51 |
bc7bb895e359
incorporated null-seen information into JavaTypeProfile
Doug Simon <doug.simon@oracle.com>
parents:
7530
diff
changeset
|
52 /** |
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
|
53 * 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
|
54 * 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
|
55 * type and a negative type is not. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 */ |
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
|
57 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
|
58 return getItems(); |
9366
f1170c277b7b
Implement instanceof after instanceof swapping.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8909
diff
changeset
|
59 } |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
60 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
61 public JavaTypeProfile restrict(JavaTypeProfile otherProfile) { |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
62 if (otherProfile.getNotRecordedProbability() > 0.0) { |
9999
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
63 // Not useful for restricting since there is an unknown set of types occurring. |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
64 return this; |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
65 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
66 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
67 if (this.getNotRecordedProbability() > 0.0) { |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
68 // 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
|
69 return otherProfile; |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
70 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
71 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 ResolvedJavaType type = ptype.getItem(); |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
76 if (otherProfile.isIncluded(type)) { |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
77 result.add(ptype); |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
78 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
79 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
80 |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
81 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
|
82 double newNotRecorded = getNotRecordedProbability(); |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
83 return createAdjustedProfile(result, newNullSeen, newNotRecorded); |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
84 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
85 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 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
|
90 ResolvedJavaType type = ptype.getItem(); |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
91 if (declaredType.isAssignableFrom(type)) { |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
92 result.add(ptype); |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
93 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
94 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
95 |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
96 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
|
97 double newNotRecorded = this.getNotRecordedProbability(); |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
98 // 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
|
99 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
|
100 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
|
101 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
102 return createAdjustedProfile(result, newNullSeen, newNotRecorded); |
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 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 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
|
109 } |
15825
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
110 double factor; |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
111 if (result.size() == this.getItems().length) { |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
112 /* List of types did not change, no need to recompute probabilities. */ |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
113 factor = 1.0; |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
114 } else { |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
115 double probabilitySum = 0.0; |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
116 for (int i = 0; i < result.size(); i++) { |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
117 probabilitySum += result.get(i).getProbability(); |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
118 } |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
119 probabilitySum += newNotRecorded; |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
120 |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
121 factor = 1.0 / probabilitySum; // Normalize to 1.0 |
4fd787b04c92
Recompute probability only when number of types in profile changed
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15311
diff
changeset
|
122 assert factor >= 1.0; |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
123 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
124 ProfiledType[] newResult = new ProfiledType[result.size()]; |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
129 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
|
130 return new JavaTypeProfile(newNullSeen, newNotRecordedTypeProbability, newResult); |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
131 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
132 return this; |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
133 } |
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 @Override |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
136 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
|
137 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
|
138 } |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
139 |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
140 @Override |
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
141 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
|
142 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
|
143 } |
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 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
|
146 |
13168
533808334e7b
renamed parameters of ProfiledMethod and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
13166
diff
changeset
|
147 public ProfiledType(ResolvedJavaType type, double probability) { |
533808334e7b
renamed parameters of ProfiledMethod and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
13166
diff
changeset
|
148 super(type, probability); |
18823
5a21cac1968f
Add utilities ModifiersProvider#isConcrete, ResolvedJavaMethod#hasReceiver, ResolvedJavaMethod#hasBytecodes to Graal API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15825
diff
changeset
|
149 assert type.isArray() || type.isConcrete() : type; |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
150 } |
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 /** |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
153 * 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
|
154 */ |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
155 public ResolvedJavaType getType() { |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
156 return getItem(); |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
157 } |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
158 |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
159 @Override |
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
160 public String toString() { |
9999
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
161 return String.format("%.6f#%s", probability, item); |
9760
c76b43ed5089
Added infrastructure for recording invoked methods in the profiling information.
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9389
diff
changeset
|
162 } |
9389
708aea0e5a25
Introduce proxy nodes for propagating profiling information.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9366
diff
changeset
|
163 } |
9999
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
164 |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
165 @Override |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
166 public String toString() { |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
167 StringBuilder buf = new StringBuilder("JavaTypeProfile<nullSeen=").append(getNullSeen()).append(", types=["); |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
168 for (int j = 0; j < getTypes().length; j++) { |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
169 if (j != 0) { |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
170 buf.append(", "); |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
171 } |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
172 ProfiledType ptype = getTypes()[j]; |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
173 buf.append(String.format("%.6f:%s", ptype.getProbability(), ptype.getType())); |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
174 } |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
175 return buf.append(String.format("], notRecorded:%.6f>", getNotRecordedProbability())).toString(); |
828f342cb275
improved toString() for JavaTypeProfile and ProfiledType
Doug Simon <doug.simon@oracle.com>
parents:
9760
diff
changeset
|
176 } |
21501
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
177 |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
178 /** |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
179 * Returns {@code true} if all types seen at this location have been recorded in the profile. |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
180 */ |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
181 public boolean allTypesRecorded() { |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
182 return this.getNotRecordedProbability() == 0.0; |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
183 } |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
184 |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
185 /** |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
186 * Returns the single monormorphic type representing this profile or {@code null} if no such |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
187 * type exists. |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
188 */ |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
189 public ResolvedJavaType asSingleType() { |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
190 if (allTypesRecorded() && this.getTypes().length == 1) { |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
191 return getTypes()[0].getType(); |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
192 } |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
193 return null; |
ce585b0ac3e2
Create different nodes in the graph builder when instanceof and checkcast have a single type profile.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
21411
diff
changeset
|
194 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
195 } |