Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeAnalysisPhase.java @ 9755:432b8405e056
small refactoring of early read elimination (move logic into "virtualize" methods)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 17 May 2013 14:29:44 +0200 |
parents | f364c77077ff |
children | a8a5d5832def |
rev | line source |
---|---|
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.virtual.phases.ea; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
25 import java.util.*; |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
26 import java.util.concurrent.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
27 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
28 import com.oracle.graal.api.meta.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
29 import com.oracle.graal.debug.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 import com.oracle.graal.graph.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
32 import com.oracle.graal.nodes.java.*; |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
33 import com.oracle.graal.nodes.spi.*; |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
34 import com.oracle.graal.nodes.util.*; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
35 import com.oracle.graal.nodes.virtual.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.phases.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 import com.oracle.graal.phases.common.*; |
7394
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
7307
diff
changeset
|
38 import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 import com.oracle.graal.phases.graph.*; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
40 import com.oracle.graal.phases.schedule.*; |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
41 import com.oracle.graal.phases.tiers.*; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
42 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
43 public class PartialEscapeAnalysisPhase extends BasePhase<HighTierContext> { |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
45 private final CustomCanonicalizer customCanonicalizer; |
7012
9b7de658a76a
add test for escape analysis of InstanceOf and CheckCast
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
46 private final boolean iterative; |
8622
d8f28e2e2b49
make read elimination configurable (for tests)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8620
diff
changeset
|
47 private final boolean readElimination; |
6655
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
48 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
49 public PartialEscapeAnalysisPhase(boolean iterative, boolean readElimination) { |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
50 this(null, iterative, readElimination); |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
51 } |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
52 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
53 public PartialEscapeAnalysisPhase(CustomCanonicalizer customCanonicalizer, boolean iterative, boolean readElimination) { |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
54 this.customCanonicalizer = customCanonicalizer; |
7012
9b7de658a76a
add test for escape analysis of InstanceOf and CheckCast
Lukas Stadler <lukas.stadler@jku.at>
parents:
6710
diff
changeset
|
55 this.iterative = iterative; |
8622
d8f28e2e2b49
make read elimination configurable (for tests)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8620
diff
changeset
|
56 this.readElimination = readElimination; |
6655
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
57 } |
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
58 |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
59 public static final void trace(String format, Object... obj) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 if (GraalOptions.TraceEscapeAnalysis) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
61 Debug.log(format, obj); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
62 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
65 @Override |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
66 protected void run(StructuredGraph graph, HighTierContext context) { |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
67 runAnalysis(graph, context); |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
68 } |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
69 |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
70 public boolean runAnalysis(final StructuredGraph graph, final HighTierContext context) { |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
71 if (!matches(graph, GraalOptions.EscapeAnalyzeOnly)) { |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
72 return false; |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
73 } |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
74 |
8622
d8f28e2e2b49
make read elimination configurable (for tests)
Lukas Stadler <lukas.stadler@jku.at>
parents:
8620
diff
changeset
|
75 if (!readElimination) { |
8556
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
76 boolean analyzableNodes = false; |
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
77 for (Node node : graph.getNodes()) { |
9755
432b8405e056
small refactoring of early read elimination (move logic into "virtualize" methods)
Lukas Stadler <lukas.stadler@jku.at>
parents:
9503
diff
changeset
|
78 if (node instanceof VirtualizableRoot) { |
8556
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
79 analyzableNodes = true; |
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
80 break; |
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
81 } |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
82 } |
8556
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
83 if (!analyzableNodes) { |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
84 return false; |
8556
c69b29285ff8
better read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8553
diff
changeset
|
85 } |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
86 } |
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
87 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
88 boolean continueIteration = true; |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
89 boolean changed = false; |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
90 for (int iteration = 0; iteration < GraalOptions.EscapeAnalysisIterations && continueIteration; iteration++) { |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
91 boolean currentChanged = Debug.scope("iteration " + iteration, new Callable<Boolean>() { |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
92 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
93 @Override |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
94 public Boolean call() { |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
95 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
96 SchedulePhase schedule = new SchedulePhase(); |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
97 schedule.apply(graph, false); |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
98 PartialEscapeClosure closure = new PartialEscapeClosure(graph.createNodeBitMap(), schedule, context.getRuntime(), context.getAssumptions()); |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
99 ReentrantBlockIterator.apply(closure, schedule.getCFG().getStartBlock(), new BlockState(), null); |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
100 |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
101 if (!closure.hasChanged()) { |
7024
24950e93b962
only perform PEA iteration if there are analyzable nodes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7012
diff
changeset
|
102 return false; |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
103 } |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
105 // apply the effects collected during the escape analysis iteration |
8924
fc972f34c1d5
PEA: unify merge and loop logic, implement handling of identity-less virtual objects
Lukas Stadler <lukas.stadler@jku.at>
parents:
8622
diff
changeset
|
106 List<Node> obsoleteNodes = closure.applyEffects(graph); |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
107 |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
108 Debug.dump(graph, "after PartialEscapeAnalysis iteration"); |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
109 assert noObsoleteNodes(graph, obsoleteNodes); |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
110 |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
111 new DeadCodeEliminationPhase().apply(graph); |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
112 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
113 if (GraalOptions.OptCanonicalizer) { |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
114 new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), null, customCanonicalizer).apply(graph); |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
115 } |
8559
af0c1352f969
more work on read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
8556
diff
changeset
|
116 |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
117 return true; |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
118 } |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
119 }); |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
120 continueIteration = currentChanged && iterative; |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
121 changed |= currentChanged; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
122 } |
9050
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
123 |
b393a023dd4e
Make PartialEscapeAnalysisPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents:
9049
diff
changeset
|
124 return changed; |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
125 } |
6655
b01f9c391e17
first part of PEA refactoring
Lukas Stadler <lukas.stadler@jku.at>
parents:
6654
diff
changeset
|
126 |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
127 private static boolean matches(StructuredGraph graph, String filter) { |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
128 if (filter != null) { |
9503
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
129 if (filter.startsWith("~")) { |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
130 ResolvedJavaMethod method = graph.method(); |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
131 return method == null || !MetaUtil.format("%H.%n", method).contains(filter.substring(1)); |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
132 } else { |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
133 ResolvedJavaMethod method = graph.method(); |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
134 return method != null && MetaUtil.format("%H.%n", method).contains(filter); |
f364c77077ff
handle "~" in EscapeAnalyzeOnly
Lukas Stadler <lukas.stadler@jku.at>
parents:
9501
diff
changeset
|
135 } |
6657
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
136 } |
768793150bcd
more PEA refactoring, multiple iterations
Lukas Stadler <lukas.stadler@jku.at>
parents:
6655
diff
changeset
|
137 return true; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
139 |
8924
fc972f34c1d5
PEA: unify merge and loop logic, implement handling of identity-less virtual objects
Lukas Stadler <lukas.stadler@jku.at>
parents:
8622
diff
changeset
|
140 static boolean noObsoleteNodes(StructuredGraph graph, List<Node> obsoleteNodes) { |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
141 // helper code that determines the paths that keep obsolete nodes alive: |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
142 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
143 NodeFlood flood = graph.createNodeFlood(); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
144 IdentityHashMap<Node, Node> path = new IdentityHashMap<>(); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
145 flood.add(graph.start()); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
146 for (Node current : flood) { |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
147 if (current instanceof AbstractEndNode) { |
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9238
diff
changeset
|
148 AbstractEndNode end = (AbstractEndNode) current; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
149 flood.add(end.merge()); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
150 if (!path.containsKey(end.merge())) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 path.put(end.merge(), end); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
152 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
153 } else { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
154 for (Node successor : current.successors()) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
155 flood.add(successor); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
156 if (!path.containsKey(successor)) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
157 path.put(successor, current); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
158 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
159 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
160 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
161 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
162 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
163 for (Node node : obsoleteNodes) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
164 if (node instanceof FixedNode) { |
8548
51d5999900e2
simple iterative inlining, simple read elimination in PEA
Lukas Stadler <lukas.stadler@jku.at>
parents:
7827
diff
changeset
|
165 assert !flood.isMarked(node) : node; |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
166 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
167 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
168 |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 for (Node node : graph.getNodes()) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
170 if (node instanceof LocalNode) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
171 flood.add(node); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
172 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
173 if (flood.isMarked(node)) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 for (Node input : node.inputs()) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
175 flood.add(input); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
176 if (!path.containsKey(input)) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
177 path.put(input, node); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
178 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
179 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
180 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
181 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
182 for (Node current : flood) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
183 for (Node input : current.inputs()) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
184 flood.add(input); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
185 if (!path.containsKey(input)) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
186 path.put(input, current); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
187 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
188 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
189 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
190 boolean success = true; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
191 for (Node node : obsoleteNodes) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
192 if (flood.isMarked(node)) { |
9109
23c96de53386
Change severity of checkstyle problems from "warning" to "error". Fixed several System.out.print violations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9050
diff
changeset
|
193 TTY.print("offending node path:"); |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
194 Node current = node; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
195 while (current != null) { |
9109
23c96de53386
Change severity of checkstyle problems from "warning" to "error". Fixed several System.out.print violations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9050
diff
changeset
|
196 TTY.println(current.toString()); |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
197 current = path.get(current); |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
198 if (current != null && current instanceof FixedNode && !obsoleteNodes.contains(current)) { |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
199 break; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
200 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
201 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
202 success = false; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
203 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
204 } |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
205 return success; |
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
206 } |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
207 |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
208 public static Map<Invoke, Double> getHints(StructuredGraph graph) { |
9238
8f01fe16e473
refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents:
9234
diff
changeset
|
209 NodesToDoubles probabilities = new ComputeProbabilityClosure(graph).apply(); |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
210 Map<Invoke, Double> hints = null; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
211 for (CommitAllocationNode commit : graph.getNodes(CommitAllocationNode.class)) { |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
212 double sum = 0; |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
213 double invokeSum = 0; |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
214 for (Node commitUsage : commit.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
215 for (Node usage : commitUsage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
216 if (usage instanceof FixedNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
217 sum += probabilities.get((FixedNode) usage); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
218 } else { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
219 if (usage instanceof MethodCallTargetNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
220 invokeSum += probabilities.get(((MethodCallTargetNode) usage).invoke().asNode()); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
221 } |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
222 for (Node secondLevelUage : usage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
223 if (secondLevelUage instanceof FixedNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
224 sum += probabilities.get(((FixedNode) secondLevelUage)); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
225 } |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
226 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
227 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
228 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
229 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
230 // TODO(lstadler) get rid of this magic number |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
231 if (sum > 100 && invokeSum > 0) { |
9501
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
232 for (Node commitUsage : commit.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
233 for (Node usage : commitUsage.usages()) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
234 if (usage instanceof MethodCallTargetNode) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
235 if (hints == null) { |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
236 hints = new HashMap<>(); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
237 } |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
238 Invoke invoke = ((MethodCallTargetNode) usage).invoke(); |
bef43373de39
coalesce allocations during escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents:
9434
diff
changeset
|
239 hints.put(invoke, sum / invokeSum); |
8553
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
240 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
241 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
242 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
243 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
244 } |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
245 return hints; |
ed38b01ce7bc
changes to iterative inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
8548
diff
changeset
|
246 } |
6650
ea38da80dd29
refactor PEA into separate classes
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
247 } |