annotate src/share/vm/compiler/methodLiveness.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children 37f87013dfd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // The MethodLiveness class performs a simple liveness analysis on a method
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // in order to decide which locals are live (that is, will be used again) at
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // a particular bytecode index (bci).
a61af66fc99e Initial load
duke
parents:
diff changeset
28 //
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // The algorithm goes:
a61af66fc99e Initial load
duke
parents:
diff changeset
30 //
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // 1. Break the method into a set of basic blocks. For each basic block we
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // also keep track of its set of predecessors through normal control flow
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // and predecessors through exceptional control flow.
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // 2. For each basic block, compute two sets, gen (the set of values used before
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // they are defined) and kill (the set of values defined before they are used)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // in the basic block. A basic block "needs" the locals in its gen set to
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // perform its computation. A basic block "provides" values for the locals in
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // its kill set, allowing a need from a successor to be ignored.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // 3. Liveness information (the set of locals which are needed) is pushed backwards through
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // the program, from blocks to their predecessors. We compute and store liveness
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // information for the normal/exceptional exit paths for each basic block. When
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // this process reaches a fixed point, we are done.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // 4. When we are asked about the liveness at a particular bci with a basic block, we
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // compute gen/kill sets which represent execution from that bci to the exit of
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // its blocks. We then compose this range gen/kill information with the normal
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // and exceptional exit information for the block to produce liveness information
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // at that bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 //
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // The algorithm is approximate in many respects. Notably:
a61af66fc99e Initial load
duke
parents:
diff changeset
53 //
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // 1. We do not do the analysis necessary to match jsr's with the appropriate ret.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Instead we make the conservative assumption that any ret can return to any
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // jsr return site.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // 2. Instead of computing the effects of exceptions at every instruction, we
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // summarize the effects of all exceptional continuations from the block as
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // a single set (_exception_exit), losing some information but simplifying the
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
64 # include "incls/_methodLiveness.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 //--------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // The BitCounter class is used for counting the number of bits set in
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // some BitMap. It is only used when collecting liveness statistics.
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 class BitCounter: public BitMapClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int _count;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
76 BitCounter() : _count(0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Callback when bit in map is set
a61af66fc99e Initial load
duke
parents:
diff changeset
79 virtual void do_bit(size_t offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 int count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return _count;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 };
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 //--------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Counts
a61af66fc99e Initial load
duke
parents:
diff changeset
93 long MethodLiveness::_total_bytes = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int MethodLiveness::_total_methods = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 long MethodLiveness::_total_blocks = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int MethodLiveness::_max_method_blocks = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 long MethodLiveness::_total_edges = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int MethodLiveness::_max_block_edges = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 long MethodLiveness::_total_exc_edges = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 int MethodLiveness::_max_block_exc_edges = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 long MethodLiveness::_total_method_locals = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int MethodLiveness::_max_method_locals = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 long MethodLiveness::_total_locals_queried = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 long MethodLiveness::_total_live_locals_queried = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 long MethodLiveness::_total_visits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Timers
a61af66fc99e Initial load
duke
parents:
diff changeset
116 elapsedTimer MethodLiveness::_time_build_graph;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 elapsedTimer MethodLiveness::_time_gen_kill;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 elapsedTimer MethodLiveness::_time_flow;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 elapsedTimer MethodLiveness::_time_query;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 elapsedTimer MethodLiveness::_time_total;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 MethodLiveness::MethodLiveness(Arena* arena, ciMethod* method)
a61af66fc99e Initial load
duke
parents:
diff changeset
123 #ifdef COMPILER1
a61af66fc99e Initial load
duke
parents:
diff changeset
124 : _bci_block_start((uintptr_t*)arena->Amalloc((method->code_size() >> LogBitsPerByte) + 1), method->code_size())
a61af66fc99e Initial load
duke
parents:
diff changeset
125 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
126 {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _arena = arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _bit_map_size_bits = method->max_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 _bit_map_size_words = (_bit_map_size_bits / sizeof(unsigned int)) + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 #ifdef COMPILER1
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _bci_block_start.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void MethodLiveness::compute_liveness() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (TraceLivenessGen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 tty->print_cr("################################################################");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 tty->print("# Computing liveness information for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 method()->print_short_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (TimeLivenessAnalysis) _time_total.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 TraceTime buildGraph(NULL, &_time_build_graph, TimeLivenessAnalysis);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 init_basic_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 TraceTime genKill(NULL, &_time_gen_kill, TimeLivenessAnalysis);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 init_gen_kill();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 TraceTime flow(NULL, &_time_flow, TimeLivenessAnalysis);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 propagate_liveness();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (TimeLivenessAnalysis) _time_total.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (TimeLivenessAnalysis) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Collect statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _total_bytes += method()->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 _total_methods++;
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int num_blocks = _block_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _total_blocks += num_blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _max_method_blocks = MAX2(num_blocks,_max_method_blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 for (int i=0; i<num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 BasicBlock *block = _block_list[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 int numEdges = block->_normal_predecessors->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int numExcEdges = block->_exception_predecessors->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _total_edges += numEdges;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 _total_exc_edges += numExcEdges;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 _max_block_edges = MAX2(numEdges,_max_block_edges);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 _max_block_exc_edges = MAX2(numExcEdges,_max_block_exc_edges);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 int numLocals = _bit_map_size_bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _total_method_locals += numLocals;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _max_method_locals = MAX2(numLocals,_max_method_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 void MethodLiveness::init_basic_blocks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 bool bailout = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 int method_len = method()->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 ciMethodBlocks *mblocks = method()->get_method_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Create an array to store the bci->BasicBlock mapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
200 _block_map = new (arena()) GrowableArray<BasicBlock*>(arena(), method_len, method_len, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _block_count = mblocks->num_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 _block_list = (BasicBlock **) arena()->Amalloc(sizeof(BasicBlock *) * _block_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Used for patching up jsr/ret control flow.
a61af66fc99e Initial load
duke
parents:
diff changeset
206 GrowableArray<BasicBlock*>* jsr_exit_list = new GrowableArray<BasicBlock*>(5);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 GrowableArray<BasicBlock*>* ret_list = new GrowableArray<BasicBlock*>(5);
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // generate our block list from ciMethodBlocks
a61af66fc99e Initial load
duke
parents:
diff changeset
210 for (int blk = 0; blk < _block_count; blk++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ciBlock *cib = mblocks->block(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 int start_bci = cib->start_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 _block_list[blk] = new (arena()) BasicBlock(this, start_bci, cib->limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
214 _block_map->at_put(start_bci, _block_list[blk]);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 #ifdef COMPILER1
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // mark all bcis where a new basic block starts
a61af66fc99e Initial load
duke
parents:
diff changeset
217 _bci_block_start.set_bit(start_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 #endif // COMPILER1
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // fill in the predecessors of blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
221 ciBytecodeStream bytes(method());
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 for (int blk = 0; blk < _block_count; blk++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 BasicBlock *current_block = _block_list[blk];
a61af66fc99e Initial load
duke
parents:
diff changeset
225 int bci = mblocks->block(blk)->control_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (bci == ciBlock::fall_through_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 int limit = current_block->limit_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (limit < method_len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 BasicBlock *next = _block_map->at(limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 assert( next != NULL, "must be a block immediately following this one.");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 next->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 bytes.reset_to_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 Bytecodes::Code code = bytes.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 BasicBlock *dest;
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // Now we need to interpret the instruction's effect
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // on control flow.
a61af66fc99e Initial load
duke
parents:
diff changeset
242 assert (current_block != NULL, "we must have a current block");
a61af66fc99e Initial load
duke
parents:
diff changeset
243 switch (code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 case Bytecodes::_ifeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
245 case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
246 case Bytecodes::_iflt:
a61af66fc99e Initial load
duke
parents:
diff changeset
247 case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
248 case Bytecodes::_ifgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
249 case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
250 case Bytecodes::_if_icmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
251 case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
252 case Bytecodes::_if_icmplt:
a61af66fc99e Initial load
duke
parents:
diff changeset
253 case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
254 case Bytecodes::_if_icmpgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
255 case Bytecodes::_if_icmple:
a61af66fc99e Initial load
duke
parents:
diff changeset
256 case Bytecodes::_if_acmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
257 case Bytecodes::_if_acmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
258 case Bytecodes::_ifnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
259 case Bytecodes::_ifnonnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // Two way branch. Set predecessors at each destination.
a61af66fc99e Initial load
duke
parents:
diff changeset
261 dest = _block_map->at(bytes.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert(dest != NULL, "must be a block immediately following this one.");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 dest = _block_map->at(bytes.get_dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
266 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
267 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
269 case Bytecodes::_goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
270 dest = _block_map->at(bytes.get_dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
271 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
272 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 case Bytecodes::_goto_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
275 dest = _block_map->at(bytes.get_far_dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
276 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
277 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 case Bytecodes::_tableswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
280 {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 Bytecode_tableswitch *tableswitch =
a61af66fc99e Initial load
duke
parents:
diff changeset
282 Bytecode_tableswitch_at(bytes.cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 int len = tableswitch->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 dest = _block_map->at(bci + tableswitch->default_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
287 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
288 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 while (--len >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 dest = _block_map->at(bci + tableswitch->dest_offset_at(len));
a61af66fc99e Initial load
duke
parents:
diff changeset
291 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
292 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
298 {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 Bytecode_lookupswitch *lookupswitch =
a61af66fc99e Initial load
duke
parents:
diff changeset
300 Bytecode_lookupswitch_at(bytes.cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 int npairs = lookupswitch->number_of_pairs();
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 dest = _block_map->at(bci + lookupswitch->default_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
305 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
306 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 while(--npairs >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 LookupswitchPair *pair = lookupswitch->pair_at(npairs);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 dest = _block_map->at( bci + pair->offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
310 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
317 {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 assert(bytes.is_wide()==false, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
319 dest = _block_map->at(bytes.get_dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
320 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
321 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
323 assert(jsrExit != NULL, "jsr return bci must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
324 jsr_exit_list->append(jsrExit);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
328 {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 dest = _block_map->at(bytes.get_far_dest());
a61af66fc99e Initial load
duke
parents:
diff changeset
330 assert(dest != NULL, "branch desination must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
331 dest->add_normal_predecessor(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
333 assert(jsrExit != NULL, "jsr return bci must start a block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
334 jsr_exit_list->append(jsrExit);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 case Bytecodes::_wide:
a61af66fc99e Initial load
duke
parents:
diff changeset
339 assert(false, "wide opcodes should not be seen here");
a61af66fc99e Initial load
duke
parents:
diff changeset
340 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 case Bytecodes::_athrow:
a61af66fc99e Initial load
duke
parents:
diff changeset
342 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
343 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
344 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
345 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
346 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
347 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // These opcodes are not the normal predecessors of any other opcodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
349 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 case Bytecodes::_ret:
a61af66fc99e Initial load
duke
parents:
diff changeset
351 // We will patch up jsr/rets in a subsequent pass.
a61af66fc99e Initial load
duke
parents:
diff changeset
352 ret_list->append(current_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 case Bytecodes::_breakpoint:
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // Bail out of there are breakpoints in here.
a61af66fc99e Initial load
duke
parents:
diff changeset
356 bailout = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Do nothing.
a61af66fc99e Initial load
duke
parents:
diff changeset
360 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // Patch up the jsr/ret's. We conservatively assume that any ret
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // can return to any jsr site.
a61af66fc99e Initial load
duke
parents:
diff changeset
365 int ret_list_len = ret_list->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 int jsr_exit_list_len = jsr_exit_list->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (ret_list_len > 0 && jsr_exit_list_len > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 for (int i = jsr_exit_list_len - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 BasicBlock *jsrExit = jsr_exit_list->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 for (int i = ret_list_len - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 jsrExit->add_normal_predecessor(ret_list->at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376 // Compute exception edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
377 for (int b=_block_count-1; b >= 0; b--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 BasicBlock *block = _block_list[b];
a61af66fc99e Initial load
duke
parents:
diff changeset
379 int block_start = block->start_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
380 int block_limit = block->limit_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 ciExceptionHandlerStream handlers(method());
a61af66fc99e Initial load
duke
parents:
diff changeset
382 for (; !handlers.is_done(); handlers.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 ciExceptionHandler* handler = handlers.handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
384 int start = handler->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 int limit = handler->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
386 int handler_bci = handler->handler_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 int intersect_start = MAX2(block_start, start);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 int intersect_limit = MIN2(block_limit, limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (intersect_start < intersect_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // The catch range has a nonempty intersection with this
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // basic block. That means this basic block can be an
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // exceptional predecessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
394 _block_map->at(handler_bci)->add_exception_predecessor(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (handler->is_catch_all()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // This is a catch-all block.
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if (intersect_start == block_start && intersect_limit == block_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // The basic block is entirely contained in this catch-all block.
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // Skip the rest of the exception handlers -- they can never be
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // reached in execution.
a61af66fc99e Initial load
duke
parents:
diff changeset
402 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 void MethodLiveness::init_gen_kill() {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 for (int i=_block_count-1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
412 _block_list[i]->compute_gen_kill(method());
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 void MethodLiveness::propagate_liveness() {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 int num_blocks = _block_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
418 BasicBlock *block;
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // We start our work list off with all blocks in it.
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // Alternately, we could start off the work list with the list of all
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // blocks which could exit the method directly, along with one block
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // from any infinite loop. If this matters, it can be changed. It
a61af66fc99e Initial load
duke
parents:
diff changeset
424 // may not be clear from looking at the code, but the order of the
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // workList will be the opposite of the creation order of the basic
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // blocks, which should be decent for quick convergence (with the
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // possible exception of exception handlers, which are all created
a61af66fc99e Initial load
duke
parents:
diff changeset
428 // early).
a61af66fc99e Initial load
duke
parents:
diff changeset
429 _work_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
430 for (int i = 0; i < num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 block = _block_list[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
432 block->set_next(_work_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 block->set_on_work_list(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 _work_list = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 while ((block = work_list_get()) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 block->propagate(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 NOT_PRODUCT(_total_visits++;)
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 void MethodLiveness::work_list_add(BasicBlock *block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 if (!block->on_work_list()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
446 block->set_next(_work_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 block->set_on_work_list(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 _work_list = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 MethodLiveness::BasicBlock *MethodLiveness::work_list_get() {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 BasicBlock *block = _work_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (block != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 block->set_on_work_list(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 _work_list = block->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 return block;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 MethodLivenessResult MethodLiveness::get_liveness_at(int entry_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 int bci = entry_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 bool is_entry = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 if (entry_bci == InvocationEntryBci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 is_entry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 MethodLivenessResult answer(NULL,0);
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 if (_block_count > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 if (TimeLivenessAnalysis) _time_total.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
474 if (TimeLivenessAnalysis) _time_query.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 assert( 0 <= bci && bci < method()->code_size(), "bci out of range" );
a61af66fc99e Initial load
duke
parents:
diff changeset
477 BasicBlock *block = _block_map->at(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // We may not be at the block start, so search backwards to find the block
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // containing bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
480 int t = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 while (block == NULL && t > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 block = _block_map->at(--t);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 assert( block != NULL, "invalid bytecode index; must be instruction index" );
a61af66fc99e Initial load
duke
parents:
diff changeset
485 assert(bci >= block->start_bci() && bci < block->limit_bci(), "block must contain bci.");
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 answer = block->get_liveness_at(method(), bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 if (is_entry && method()->is_synchronized() && !method()->is_static()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // Synchronized methods use the receiver once on entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 answer.at_put(0, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (TraceLivenessQuery) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 tty->print("Liveness query of ");
a61af66fc99e Initial load
duke
parents:
diff changeset
497 method()->print_short_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
498 tty->print(" @ %d : result is ", bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
499 answer.print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (TimeLivenessAnalysis) _time_query.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
503 if (TimeLivenessAnalysis) _time_total.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
504 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
508 if (TimeLivenessAnalysis) {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // Collect statistics.
a61af66fc99e Initial load
duke
parents:
diff changeset
510 _total_locals_queried += _bit_map_size_bits;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 BitCounter counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 answer.iterate(&counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 _total_live_locals_queried += counter.count();
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 return answer;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 void MethodLiveness::print_times() {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 tty->print_cr ("Accumulated liveness analysis times/statistics:");
a61af66fc99e Initial load
duke
parents:
diff changeset
525 tty->print_cr ("-----------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
526 tty->print_cr (" Total : %3.3f sec.", _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
527 tty->print_cr (" Build graph : %3.3f sec. (%2.2f%%)", _time_build_graph.seconds(),
a61af66fc99e Initial load
duke
parents:
diff changeset
528 _time_build_graph.seconds() * 100 / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
529 tty->print_cr (" Gen / Kill : %3.3f sec. (%2.2f%%)", _time_gen_kill.seconds(),
a61af66fc99e Initial load
duke
parents:
diff changeset
530 _time_gen_kill.seconds() * 100 / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
531 tty->print_cr (" Dataflow : %3.3f sec. (%2.2f%%)", _time_flow.seconds(),
a61af66fc99e Initial load
duke
parents:
diff changeset
532 _time_flow.seconds() * 100 / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
533 tty->print_cr (" Query : %3.3f sec. (%2.2f%%)", _time_query.seconds(),
a61af66fc99e Initial load
duke
parents:
diff changeset
534 _time_query.seconds() * 100 / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
535 tty->print_cr (" #bytes : %8d (%3.0f bytes per sec)",
a61af66fc99e Initial load
duke
parents:
diff changeset
536 _total_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
537 _total_bytes / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
538 tty->print_cr (" #methods : %8d (%3.0f methods per sec)",
a61af66fc99e Initial load
duke
parents:
diff changeset
539 _total_methods,
a61af66fc99e Initial load
duke
parents:
diff changeset
540 _total_methods / _time_total.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
541 tty->print_cr (" avg locals : %3.3f max locals : %3d",
a61af66fc99e Initial load
duke
parents:
diff changeset
542 (float)_total_method_locals / _total_methods,
a61af66fc99e Initial load
duke
parents:
diff changeset
543 _max_method_locals);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 tty->print_cr (" avg blocks : %3.3f max blocks : %3d",
a61af66fc99e Initial load
duke
parents:
diff changeset
545 (float)_total_blocks / _total_methods,
a61af66fc99e Initial load
duke
parents:
diff changeset
546 _max_method_blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 tty->print_cr (" avg bytes : %3.3f",
a61af66fc99e Initial load
duke
parents:
diff changeset
548 (float)_total_bytes / _total_methods);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 tty->print_cr (" #blocks : %8d",
a61af66fc99e Initial load
duke
parents:
diff changeset
550 _total_blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 tty->print_cr (" avg normal predecessors : %3.3f max normal predecessors : %3d",
a61af66fc99e Initial load
duke
parents:
diff changeset
552 (float)_total_edges / _total_blocks,
a61af66fc99e Initial load
duke
parents:
diff changeset
553 _max_block_edges);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 tty->print_cr (" avg exception predecessors : %3.3f max exception predecessors : %3d",
a61af66fc99e Initial load
duke
parents:
diff changeset
555 (float)_total_exc_edges / _total_blocks,
a61af66fc99e Initial load
duke
parents:
diff changeset
556 _max_block_exc_edges);
a61af66fc99e Initial load
duke
parents:
diff changeset
557 tty->print_cr (" avg visits : %3.3f",
a61af66fc99e Initial load
duke
parents:
diff changeset
558 (float)_total_visits / _total_blocks);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 tty->print_cr (" #locals queried : %8d #live : %8d %%live : %2.2f%%",
a61af66fc99e Initial load
duke
parents:
diff changeset
560 _total_locals_queried,
a61af66fc99e Initial load
duke
parents:
diff changeset
561 _total_live_locals_queried,
a61af66fc99e Initial load
duke
parents:
diff changeset
562 100.0 * _total_live_locals_queried / _total_locals_queried);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567
a61af66fc99e Initial load
duke
parents:
diff changeset
568 MethodLiveness::BasicBlock::BasicBlock(MethodLiveness *analyzer, int start, int limit) :
a61af66fc99e Initial load
duke
parents:
diff changeset
569 _gen((uintptr_t*)analyzer->arena()->Amalloc(BytesPerWord * analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
570 analyzer->bit_map_size_bits()),
a61af66fc99e Initial load
duke
parents:
diff changeset
571 _kill((uintptr_t*)analyzer->arena()->Amalloc(BytesPerWord * analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
572 analyzer->bit_map_size_bits()),
a61af66fc99e Initial load
duke
parents:
diff changeset
573 _entry((uintptr_t*)analyzer->arena()->Amalloc(BytesPerWord * analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
574 analyzer->bit_map_size_bits()),
a61af66fc99e Initial load
duke
parents:
diff changeset
575 _normal_exit((uintptr_t*)analyzer->arena()->Amalloc(BytesPerWord * analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
576 analyzer->bit_map_size_bits()),
a61af66fc99e Initial load
duke
parents:
diff changeset
577 _exception_exit((uintptr_t*)analyzer->arena()->Amalloc(BytesPerWord * analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
578 analyzer->bit_map_size_bits()),
a61af66fc99e Initial load
duke
parents:
diff changeset
579 _last_bci(-1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 _analyzer = analyzer;
a61af66fc99e Initial load
duke
parents:
diff changeset
581 _start_bci = start;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 _limit_bci = limit;
a61af66fc99e Initial load
duke
parents:
diff changeset
583 _normal_predecessors =
a61af66fc99e Initial load
duke
parents:
diff changeset
584 new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 _exception_predecessors =
a61af66fc99e Initial load
duke
parents:
diff changeset
586 new (analyzer->arena()) GrowableArray<MethodLiveness::BasicBlock*>(analyzer->arena(), 5, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
587 _normal_exit.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 _exception_exit.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
589 _entry.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // this initialization is not strictly necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // _gen and _kill are cleared at the beginning of compute_gen_kill_range()
a61af66fc99e Initial load
duke
parents:
diff changeset
593 _gen.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
594 _kill.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598
a61af66fc99e Initial load
duke
parents:
diff changeset
599 MethodLiveness::BasicBlock *MethodLiveness::BasicBlock::split(int split_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 int start = _start_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 int limit = _limit_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if (TraceLivenessGen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 tty->print_cr(" ** Splitting block (%d,%d) at %d", start, limit, split_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 GrowableArray<BasicBlock*>* save_predecessors = _normal_predecessors;
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 assert (start < split_bci && split_bci < limit, "improper split");
a61af66fc99e Initial load
duke
parents:
diff changeset
610
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // Make a new block to cover the first half of the range.
a61af66fc99e Initial load
duke
parents:
diff changeset
612 BasicBlock *first_half = new (_analyzer->arena()) BasicBlock(_analyzer, start, split_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // Assign correct values to the second half (this)
a61af66fc99e Initial load
duke
parents:
diff changeset
615 _normal_predecessors = first_half->_normal_predecessors;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 _start_bci = split_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
617 add_normal_predecessor(first_half);
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // Assign correct predecessors to the new first half
a61af66fc99e Initial load
duke
parents:
diff changeset
620 first_half->_normal_predecessors = save_predecessors;
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 return first_half;
a61af66fc99e Initial load
duke
parents:
diff changeset
623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 void MethodLiveness::BasicBlock::compute_gen_kill(ciMethod* method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 ciBytecodeStream bytes(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
627 bytes.reset_to_bci(start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
628 bytes.set_max_bci(limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
629 compute_gen_kill_range(&bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
630
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 void MethodLiveness::BasicBlock::compute_gen_kill_range(ciBytecodeStream *bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 _gen.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
635 _kill.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 while (bytes->next() != ciBytecodeStream::EOBC()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 compute_gen_kill_single(bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 void MethodLiveness::BasicBlock::compute_gen_kill_single(ciBytecodeStream *instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 int localNum;
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // We prohibit _gen and _kill from having locals in common. If we
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // know that one is definitely going to be applied before the other,
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // we could save some computation time by relaxing this prohibition.
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 switch (instruction->cur_bc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 case Bytecodes::_nop:
a61af66fc99e Initial load
duke
parents:
diff changeset
651 case Bytecodes::_goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
652 case Bytecodes::_goto_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
653 case Bytecodes::_aconst_null:
a61af66fc99e Initial load
duke
parents:
diff changeset
654 case Bytecodes::_new:
a61af66fc99e Initial load
duke
parents:
diff changeset
655 case Bytecodes::_iconst_m1:
a61af66fc99e Initial load
duke
parents:
diff changeset
656 case Bytecodes::_iconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
657 case Bytecodes::_iconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
658 case Bytecodes::_iconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
659 case Bytecodes::_iconst_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
660 case Bytecodes::_iconst_4:
a61af66fc99e Initial load
duke
parents:
diff changeset
661 case Bytecodes::_iconst_5:
a61af66fc99e Initial load
duke
parents:
diff changeset
662 case Bytecodes::_fconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
663 case Bytecodes::_fconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
664 case Bytecodes::_fconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
665 case Bytecodes::_bipush:
a61af66fc99e Initial load
duke
parents:
diff changeset
666 case Bytecodes::_sipush:
a61af66fc99e Initial load
duke
parents:
diff changeset
667 case Bytecodes::_lconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
668 case Bytecodes::_lconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
669 case Bytecodes::_dconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
670 case Bytecodes::_dconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
671 case Bytecodes::_ldc2_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
672 case Bytecodes::_ldc:
a61af66fc99e Initial load
duke
parents:
diff changeset
673 case Bytecodes::_ldc_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
674 case Bytecodes::_iaload:
a61af66fc99e Initial load
duke
parents:
diff changeset
675 case Bytecodes::_faload:
a61af66fc99e Initial load
duke
parents:
diff changeset
676 case Bytecodes::_baload:
a61af66fc99e Initial load
duke
parents:
diff changeset
677 case Bytecodes::_caload:
a61af66fc99e Initial load
duke
parents:
diff changeset
678 case Bytecodes::_saload:
a61af66fc99e Initial load
duke
parents:
diff changeset
679 case Bytecodes::_laload:
a61af66fc99e Initial load
duke
parents:
diff changeset
680 case Bytecodes::_daload:
a61af66fc99e Initial load
duke
parents:
diff changeset
681 case Bytecodes::_aaload:
a61af66fc99e Initial load
duke
parents:
diff changeset
682 case Bytecodes::_iastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
683 case Bytecodes::_fastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
684 case Bytecodes::_bastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
685 case Bytecodes::_castore:
a61af66fc99e Initial load
duke
parents:
diff changeset
686 case Bytecodes::_sastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
687 case Bytecodes::_lastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
688 case Bytecodes::_dastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
689 case Bytecodes::_aastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
690 case Bytecodes::_pop:
a61af66fc99e Initial load
duke
parents:
diff changeset
691 case Bytecodes::_pop2:
a61af66fc99e Initial load
duke
parents:
diff changeset
692 case Bytecodes::_dup:
a61af66fc99e Initial load
duke
parents:
diff changeset
693 case Bytecodes::_dup_x1:
a61af66fc99e Initial load
duke
parents:
diff changeset
694 case Bytecodes::_dup_x2:
a61af66fc99e Initial load
duke
parents:
diff changeset
695 case Bytecodes::_dup2:
a61af66fc99e Initial load
duke
parents:
diff changeset
696 case Bytecodes::_dup2_x1:
a61af66fc99e Initial load
duke
parents:
diff changeset
697 case Bytecodes::_dup2_x2:
a61af66fc99e Initial load
duke
parents:
diff changeset
698 case Bytecodes::_swap:
a61af66fc99e Initial load
duke
parents:
diff changeset
699 case Bytecodes::_iadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
700 case Bytecodes::_fadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
701 case Bytecodes::_isub:
a61af66fc99e Initial load
duke
parents:
diff changeset
702 case Bytecodes::_fsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
703 case Bytecodes::_imul:
a61af66fc99e Initial load
duke
parents:
diff changeset
704 case Bytecodes::_fmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
705 case Bytecodes::_idiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
706 case Bytecodes::_fdiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
707 case Bytecodes::_irem:
a61af66fc99e Initial load
duke
parents:
diff changeset
708 case Bytecodes::_frem:
a61af66fc99e Initial load
duke
parents:
diff changeset
709 case Bytecodes::_ishl:
a61af66fc99e Initial load
duke
parents:
diff changeset
710 case Bytecodes::_ishr:
a61af66fc99e Initial load
duke
parents:
diff changeset
711 case Bytecodes::_iushr:
a61af66fc99e Initial load
duke
parents:
diff changeset
712 case Bytecodes::_iand:
a61af66fc99e Initial load
duke
parents:
diff changeset
713 case Bytecodes::_ior:
a61af66fc99e Initial load
duke
parents:
diff changeset
714 case Bytecodes::_ixor:
a61af66fc99e Initial load
duke
parents:
diff changeset
715 case Bytecodes::_l2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
716 case Bytecodes::_l2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
717 case Bytecodes::_d2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
718 case Bytecodes::_d2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
719 case Bytecodes::_fcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
720 case Bytecodes::_fcmpg:
a61af66fc99e Initial load
duke
parents:
diff changeset
721 case Bytecodes::_ladd:
a61af66fc99e Initial load
duke
parents:
diff changeset
722 case Bytecodes::_dadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
723 case Bytecodes::_lsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
724 case Bytecodes::_dsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
725 case Bytecodes::_lmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
726 case Bytecodes::_dmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
727 case Bytecodes::_ldiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
728 case Bytecodes::_ddiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
729 case Bytecodes::_lrem:
a61af66fc99e Initial load
duke
parents:
diff changeset
730 case Bytecodes::_drem:
a61af66fc99e Initial load
duke
parents:
diff changeset
731 case Bytecodes::_land:
a61af66fc99e Initial load
duke
parents:
diff changeset
732 case Bytecodes::_lor:
a61af66fc99e Initial load
duke
parents:
diff changeset
733 case Bytecodes::_lxor:
a61af66fc99e Initial load
duke
parents:
diff changeset
734 case Bytecodes::_ineg:
a61af66fc99e Initial load
duke
parents:
diff changeset
735 case Bytecodes::_fneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
736 case Bytecodes::_i2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
737 case Bytecodes::_f2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
738 case Bytecodes::_i2c:
a61af66fc99e Initial load
duke
parents:
diff changeset
739 case Bytecodes::_i2s:
a61af66fc99e Initial load
duke
parents:
diff changeset
740 case Bytecodes::_i2b:
a61af66fc99e Initial load
duke
parents:
diff changeset
741 case Bytecodes::_lneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
742 case Bytecodes::_dneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
743 case Bytecodes::_l2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
744 case Bytecodes::_d2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
745 case Bytecodes::_lshl:
a61af66fc99e Initial load
duke
parents:
diff changeset
746 case Bytecodes::_lshr:
a61af66fc99e Initial load
duke
parents:
diff changeset
747 case Bytecodes::_lushr:
a61af66fc99e Initial load
duke
parents:
diff changeset
748 case Bytecodes::_i2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
749 case Bytecodes::_i2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
750 case Bytecodes::_f2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
751 case Bytecodes::_f2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
752 case Bytecodes::_lcmp:
a61af66fc99e Initial load
duke
parents:
diff changeset
753 case Bytecodes::_dcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
754 case Bytecodes::_dcmpg:
a61af66fc99e Initial load
duke
parents:
diff changeset
755 case Bytecodes::_ifeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
756 case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
757 case Bytecodes::_iflt:
a61af66fc99e Initial load
duke
parents:
diff changeset
758 case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
759 case Bytecodes::_ifgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
760 case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
761 case Bytecodes::_tableswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
762 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
763 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
764 case Bytecodes::_if_icmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
765 case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
766 case Bytecodes::_if_icmplt:
a61af66fc99e Initial load
duke
parents:
diff changeset
767 case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
768 case Bytecodes::_if_icmpgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
769 case Bytecodes::_if_icmple:
a61af66fc99e Initial load
duke
parents:
diff changeset
770 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
771 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
772 case Bytecodes::_if_acmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
773 case Bytecodes::_if_acmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
774 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
775 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
776 case Bytecodes::_getstatic:
a61af66fc99e Initial load
duke
parents:
diff changeset
777 case Bytecodes::_putstatic:
a61af66fc99e Initial load
duke
parents:
diff changeset
778 case Bytecodes::_getfield:
a61af66fc99e Initial load
duke
parents:
diff changeset
779 case Bytecodes::_putfield:
a61af66fc99e Initial load
duke
parents:
diff changeset
780 case Bytecodes::_invokevirtual:
a61af66fc99e Initial load
duke
parents:
diff changeset
781 case Bytecodes::_invokespecial:
a61af66fc99e Initial load
duke
parents:
diff changeset
782 case Bytecodes::_invokestatic:
a61af66fc99e Initial load
duke
parents:
diff changeset
783 case Bytecodes::_invokeinterface:
a61af66fc99e Initial load
duke
parents:
diff changeset
784 case Bytecodes::_newarray:
a61af66fc99e Initial load
duke
parents:
diff changeset
785 case Bytecodes::_anewarray:
a61af66fc99e Initial load
duke
parents:
diff changeset
786 case Bytecodes::_checkcast:
a61af66fc99e Initial load
duke
parents:
diff changeset
787 case Bytecodes::_arraylength:
a61af66fc99e Initial load
duke
parents:
diff changeset
788 case Bytecodes::_instanceof:
a61af66fc99e Initial load
duke
parents:
diff changeset
789 case Bytecodes::_athrow:
a61af66fc99e Initial load
duke
parents:
diff changeset
790 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
791 case Bytecodes::_monitorenter:
a61af66fc99e Initial load
duke
parents:
diff changeset
792 case Bytecodes::_monitorexit:
a61af66fc99e Initial load
duke
parents:
diff changeset
793 case Bytecodes::_ifnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
794 case Bytecodes::_ifnonnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
795 case Bytecodes::_multianewarray:
a61af66fc99e Initial load
duke
parents:
diff changeset
796 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // These bytecodes have no effect on the method's locals.
a61af66fc99e Initial load
duke
parents:
diff changeset
798 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
799
a61af66fc99e Initial load
duke
parents:
diff changeset
800 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
801 if (instruction->method()->intrinsic_id() == vmIntrinsics::_Object_init) {
a61af66fc99e Initial load
duke
parents:
diff changeset
802 // return from Object.init implicitly registers a finalizer
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // for the receiver if needed, so keep it alive.
a61af66fc99e Initial load
duke
parents:
diff changeset
804 load_one(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 }
a61af66fc99e Initial load
duke
parents:
diff changeset
806 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
807
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 case Bytecodes::_lload:
a61af66fc99e Initial load
duke
parents:
diff changeset
810 case Bytecodes::_dload:
a61af66fc99e Initial load
duke
parents:
diff changeset
811 load_two(instruction->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
812 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
813
a61af66fc99e Initial load
duke
parents:
diff changeset
814 case Bytecodes::_lload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
815 case Bytecodes::_dload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
816 load_two(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
817 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
818
a61af66fc99e Initial load
duke
parents:
diff changeset
819 case Bytecodes::_lload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
820 case Bytecodes::_dload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
821 load_two(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
822 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824 case Bytecodes::_lload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
825 case Bytecodes::_dload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
826 load_two(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
828
a61af66fc99e Initial load
duke
parents:
diff changeset
829 case Bytecodes::_lload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
830 case Bytecodes::_dload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
831 load_two(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 case Bytecodes::_iload:
a61af66fc99e Initial load
duke
parents:
diff changeset
835 case Bytecodes::_iinc:
a61af66fc99e Initial load
duke
parents:
diff changeset
836 case Bytecodes::_fload:
a61af66fc99e Initial load
duke
parents:
diff changeset
837 case Bytecodes::_aload:
a61af66fc99e Initial load
duke
parents:
diff changeset
838 case Bytecodes::_ret:
a61af66fc99e Initial load
duke
parents:
diff changeset
839 load_one(instruction->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
840 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
841
a61af66fc99e Initial load
duke
parents:
diff changeset
842 case Bytecodes::_iload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
843 case Bytecodes::_fload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
844 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
845 load_one(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
847
a61af66fc99e Initial load
duke
parents:
diff changeset
848 case Bytecodes::_iload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
849 case Bytecodes::_fload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
850 case Bytecodes::_aload_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
851 load_one(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
852 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
853
a61af66fc99e Initial load
duke
parents:
diff changeset
854 case Bytecodes::_iload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
855 case Bytecodes::_fload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
856 case Bytecodes::_aload_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
857 load_one(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
858 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
859
a61af66fc99e Initial load
duke
parents:
diff changeset
860 case Bytecodes::_iload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
861 case Bytecodes::_fload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
862 case Bytecodes::_aload_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
863 load_one(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
865
a61af66fc99e Initial load
duke
parents:
diff changeset
866 case Bytecodes::_lstore:
a61af66fc99e Initial load
duke
parents:
diff changeset
867 case Bytecodes::_dstore:
a61af66fc99e Initial load
duke
parents:
diff changeset
868 store_two(localNum = instruction->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
869 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
870
a61af66fc99e Initial load
duke
parents:
diff changeset
871 case Bytecodes::_lstore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
872 case Bytecodes::_dstore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
873 store_two(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
874 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 case Bytecodes::_lstore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
877 case Bytecodes::_dstore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
878 store_two(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
880
a61af66fc99e Initial load
duke
parents:
diff changeset
881 case Bytecodes::_lstore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
882 case Bytecodes::_dstore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
883 store_two(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
884 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 case Bytecodes::_lstore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
887 case Bytecodes::_dstore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
888 store_two(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
889 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
890
a61af66fc99e Initial load
duke
parents:
diff changeset
891 case Bytecodes::_istore:
a61af66fc99e Initial load
duke
parents:
diff changeset
892 case Bytecodes::_fstore:
a61af66fc99e Initial load
duke
parents:
diff changeset
893 case Bytecodes::_astore:
a61af66fc99e Initial load
duke
parents:
diff changeset
894 store_one(instruction->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
895 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
896
a61af66fc99e Initial load
duke
parents:
diff changeset
897 case Bytecodes::_istore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
898 case Bytecodes::_fstore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
899 case Bytecodes::_astore_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
900 store_one(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
901 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 case Bytecodes::_istore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
904 case Bytecodes::_fstore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
905 case Bytecodes::_astore_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
906 store_one(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
907 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
908
a61af66fc99e Initial load
duke
parents:
diff changeset
909 case Bytecodes::_istore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
910 case Bytecodes::_fstore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
911 case Bytecodes::_astore_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
912 store_one(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915 case Bytecodes::_istore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
916 case Bytecodes::_fstore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
917 case Bytecodes::_astore_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
918 store_one(3);
a61af66fc99e Initial load
duke
parents:
diff changeset
919 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
920
a61af66fc99e Initial load
duke
parents:
diff changeset
921 case Bytecodes::_wide:
a61af66fc99e Initial load
duke
parents:
diff changeset
922 fatal("Iterator should skip this bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
923 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
924
a61af66fc99e Initial load
duke
parents:
diff changeset
925 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
926 tty->print("unexpected opcode: %d\n", instruction->cur_bc());
a61af66fc99e Initial load
duke
parents:
diff changeset
927 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
928 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
931
a61af66fc99e Initial load
duke
parents:
diff changeset
932 void MethodLiveness::BasicBlock::load_two(int local) {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 load_one(local);
a61af66fc99e Initial load
duke
parents:
diff changeset
934 load_one(local+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936
a61af66fc99e Initial load
duke
parents:
diff changeset
937 void MethodLiveness::BasicBlock::load_one(int local) {
a61af66fc99e Initial load
duke
parents:
diff changeset
938 if (!_kill.at(local)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 _gen.at_put(local, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942
a61af66fc99e Initial load
duke
parents:
diff changeset
943 void MethodLiveness::BasicBlock::store_two(int local) {
a61af66fc99e Initial load
duke
parents:
diff changeset
944 store_one(local);
a61af66fc99e Initial load
duke
parents:
diff changeset
945 store_one(local+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
946 }
a61af66fc99e Initial load
duke
parents:
diff changeset
947
a61af66fc99e Initial load
duke
parents:
diff changeset
948 void MethodLiveness::BasicBlock::store_one(int local) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 if (!_gen.at(local)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 _kill.at_put(local, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
952 }
a61af66fc99e Initial load
duke
parents:
diff changeset
953
a61af66fc99e Initial load
duke
parents:
diff changeset
954 void MethodLiveness::BasicBlock::propagate(MethodLiveness *ml) {
a61af66fc99e Initial load
duke
parents:
diff changeset
955 // These set operations could be combined for efficiency if the
a61af66fc99e Initial load
duke
parents:
diff changeset
956 // performance of this analysis becomes an issue.
a61af66fc99e Initial load
duke
parents:
diff changeset
957 _entry.set_union(_normal_exit);
a61af66fc99e Initial load
duke
parents:
diff changeset
958 _entry.set_difference(_kill);
a61af66fc99e Initial load
duke
parents:
diff changeset
959 _entry.set_union(_gen);
a61af66fc99e Initial load
duke
parents:
diff changeset
960
a61af66fc99e Initial load
duke
parents:
diff changeset
961 // Note that we merge information from our exceptional successors
a61af66fc99e Initial load
duke
parents:
diff changeset
962 // just once, rather than at individual bytecodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
963 _entry.set_union(_exception_exit);
a61af66fc99e Initial load
duke
parents:
diff changeset
964
a61af66fc99e Initial load
duke
parents:
diff changeset
965 if (TraceLivenessGen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 tty->print_cr(" ** Visiting block at %d **", start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
967 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
971 for (i=_normal_predecessors->length()-1; i>=0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
972 BasicBlock *block = _normal_predecessors->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
973 if (block->merge_normal(_entry)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
974 ml->work_list_add(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
975 }
a61af66fc99e Initial load
duke
parents:
diff changeset
976 }
a61af66fc99e Initial load
duke
parents:
diff changeset
977 for (i=_exception_predecessors->length()-1; i>=0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 BasicBlock *block = _exception_predecessors->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
979 if (block->merge_exception(_entry)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
980 ml->work_list_add(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
983 }
a61af66fc99e Initial load
duke
parents:
diff changeset
984
a61af66fc99e Initial load
duke
parents:
diff changeset
985 bool MethodLiveness::BasicBlock::merge_normal(BitMap other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
986 return _normal_exit.set_union_with_result(other);
a61af66fc99e Initial load
duke
parents:
diff changeset
987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 bool MethodLiveness::BasicBlock::merge_exception(BitMap other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 return _exception_exit.set_union_with_result(other);
a61af66fc99e Initial load
duke
parents:
diff changeset
991 }
a61af66fc99e Initial load
duke
parents:
diff changeset
992
a61af66fc99e Initial load
duke
parents:
diff changeset
993 MethodLivenessResult MethodLiveness::BasicBlock::get_liveness_at(ciMethod* method, int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
994 MethodLivenessResult answer(NEW_RESOURCE_ARRAY(uintptr_t, _analyzer->bit_map_size_words()),
a61af66fc99e Initial load
duke
parents:
diff changeset
995 _analyzer->bit_map_size_bits());
a61af66fc99e Initial load
duke
parents:
diff changeset
996 answer.set_is_valid();
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 #ifndef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
999 if (bci == start_bci()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 answer.set_from(_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 return answer;
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1004
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 BitMap g(_gen.size()); g.set_from(_gen);
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 BitMap k(_kill.size()); k.set_from(_kill);
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 if (_last_bci != bci || trueInDebug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 ciBytecodeStream bytes(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 bytes.reset_to_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 bytes.set_max_bci(limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 compute_gen_kill_range(&bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 assert(_last_bci != bci ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 (g.is_same(_gen) && k.is_same(_kill)), "cached computation is incorrect");
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 _last_bci = bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1019
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 answer.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 answer.set_union(_normal_exit);
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 answer.set_difference(_kill);
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 answer.set_union(_gen);
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 answer.set_union(_exception_exit);
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 if (bci == start_bci()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 assert(answer.is_same(_entry), "optimized answer must be accurate");
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1031
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 return answer;
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1036
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 void MethodLiveness::BasicBlock::print_on(outputStream *os) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 os->print_cr("===================================================================");
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 os->print_cr(" Block start: %4d, limit: %4d", _start_bci, _limit_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 os->print (" Normal predecessors (%2d) @", _normal_predecessors->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 for (i=0; i < _normal_predecessors->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 os->print(" %4d", _normal_predecessors->at(i)->start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 os->print (" Exceptional predecessors (%2d) @", _exception_predecessors->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 for (i=0; i < _exception_predecessors->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 os->print(" %4d", _exception_predecessors->at(i)->start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 os->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 os->print (" Normal Exit : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 _normal_exit.print_on(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 os->print (" Gen : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 _gen.print_on(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 os->print (" Kill : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 _kill.print_on(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 os->print (" Exception Exit: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 _exception_exit.print_on(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 os->print (" Entry : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 _entry.print_on(os);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 #endif // PRODUCT