annotate src/share/vm/ci/ciMethodBlocks.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 0871d5cd64cd
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 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 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_ciMethodBlocks.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // ciMethodBlocks
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 ciBlock *ciMethodBlocks::block_containing(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 ciBlock *blk = _bci_to_block[bci];
a61af66fc99e Initial load
duke
parents:
diff changeset
34 return blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 }
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 bool ciMethodBlocks::is_block_start(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(bci >=0 && bci < _code_size, "valid bytecode range");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 ciBlock *b = _bci_to_block[bci];
a61af66fc99e Initial load
duke
parents:
diff changeset
40 assert(b != NULL, "must have block for bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 return b->start_bci() == bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // ciMethodBlocks::split_block_at
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Split the block spanning bci into two separate ranges. The former
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // block becomes the second half and a new range is created for the
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // first half. Returns the range beginning at bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
50 ciBlock *ciMethodBlocks::split_block_at(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 ciBlock *former_block = block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 ciBlock *new_block = new(_arena) ciBlock(_method, _num_blocks++, this, former_block->start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _blocks->append(new_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 assert(former_block != NULL, "must not be NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
55 new_block->set_limit_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 former_block->set_start_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 for (int pos=bci-1; pos >= 0; pos--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 ciBlock *current_block = block_containing(pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (current_block == former_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Replace it.
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _bci_to_block[pos] = new_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 } else if (current_block == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Non-bytecode start. Skip.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // We are done with our backwards walk
a61af66fc99e Initial load
duke
parents:
diff changeset
67 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return former_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 ciBlock *ciMethodBlocks::make_block_at(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 ciBlock *cb = block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (cb == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // This is our first time visiting this bytecode. Create
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // a fresh block and assign it this starting point.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 ciBlock *nb = new(_arena) ciBlock(_method, _num_blocks++, this, bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 _blocks->append(nb);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _bci_to_block[bci] = nb;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return nb;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } else if (cb->start_bci() == bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // The block begins at bci. Simply return it.
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return cb;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // We have already created a block containing bci but
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // not starting at bci. This existing block needs to
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // be split into two.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return split_block_at(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 void ciMethodBlocks::do_analysis() {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 ciBytecodeStream s(_method);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 ciBlock *cur_block = block_containing(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 int limit_bci = _method->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 while (s.next() != ciBytecodeStream::EOBC()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 int bci = s.cur_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Determine if a new block has been made at the current bci. If
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // this block differs from our current range, switch to the new
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // one and end the old one.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 assert(cur_block != NULL, "must always have a current block");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 ciBlock *new_block = block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (new_block == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // We have not marked this bci as the start of a new block.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Keep interpreting the current_range.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _bci_to_block[bci] = cur_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 cur_block->set_limit_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 cur_block = new_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 switch (s.cur_bc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case Bytecodes::_ifeq :
a61af66fc99e Initial load
duke
parents:
diff changeset
116 case Bytecodes::_ifne :
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case Bytecodes::_iflt :
a61af66fc99e Initial load
duke
parents:
diff changeset
118 case Bytecodes::_ifge :
a61af66fc99e Initial load
duke
parents:
diff changeset
119 case Bytecodes::_ifgt :
a61af66fc99e Initial load
duke
parents:
diff changeset
120 case Bytecodes::_ifle :
a61af66fc99e Initial load
duke
parents:
diff changeset
121 case Bytecodes::_if_icmpeq :
a61af66fc99e Initial load
duke
parents:
diff changeset
122 case Bytecodes::_if_icmpne :
a61af66fc99e Initial load
duke
parents:
diff changeset
123 case Bytecodes::_if_icmplt :
a61af66fc99e Initial load
duke
parents:
diff changeset
124 case Bytecodes::_if_icmpge :
a61af66fc99e Initial load
duke
parents:
diff changeset
125 case Bytecodes::_if_icmpgt :
a61af66fc99e Initial load
duke
parents:
diff changeset
126 case Bytecodes::_if_icmple :
a61af66fc99e Initial load
duke
parents:
diff changeset
127 case Bytecodes::_if_acmpeq :
a61af66fc99e Initial load
duke
parents:
diff changeset
128 case Bytecodes::_if_acmpne :
a61af66fc99e Initial load
duke
parents:
diff changeset
129 case Bytecodes::_ifnull :
a61af66fc99e Initial load
duke
parents:
diff changeset
130 case Bytecodes::_ifnonnull :
a61af66fc99e Initial load
duke
parents:
diff changeset
131 {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ciBlock *fall_through = make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int dest_bci = s.get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ciBlock *dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 case Bytecodes::_goto :
a61af66fc99e Initial load
duke
parents:
diff changeset
140 {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (s.next_bci() < limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 (void) make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 int dest_bci = s.get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 ciBlock *dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 case Bytecodes::_jsr :
a61af66fc99e Initial load
duke
parents:
diff changeset
151 {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 ciBlock *ret = make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int dest_bci = s.get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 ciBlock *dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 case Bytecodes::_tableswitch :
a61af66fc99e Initial load
duke
parents:
diff changeset
160 {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 Bytecode_tableswitch* switch_ = Bytecode_tableswitch_at(s.cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 int len = switch_->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 ciBlock *dest;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 int dest_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 dest_bci = s.cur_bci() + switch_->dest_offset_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 dest_bci = s.cur_bci() + switch_->default_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (s.next_bci() < limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 dest = make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
179 {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 Bytecode_lookupswitch* switch_ = Bytecode_lookupswitch_at(s.cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
182 int len = switch_->number_of_pairs();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 ciBlock *dest;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 int dest_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 dest_bci = s.cur_bci() + switch_->pair_at(i)->offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 dest_bci = s.cur_bci() + switch_->default_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (s.next_bci() < limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 dest = make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 case Bytecodes::_goto_w :
a61af66fc99e Initial load
duke
parents:
diff changeset
198 {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (s.next_bci() < limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 (void) make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 int dest_bci = s.get_far_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ciBlock *dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 case Bytecodes::_jsr_w :
a61af66fc99e Initial load
duke
parents:
diff changeset
209 {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ciBlock *ret = make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
212 int dest_bci = s.get_far_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 ciBlock *dest = make_block_at(dest_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 case Bytecodes::_athrow :
a61af66fc99e Initial load
duke
parents:
diff changeset
218 cur_block->set_may_throw();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // fall-through
a61af66fc99e Initial load
duke
parents:
diff changeset
220 case Bytecodes::_ret :
a61af66fc99e Initial load
duke
parents:
diff changeset
221 case Bytecodes::_ireturn :
a61af66fc99e Initial load
duke
parents:
diff changeset
222 case Bytecodes::_lreturn :
a61af66fc99e Initial load
duke
parents:
diff changeset
223 case Bytecodes::_freturn :
a61af66fc99e Initial load
duke
parents:
diff changeset
224 case Bytecodes::_dreturn :
a61af66fc99e Initial load
duke
parents:
diff changeset
225 case Bytecodes::_areturn :
a61af66fc99e Initial load
duke
parents:
diff changeset
226 case Bytecodes::_return :
a61af66fc99e Initial load
duke
parents:
diff changeset
227 cur_block->set_control_bci(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (s.next_bci() < limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 (void) make_block_at(s.next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // End the last block
a61af66fc99e Initial load
duke
parents:
diff changeset
235 cur_block->set_limit_bci(limit_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 ciMethodBlocks::ciMethodBlocks(Arena *arena, ciMethod *meth): _method(meth),
a61af66fc99e Initial load
duke
parents:
diff changeset
239 _arena(arena), _num_blocks(0), _code_size(meth->code_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 int block_estimate = _code_size / 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 _blocks = new(_arena) GrowableArray<ciBlock *>(block_estimate);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 int b2bsize = _code_size * sizeof(ciBlock **);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 _bci_to_block = (ciBlock **) arena->Amalloc(b2bsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 Copy::zero_to_words((HeapWord*) _bci_to_block, b2bsize / sizeof(HeapWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // create initial block covering the entire method
a61af66fc99e Initial load
duke
parents:
diff changeset
248 ciBlock *b = new(arena) ciBlock(_method, _num_blocks++, this, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 _blocks->append(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 _bci_to_block[0] = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // create blocks for exception handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (meth->has_exception_handlers()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 for(ciExceptionHandlerStream str(meth); !str.is_done(); str.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ciExceptionHandler* handler = str.handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
256 ciBlock *eb = make_block_at(handler->handler_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
257 eb->set_handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int ex_start = handler->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
259 int ex_end = handler->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 eb->set_exception_range(ex_start, ex_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // ensure a block at the start of exception range and start of following code
a61af66fc99e Initial load
duke
parents:
diff changeset
262 (void) make_block_at(ex_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (ex_end < _code_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
264 (void) make_block_at(ex_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // scan the bytecodes and identify blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
269 do_analysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // mark blocks that have exception handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (meth->has_exception_handlers()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 for(ciExceptionHandlerStream str(meth); !str.is_done(); str.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 ciExceptionHandler* handler = str.handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 int ex_start = handler->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 int ex_end = handler->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 int bci = ex_start;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 while (bci < ex_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ciBlock *b = block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 b->set_has_handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 bci = b->limit_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 void ciMethodBlocks::clear_processed() {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 for (int i = 0; i < _blocks->length(); i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
290 _blocks->at(i)->clear_processed();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
294 void ciMethodBlocks::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 tty->print("---- blocks for method: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
296 _method->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 for (int i = 0; i < _blocks->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 tty->print(" B%d: ", i); _blocks->at(i)->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 ciBlock::ciBlock(ciMethod *method, int index, ciMethodBlocks *mb, int start_bci) :
a61af66fc99e Initial load
duke
parents:
diff changeset
306 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
307 _method(method),
a61af66fc99e Initial load
duke
parents:
diff changeset
308 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
309 _idx(index), _flags(0), _start_bci(start_bci), _limit_bci(-1), _control_bci(fall_through_bci),
a61af66fc99e Initial load
duke
parents:
diff changeset
310 _ex_start_bci(-1), _ex_limit_bci(-1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 void ciBlock::set_exception_range(int start_bci, int limit_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 assert(limit_bci >= start_bci, "valid range");
a61af66fc99e Initial load
duke
parents:
diff changeset
315 assert(is_handler(), "must be handler");
a61af66fc99e Initial load
duke
parents:
diff changeset
316 _ex_start_bci = start_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
317 _ex_limit_bci = limit_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
321 static char *flagnames[] = {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 "Processed",
a61af66fc99e Initial load
duke
parents:
diff changeset
323 "Handler",
a61af66fc99e Initial load
duke
parents:
diff changeset
324 "MayThrow",
a61af66fc99e Initial load
duke
parents:
diff changeset
325 "Jsr",
a61af66fc99e Initial load
duke
parents:
diff changeset
326 "Ret",
a61af66fc99e Initial load
duke
parents:
diff changeset
327 "RetTarget",
a61af66fc99e Initial load
duke
parents:
diff changeset
328 "HasHandler",
a61af66fc99e Initial load
duke
parents:
diff changeset
329 };
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 void ciBlock::dump() {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 tty->print(" [%d .. %d), {", _start_bci, _limit_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 for (int i = 0; i < 8; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if ((_flags & (1 << i)) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 tty->print(" %s", flagnames[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338 tty->print(" ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
339 if (is_handler())
a61af66fc99e Initial load
duke
parents:
diff changeset
340 tty->print(" handles(%d..%d)", _ex_start_bci, _ex_limit_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
341 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // ciBlock::print_on
a61af66fc99e Initial load
duke
parents:
diff changeset
346 void ciBlock::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 st->print_cr("--------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
348 st->print ("ciBlock [%d - %d) control : ", start_bci(), limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (control_bci() == fall_through_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 st->print_cr("%d:fall through", limit_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
351 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 st->print_cr("%d:%s", control_bci(),
a61af66fc99e Initial load
duke
parents:
diff changeset
353 Bytecodes::name(method()->java_code_at_bci(control_bci())));
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (Verbose || WizardMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 method()->print_codes_on(start_bci(), limit_bci(), st);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 #endif