annotate src/share/vm/ci/ciTypeFlow.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children fa4d1d240383
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 2000-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
a61af66fc99e Initial load
duke
parents:
diff changeset
26 class ciTypeFlow : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
27 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
28 ciEnv* _env;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 ciMethod* _method;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 ciMethodBlocks* _methodBlocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 int _osr_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // information cached from the method:
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int _max_locals;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 int _max_stack;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 int _code_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 const char* _failure_reason;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class StateVector;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class Block;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Build a type flow analyzer
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Do an OSR analysis if osr_bci >= 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci = InvocationEntryBci);
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
49 ciMethod* method() const { return _method; }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 ciEnv* env() { return _env; }
a61af66fc99e Initial load
duke
parents:
diff changeset
51 Arena* arena() { return _env->arena(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
52 bool is_osr_flow() const{ return _osr_bci != InvocationEntryBci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 int start_bci() const { return is_osr_flow()? _osr_bci: 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 int max_locals() const { return _max_locals; }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 int max_stack() const { return _max_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int max_cells() const { return _max_locals + _max_stack; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int code_size() const { return _code_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Represents information about an "active" jsr call. This
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // class represents a call to the routine at some entry address
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // with some distinct return address.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 class JsrRecord : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
64 int _entry_address;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 int _return_address;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 JsrRecord(int entry_address, int return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _entry_address = entry_address;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 _return_address = return_address;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int entry_address() const { return _entry_address; }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 int return_address() const { return _return_address; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
77 st->print("%d->%d", entry_address(), return_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
78 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 };
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // A JsrSet represents some set of JsrRecords. This class
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // is used to record a set of all jsr routines which we permit
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // execution to return (ret) from.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 //
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // During abstract interpretation, JsrSets are used to determine
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // whether two paths which reach a given block are unique, and
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // should be cloned apart, or are compatible, and should merge
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // together.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 //
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Note that different amounts of effort can be expended determining
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // if paths are compatible. <DISCUSSION>
a61af66fc99e Initial load
duke
parents:
diff changeset
93 class JsrSet : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
95 GrowableArray<JsrRecord*>* _set;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 JsrRecord* record_at(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return _set->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Insert the given JsrRecord into the JsrSet, maintaining the order
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // of the set and replacing any element with the same entry address.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void insert_jsr_record(JsrRecord* record);
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Remove the JsrRecord with the given return address from the JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 void remove_jsr_record(int return_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
109 JsrSet(Arena* arena, int default_len = 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Copy this JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void copy_into(JsrSet* jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // Is this JsrSet compatible with some other JsrSet?
a61af66fc99e Initial load
duke
parents:
diff changeset
115 bool is_compatible_with(JsrSet* other);
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Apply the effect of a single bytecode to the JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void apply_control(ciTypeFlow* analyzer,
a61af66fc99e Initial load
duke
parents:
diff changeset
119 ciBytecodeStream* str,
a61af66fc99e Initial load
duke
parents:
diff changeset
120 StateVector* state);
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // What is the cardinality of this set?
a61af66fc99e Initial load
duke
parents:
diff changeset
123 int size() const { return _set->length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void print_on(outputStream* st) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 };
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Used as a combined index for locals and temps
a61af66fc99e Initial load
duke
parents:
diff changeset
129 enum Cell {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 Cell_0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 };
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // A StateVector summarizes the type information at some
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // point in the program
a61af66fc99e Initial load
duke
parents:
diff changeset
135 class StateVector : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ciType** _types;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 int _stack_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int _monitor_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 ciTypeFlow* _outer;
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 int _trap_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 int _trap_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 static ciType* type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer);
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Special elements in our type lattice.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 T_TOP = T_VOID, // why not?
a61af66fc99e Initial load
duke
parents:
diff changeset
151 T_BOTTOM = T_CONFLICT,
a61af66fc99e Initial load
duke
parents:
diff changeset
152 T_LONG2 = T_SHORT, // 2nd word of T_LONG
a61af66fc99e Initial load
duke
parents:
diff changeset
153 T_DOUBLE2 = T_CHAR, // 2nd word of T_DOUBLE
a61af66fc99e Initial load
duke
parents:
diff changeset
154 T_NULL = T_BYTE // for now.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 };
a61af66fc99e Initial load
duke
parents:
diff changeset
156 static ciType* top_type() { return ciType::make((BasicType)T_TOP); }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 static ciType* bottom_type() { return ciType::make((BasicType)T_BOTTOM); }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 static ciType* long2_type() { return ciType::make((BasicType)T_LONG2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 static ciType* double2_type(){ return ciType::make((BasicType)T_DOUBLE2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 static ciType* null_type() { return ciType::make((BasicType)T_NULL); }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 static ciType* half_type(ciType* t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 switch (t->basic_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 case T_LONG: return long2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 case T_DOUBLE: return double2_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 default: ShouldNotReachHere(); return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // The meet operation for our type lattice.
a61af66fc99e Initial load
duke
parents:
diff changeset
171 ciType* type_meet(ciType* t1, ciType* t2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return type_meet_internal(t1, t2, outer());
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ciTypeFlow* outer() const { return _outer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 int stack_size() const { return _stack_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 void set_stack_size(int ss) { _stack_size = ss; }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 int monitor_count() const { return _monitor_count; }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 void set_monitor_count(int mc) { _monitor_count = mc; }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 static Cell start_cell() { return (Cell)0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 static Cell next_cell(Cell c) { return (Cell)(((int)c) + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 Cell limit_cell() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return (Cell)(outer()->max_locals() + stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Cell creation
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Cell local(int lnum) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert(lnum < outer()->max_locals(), "index check");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return (Cell)(lnum);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 Cell stack(int snum) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 assert(snum < stack_size(), "index check");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return (Cell)(outer()->max_locals() + snum);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Cell tos() const { return stack(stack_size()-1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // For external use only:
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ciType* local_type_at(int i) const { return type_at(local(i)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 ciType* stack_type_at(int i) const { return type_at(stack(i)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // Accessors for the type of some Cell c
a61af66fc99e Initial load
duke
parents:
diff changeset
208 ciType* type_at(Cell c) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return _types[c];
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void set_type_at(Cell c, ciType* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _types[c] = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Top-of-stack operations.
a61af66fc99e Initial load
duke
parents:
diff changeset
219 void set_type_at_tos(ciType* type) { set_type_at(tos(), type); }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 ciType* type_at_tos() const { return type_at(tos()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 void push(ciType* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 _stack_size++;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 set_type_at_tos(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 void pop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 debug_only(set_type_at_tos(bottom_type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _stack_size--;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 ciType* pop_value() {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 ciType* t = type_at_tos();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // Convenience operations.
a61af66fc99e Initial load
duke
parents:
diff changeset
237 bool is_reference(ciType* type) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 return type == null_type() || !type->is_primitive_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 bool is_int(ciType* type) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 return type->basic_type() == T_INT;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243 bool is_long(ciType* type) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 return type->basic_type() == T_LONG;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 bool is_float(ciType* type) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return type->basic_type() == T_FLOAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 bool is_double(ciType* type) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 return type->basic_type() == T_DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void push_translate(ciType* type);
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 void push_int() {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 push(ciType::make(T_INT));
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 void pop_int() {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 assert(is_int(type_at_tos()), "must be integer");
a61af66fc99e Initial load
duke
parents:
diff changeset
260 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 void check_int(Cell c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 assert(is_int(type_at(c)), "must be integer");
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void push_double() {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 push(ciType::make(T_DOUBLE));
a61af66fc99e Initial load
duke
parents:
diff changeset
267 push(double2_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269 void pop_double() {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 assert(type_at_tos() == double2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
271 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 assert(is_double(type_at_tos()), "must be double");
a61af66fc99e Initial load
duke
parents:
diff changeset
273 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 void push_float() {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 push(ciType::make(T_FLOAT));
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 void pop_float() {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 assert(is_float(type_at_tos()), "must be float");
a61af66fc99e Initial load
duke
parents:
diff changeset
280 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 void push_long() {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 push(ciType::make(T_LONG));
a61af66fc99e Initial load
duke
parents:
diff changeset
284 push(long2_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 void pop_long() {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 assert(type_at_tos() == long2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
288 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 assert(is_long(type_at_tos()), "must be long");
a61af66fc99e Initial load
duke
parents:
diff changeset
290 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 void push_object(ciKlass* klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 push(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 void pop_object() {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 assert(is_reference(type_at_tos()), "must be reference type");
a61af66fc99e Initial load
duke
parents:
diff changeset
297 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 void pop_array() {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 assert(type_at_tos() == null_type() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
301 type_at_tos()->is_array_klass(), "must be array type");
a61af66fc99e Initial load
duke
parents:
diff changeset
302 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // pop_objArray and pop_typeArray narrow the tos to ciObjArrayKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // or ciTypeArrayKlass (resp.). In the rare case that an explicit
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // null is popped from the stack, we return NULL. Caller beware.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 ciObjArrayKlass* pop_objArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 ciType* array = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (array == null_type()) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 assert(array->is_obj_array_klass(), "must be object array type");
a61af66fc99e Initial load
duke
parents:
diff changeset
311 return array->as_obj_array_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 ciTypeArrayKlass* pop_typeArray() {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 ciType* array = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 if (array == null_type()) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 assert(array->is_type_array_klass(), "must be prim array type");
a61af66fc99e Initial load
duke
parents:
diff changeset
317 return array->as_type_array_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 void push_null() {
a61af66fc99e Initial load
duke
parents:
diff changeset
320 push(null_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 void do_null_assert(ciKlass* unloaded_klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Helper convenience routines.
a61af66fc99e Initial load
duke
parents:
diff changeset
325 void do_aaload(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void do_checkcast(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void do_getfield(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 void do_getstatic(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 void do_invoke(ciBytecodeStream* str, bool has_receiver);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 void do_jsr(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 void do_ldc(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 void do_multianewarray(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 void do_new(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 void do_newarray(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
335 void do_putfield(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 void do_putstatic(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 void do_ret(ciBytecodeStream* str);
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 void overwrite_local_double_long(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // Invalidate the previous local if it contains first half of
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // a double or long value since it's seconf half is being overwritten.
a61af66fc99e Initial load
duke
parents:
diff changeset
342 int prev_index = index - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (prev_index >= 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
344 (is_double(type_at(local(prev_index))) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
345 is_long(type_at(local(prev_index))))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 set_type_at(local(prev_index), bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 void load_local_object(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 ciType* type = type_at(local(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
352 assert(is_reference(type), "must be reference type");
a61af66fc99e Initial load
duke
parents:
diff changeset
353 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 void store_local_object(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 assert(is_reference(type) || type->is_return_address(),
a61af66fc99e Initial load
duke
parents:
diff changeset
358 "must be reference type or return address");
a61af66fc99e Initial load
duke
parents:
diff changeset
359 overwrite_local_double_long(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 set_type_at(local(index), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 void load_local_double(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 ciType* type = type_at(local(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
365 ciType* type2 = type_at(local(index+1));
a61af66fc99e Initial load
duke
parents:
diff changeset
366 assert(is_double(type), "must be double type");
a61af66fc99e Initial load
duke
parents:
diff changeset
367 assert(type2 == double2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
368 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 push(double2_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 void store_local_double(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 ciType* type2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
373 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
374 assert(is_double(type), "must be double");
a61af66fc99e Initial load
duke
parents:
diff changeset
375 assert(type2 == double2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
376 overwrite_local_double_long(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 set_type_at(local(index), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 set_type_at(local(index+1), type2);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 void load_local_float(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 ciType* type = type_at(local(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
383 assert(is_float(type), "must be float type");
a61af66fc99e Initial load
duke
parents:
diff changeset
384 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386 void store_local_float(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
388 assert(is_float(type), "must be float type");
a61af66fc99e Initial load
duke
parents:
diff changeset
389 overwrite_local_double_long(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 set_type_at(local(index), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 void load_local_int(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 ciType* type = type_at(local(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
395 assert(is_int(type), "must be int type");
a61af66fc99e Initial load
duke
parents:
diff changeset
396 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 void store_local_int(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
400 assert(is_int(type), "must be int type");
a61af66fc99e Initial load
duke
parents:
diff changeset
401 overwrite_local_double_long(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 set_type_at(local(index), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 void load_local_long(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 ciType* type = type_at(local(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
407 ciType* type2 = type_at(local(index+1));
a61af66fc99e Initial load
duke
parents:
diff changeset
408 assert(is_long(type), "must be long type");
a61af66fc99e Initial load
duke
parents:
diff changeset
409 assert(type2 == long2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
410 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 push(long2_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 void store_local_long(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 ciType* type2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
415 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 assert(is_long(type), "must be long");
a61af66fc99e Initial load
duke
parents:
diff changeset
417 assert(type2 == long2_type(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
418 overwrite_local_double_long(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 set_type_at(local(index), type);
a61af66fc99e Initial load
duke
parents:
diff changeset
420 set_type_at(local(index+1), type2);
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Stop interpretation of this path with a trap.
a61af66fc99e Initial load
duke
parents:
diff changeset
424 void trap(ciBytecodeStream* str, ciKlass* klass, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
427 StateVector(ciTypeFlow* outer);
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // Copy our value into some other StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
430 void copy_into(StateVector* copy) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // Meets this StateVector with another, destructively modifying this
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // one. Returns true if any modification takes place.
a61af66fc99e Initial load
duke
parents:
diff changeset
434 bool meet(const StateVector* incoming);
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 // Ditto, except that the incoming state is coming from an exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
437 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming);
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // Apply the effect of one bytecode to this StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
440 bool apply_one_bytecode(ciBytecodeStream* stream);
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // What is the bci of the trap?
a61af66fc99e Initial load
duke
parents:
diff changeset
443 int trap_bci() { return _trap_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // What is the index associated with the trap?
a61af66fc99e Initial load
duke
parents:
diff changeset
446 int trap_index() { return _trap_index; }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 void print_cell_on(outputStream* st, Cell c) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 void print_on(outputStream* st) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 };
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // Parameter for "find_block" calls:
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // Describes the difference between a public and private copy.
a61af66fc99e Initial load
duke
parents:
diff changeset
454 enum CreateOption {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 create_public_copy,
a61af66fc99e Initial load
duke
parents:
diff changeset
456 create_private_copy,
a61af66fc99e Initial load
duke
parents:
diff changeset
457 no_create
a61af66fc99e Initial load
duke
parents:
diff changeset
458 };
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // A basic block
a61af66fc99e Initial load
duke
parents:
diff changeset
461 class Block : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
463 ciBlock* _ciblock;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 GrowableArray<Block*>* _exceptions;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 GrowableArray<ciInstanceKlass*>* _exc_klasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 GrowableArray<Block*>* _successors;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 StateVector* _state;
a61af66fc99e Initial load
duke
parents:
diff changeset
468 JsrSet* _jsrs;
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 int _trap_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 int _trap_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // A reasonable approximation to pre-order, provided.to the client.
a61af66fc99e Initial load
duke
parents:
diff changeset
474 int _pre_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // Has this block been cloned for some special purpose?
a61af66fc99e Initial load
duke
parents:
diff changeset
477 bool _private_copy;
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // A pointer used for our internal work list
a61af66fc99e Initial load
duke
parents:
diff changeset
480 Block* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 bool _on_work_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 ciBlock* ciblock() const { return _ciblock; }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 StateVector* state() const { return _state; }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // Compute the exceptional successors and types for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
487 void compute_exceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // constructors
a61af66fc99e Initial load
duke
parents:
diff changeset
491 Block(ciTypeFlow* outer, ciBlock* ciblk, JsrSet* jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 void set_trap(int trap_bci, int trap_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 _trap_bci = trap_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 _trap_index = trap_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 assert(has_trap(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 bool has_trap() const { return _trap_bci != -1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
499 int trap_bci() const { assert(has_trap(), ""); return _trap_bci; }
a61af66fc99e Initial load
duke
parents:
diff changeset
500 int trap_index() const { assert(has_trap(), ""); return _trap_index; }
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
503 ciTypeFlow* outer() const { return state()->outer(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
504 int start() const { return _ciblock->start_bci(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
505 int limit() const { return _ciblock->limit_bci(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 int control() const { return _ciblock->control_bci(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 bool is_private_copy() const { return _private_copy; }
a61af66fc99e Initial load
duke
parents:
diff changeset
509 void set_private_copy(bool z);
a61af66fc99e Initial load
duke
parents:
diff changeset
510 int private_copy_count() const { return outer()->private_copy_count(ciblock()->index(), _jsrs); }
a61af66fc99e Initial load
duke
parents:
diff changeset
511
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // access to entry state
a61af66fc99e Initial load
duke
parents:
diff changeset
513 int stack_size() const { return _state->stack_size(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 int monitor_count() const { return _state->monitor_count(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 ciType* local_type_at(int i) const { return _state->local_type_at(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
516 ciType* stack_type_at(int i) const { return _state->stack_type_at(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // Get the successors for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
519 GrowableArray<Block*>* successors(ciBytecodeStream* str,
a61af66fc99e Initial load
duke
parents:
diff changeset
520 StateVector* state,
a61af66fc99e Initial load
duke
parents:
diff changeset
521 JsrSet* jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 GrowableArray<Block*>* successors() {
a61af66fc99e Initial load
duke
parents:
diff changeset
523 assert(_successors != NULL, "must be filled in");
a61af66fc99e Initial load
duke
parents:
diff changeset
524 return _successors;
a61af66fc99e Initial load
duke
parents:
diff changeset
525 }
a61af66fc99e Initial load
duke
parents:
diff changeset
526
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // Helper function for "successors" when making private copies of
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // loop heads for C2.
a61af66fc99e Initial load
duke
parents:
diff changeset
529 Block * clone_loop_head(ciTypeFlow* analyzer,
a61af66fc99e Initial load
duke
parents:
diff changeset
530 int branch_bci,
a61af66fc99e Initial load
duke
parents:
diff changeset
531 Block* target,
a61af66fc99e Initial load
duke
parents:
diff changeset
532 JsrSet* jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // Get the exceptional successors for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
535 GrowableArray<Block*>* exceptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (_exceptions == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 compute_exceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539 return _exceptions;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // Get the exception klasses corresponding to the
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // exceptional successors for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
544 GrowableArray<ciInstanceKlass*>* exc_klasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 if (_exc_klasses == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 compute_exceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548 return _exc_klasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 // Is this Block compatible with a given JsrSet?
a61af66fc99e Initial load
duke
parents:
diff changeset
552 bool is_compatible_with(JsrSet* other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 return _jsrs->is_compatible_with(other);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Copy the value of our state vector into another.
a61af66fc99e Initial load
duke
parents:
diff changeset
557 void copy_state_into(StateVector* copy) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 _state->copy_into(copy);
a61af66fc99e Initial load
duke
parents:
diff changeset
559 }
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // Copy the value of our JsrSet into another
a61af66fc99e Initial load
duke
parents:
diff changeset
562 void copy_jsrs_into(JsrSet* copy) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
563 _jsrs->copy_into(copy);
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // Meets the start state of this block with another state, destructively
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // modifying this one. Returns true if any modification takes place.
a61af66fc99e Initial load
duke
parents:
diff changeset
568 bool meet(const StateVector* incoming) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return state()->meet(incoming);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // Ditto, except that the incoming state is coming from an
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // exception path. This means the stack is replaced by the
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // appropriate exception type.
a61af66fc99e Initial load
duke
parents:
diff changeset
575 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming) {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 return state()->meet_exception(exc, incoming);
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // Work list manipulation
a61af66fc99e Initial load
duke
parents:
diff changeset
580 void set_next(Block* block) { _next = block; }
a61af66fc99e Initial load
duke
parents:
diff changeset
581 Block* next() const { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
582
a61af66fc99e Initial load
duke
parents:
diff changeset
583 void set_on_work_list(bool c) { _on_work_list = c; }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 bool is_on_work_list() const { return _on_work_list; }
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 bool has_pre_order() const { return _pre_order >= 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 void set_pre_order(int po) { assert(!has_pre_order() && po >= 0, ""); _pre_order = po; }
a61af66fc99e Initial load
duke
parents:
diff changeset
588 int pre_order() const { assert(has_pre_order(), ""); return _pre_order; }
a61af66fc99e Initial load
duke
parents:
diff changeset
589 bool is_start() const { return _pre_order == outer()->start_block_num(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // A ranking used in determining order within the work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
592 bool is_simpler_than(Block* other);
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 void print_value_on(outputStream* st) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
595 void print_on(outputStream* st) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
596 };
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 // Standard indexes of successors, for various bytecodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
599 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 FALL_THROUGH = 0, // normal control
a61af66fc99e Initial load
duke
parents:
diff changeset
601 IF_NOT_TAKEN = 0, // the not-taken branch of an if (i.e., fall-through)
a61af66fc99e Initial load
duke
parents:
diff changeset
602 IF_TAKEN = 1, // the taken branch of an if
a61af66fc99e Initial load
duke
parents:
diff changeset
603 GOTO_TARGET = 0, // unique successor for goto, jsr, or ret
a61af66fc99e Initial load
duke
parents:
diff changeset
604 SWITCH_DEFAULT = 0, // default branch of a switch
a61af66fc99e Initial load
duke
parents:
diff changeset
605 SWITCH_CASES = 1 // first index for any non-default switch branches
a61af66fc99e Initial load
duke
parents:
diff changeset
606 // Unlike in other blocks, the successors of a switch are listed uniquely.
a61af66fc99e Initial load
duke
parents:
diff changeset
607 };
a61af66fc99e Initial load
duke
parents:
diff changeset
608
a61af66fc99e Initial load
duke
parents:
diff changeset
609 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
610 // A mapping from pre_order to Blocks. This array is created
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // only at the end of the flow.
a61af66fc99e Initial load
duke
parents:
diff changeset
612 Block** _block_map;
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // For each ciBlock index, a list of Blocks which share this ciBlock.
a61af66fc99e Initial load
duke
parents:
diff changeset
615 GrowableArray<Block*>** _idx_to_blocklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // count of ciBlocks
a61af66fc99e Initial load
duke
parents:
diff changeset
617 int _ciblock_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // Tells if a given instruction is able to generate an exception edge.
a61af66fc99e Initial load
duke
parents:
diff changeset
620 bool can_trap(ciBytecodeStream& str);
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // Return the block beginning at bci which has a JsrSet compatible
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // with jsrs.
a61af66fc99e Initial load
duke
parents:
diff changeset
625 Block* block_at(int bci, JsrSet* set, CreateOption option = create_public_copy);
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // block factory
a61af66fc99e Initial load
duke
parents:
diff changeset
628 Block* get_block_for(int ciBlockIndex, JsrSet* jsrs, CreateOption option = create_public_copy);
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 // How many of the blocks have the private_copy bit set?
a61af66fc99e Initial load
duke
parents:
diff changeset
631 int private_copy_count(int ciBlockIndex, JsrSet* jsrs) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // Return an existing block containing bci which has a JsrSet compatible
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // with jsrs, or NULL if there is none.
a61af66fc99e Initial load
duke
parents:
diff changeset
635 Block* existing_block_at(int bci, JsrSet* set) { return block_at(bci, set, no_create); }
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // Tell whether the flow analysis has encountered an error of some sort.
a61af66fc99e Initial load
duke
parents:
diff changeset
638 bool failing() { return env()->failing() || _failure_reason != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // Reason this compilation is failing, such as "too many basic blocks".
a61af66fc99e Initial load
duke
parents:
diff changeset
641 const char* failure_reason() { return _failure_reason; }
a61af66fc99e Initial load
duke
parents:
diff changeset
642
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // Note a failure.
a61af66fc99e Initial load
duke
parents:
diff changeset
644 void record_failure(const char* reason);
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // Return the block of a given pre-order number.
a61af66fc99e Initial load
duke
parents:
diff changeset
647 int have_block_count() const { return _block_map != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
648 int block_count() const { assert(have_block_count(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
649 return _next_pre_order; }
a61af66fc99e Initial load
duke
parents:
diff changeset
650 Block* pre_order_at(int po) const { assert(0 <= po && po < block_count(), "out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
651 return _block_map[po]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 Block* start_block() const { return pre_order_at(start_block_num()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 int start_block_num() const { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
654
a61af66fc99e Initial load
duke
parents:
diff changeset
655 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // A work list used during flow analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
657 Block* _work_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
658
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // Next Block::_pre_order. After mapping, doubles as block_count.
a61af66fc99e Initial load
duke
parents:
diff changeset
660 int _next_pre_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
661
a61af66fc99e Initial load
duke
parents:
diff changeset
662 // Are there more blocks on the work list?
a61af66fc99e Initial load
duke
parents:
diff changeset
663 bool work_list_empty() { return _work_list == NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // Get the next basic block from our work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
666 Block* work_list_next();
a61af66fc99e Initial load
duke
parents:
diff changeset
667
a61af66fc99e Initial load
duke
parents:
diff changeset
668 // Add a basic block to our work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
669 void add_to_work_list(Block* block);
a61af66fc99e Initial load
duke
parents:
diff changeset
670
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // State used for make_jsr_record
a61af66fc99e Initial load
duke
parents:
diff changeset
672 int _jsr_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
673 GrowableArray<JsrRecord*>* _jsr_records;
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // Make a JsrRecord for a given (entry, return) pair, if such a record
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // does not already exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
678 JsrRecord* make_jsr_record(int entry_address, int return_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // Get the initial state for start_bci:
a61af66fc99e Initial load
duke
parents:
diff changeset
682 const StateVector* get_start_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 // Merge the current state into all exceptional successors at the
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // current point in the code.
a61af66fc99e Initial load
duke
parents:
diff changeset
686 void flow_exceptions(GrowableArray<Block*>* exceptions,
a61af66fc99e Initial load
duke
parents:
diff changeset
687 GrowableArray<ciInstanceKlass*>* exc_klasses,
a61af66fc99e Initial load
duke
parents:
diff changeset
688 StateVector* state);
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // Merge the current state into all successors at the current point
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // in the code.
a61af66fc99e Initial load
duke
parents:
diff changeset
692 void flow_successors(GrowableArray<Block*>* successors,
a61af66fc99e Initial load
duke
parents:
diff changeset
693 StateVector* state);
a61af66fc99e Initial load
duke
parents:
diff changeset
694
a61af66fc99e Initial load
duke
parents:
diff changeset
695 // Interpret the effects of the bytecodes on the incoming state
a61af66fc99e Initial load
duke
parents:
diff changeset
696 // vector of a basic block. Push the changed state to succeeding
a61af66fc99e Initial load
duke
parents:
diff changeset
697 // basic blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
698 void flow_block(Block* block,
a61af66fc99e Initial load
duke
parents:
diff changeset
699 StateVector* scratch_state,
a61af66fc99e Initial load
duke
parents:
diff changeset
700 JsrSet* scratch_jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
701
a61af66fc99e Initial load
duke
parents:
diff changeset
702 // Perform the type flow analysis, creating and cloning Blocks as
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
704 void flow_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 // Create the block map, which indexes blocks in pre_order.
a61af66fc99e Initial load
duke
parents:
diff changeset
707 void map_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
710 // Perform type inference flow analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
711 void do_flow();
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 void print_on(outputStream* st) const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
714 };