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

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 194b8e3a2fc4
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-2007 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/_ciTypeFlow.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // ciTypeFlow::JsrSet
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // A JsrSet represents some set of JsrRecords. This class
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // is used to record a set of all jsr routines which we permit
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // execution to return (ret) from.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // During abstract interpretation, JsrSets are used to determine
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // whether two paths which reach a given block are unique, and
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // should be cloned apart, or are compatible, and should merge
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // together.
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // ciTypeFlow::JsrSet::JsrSet
a61af66fc99e Initial load
duke
parents:
diff changeset
41 ciTypeFlow::JsrSet::JsrSet(Arena* arena, int default_len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 if (arena != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Allocate growable array in Arena.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _set = new (arena) GrowableArray<JsrRecord*>(arena, default_len, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Allocate growable array in current ResourceArea.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _set = new GrowableArray<JsrRecord*>(4, 0, NULL, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // ciTypeFlow::JsrSet::copy_into
a61af66fc99e Initial load
duke
parents:
diff changeset
53 void ciTypeFlow::JsrSet::copy_into(JsrSet* jsrs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 int len = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 jsrs->_set->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 jsrs->_set->append(_set->at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // ciTypeFlow::JsrSet::is_compatible_with
a61af66fc99e Initial load
duke
parents:
diff changeset
63 //
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // !!!! MISGIVINGS ABOUT THIS... disregard
a61af66fc99e Initial load
duke
parents:
diff changeset
65 //
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // Is this JsrSet compatible with some other JsrSet?
a61af66fc99e Initial load
duke
parents:
diff changeset
67 //
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // In set-theoretic terms, a JsrSet can be viewed as a partial function
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // from entry addresses to return addresses. Two JsrSets A and B are
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // compatible iff
a61af66fc99e Initial load
duke
parents:
diff changeset
71 //
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // For any x,
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // A(x) defined and B(x) defined implies A(x) == B(x)
a61af66fc99e Initial load
duke
parents:
diff changeset
74 //
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Less formally, two JsrSets are compatible when they have identical
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // return addresses for any entry addresses they share in common.
a61af66fc99e Initial load
duke
parents:
diff changeset
77 bool ciTypeFlow::JsrSet::is_compatible_with(JsrSet* other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Walk through both sets in parallel. If the same entry address
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // appears in both sets, then the return address must match for
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // the sets to be compatible.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int size1 = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 int size2 = other->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Special case. If nothing is on the jsr stack, then there can
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // be no ret.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (size2 == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else if (size1 != size2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 for (int i = 0; i < size1; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 JsrRecord* record1 = record_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 JsrRecord* record2 = other->record_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (record1->entry_address() != record2->entry_address() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
95 record1->return_address() != record2->return_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 int pos1 = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 int pos2 = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int size1 = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int size2 = other->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 while (pos1 < size1 && pos2 < size2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 JsrRecord* record1 = record_at(pos1);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 JsrRecord* record2 = other->record_at(pos2);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int entry1 = record1->entry_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int entry2 = record2->entry_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (entry1 < entry2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 pos1++;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 } else if (entry1 > entry2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 pos2++;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (record1->return_address() == record2->return_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 pos1++;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 pos2++;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // These two JsrSets are incompatible.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // The two JsrSets agree.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // ciTypeFlow::JsrSet::insert_jsr_record
a61af66fc99e Initial load
duke
parents:
diff changeset
133 //
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Insert the given JsrRecord into the JsrSet, maintaining the order
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // of the set and replacing any element with the same entry address.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void ciTypeFlow::JsrSet::insert_jsr_record(JsrRecord* record) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int len = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 int entry = record->entry_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int pos = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 for ( ; pos < len; pos++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 JsrRecord* current = record_at(pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (entry == current->entry_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Stomp over this entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _set->at_put(pos, record);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 assert(size() == len, "must be same size");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 } else if (entry < current->entry_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Insert the record into the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
153 JsrRecord* swap = record;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 JsrRecord* temp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 for ( ; pos < len; pos++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 temp = _set->at(pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 _set->at_put(pos, swap);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 swap = temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _set->append(swap);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 assert(size() == len+1, "must be larger");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // ciTypeFlow::JsrSet::remove_jsr_record
a61af66fc99e Initial load
duke
parents:
diff changeset
166 //
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Remove the JsrRecord with the given return address from the JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
168 void ciTypeFlow::JsrSet::remove_jsr_record(int return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 int len = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (record_at(i)->return_address() == return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // We have found the proper entry. Remove it from the
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // JsrSet and exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 for (int j = i+1; j < len ; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _set->at_put(j-1, _set->at(j));
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _set->trunc_to(len-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(size() == len-1, "must be smaller");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 assert(false, "verify: returning from invalid subroutine");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // ciTypeFlow::JsrSet::apply_control
a61af66fc99e Initial load
duke
parents:
diff changeset
187 //
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // Apply the effect of a control-flow bytecode on the JsrSet. The
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // only bytecodes that modify the JsrSet are jsr and ret.
a61af66fc99e Initial load
duke
parents:
diff changeset
190 void ciTypeFlow::JsrSet::apply_control(ciTypeFlow* analyzer,
a61af66fc99e Initial load
duke
parents:
diff changeset
191 ciBytecodeStream* str,
a61af66fc99e Initial load
duke
parents:
diff changeset
192 ciTypeFlow::StateVector* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 Bytecodes::Code code = str->cur_bc();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (code == Bytecodes::_jsr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 JsrRecord* record =
a61af66fc99e Initial load
duke
parents:
diff changeset
196 analyzer->make_jsr_record(str->get_dest(), str->next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
197 insert_jsr_record(record);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } else if (code == Bytecodes::_jsr_w) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 JsrRecord* record =
a61af66fc99e Initial load
duke
parents:
diff changeset
200 analyzer->make_jsr_record(str->get_far_dest(), str->next_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
201 insert_jsr_record(record);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 } else if (code == Bytecodes::_ret) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 Cell local = state->local(str->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
204 ciType* return_address = state->type_at(local);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 assert(return_address->is_return_address(), "verify: wrong type");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // Ret-state underflow: Hit a ret w/o any previous jsrs. Bail out.
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // This can happen when a loop is inside a finally clause (4614060).
a61af66fc99e Initial load
duke
parents:
diff changeset
209 analyzer->record_failure("OSR in finally clause");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 remove_jsr_record(return_address->as_return_address()->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // ciTypeFlow::JsrSet::print_on
a61af66fc99e Initial load
duke
parents:
diff changeset
219 void ciTypeFlow::JsrSet::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 st->print("{ ");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 int num_elements = size();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (num_elements > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 for( ; i < num_elements - 1; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 _set->at(i)->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 st->print(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 _set->at(i)->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 st->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 st->print("}");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // ciTypeFlow::StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
236 //
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // A StateVector summarizes the type information at some point in
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // the program.
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // ciTypeFlow::StateVector::type_meet
a61af66fc99e Initial load
duke
parents:
diff changeset
242 //
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // Meet two types.
a61af66fc99e Initial load
duke
parents:
diff changeset
244 //
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // The semi-lattice of types use by this analysis are modeled on those
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // of the verifier. The lattice is as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
247 //
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // top_type() >= all non-extremal types >= bottom_type
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // and
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Every primitive type is comparable only with itself. The meet of
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // reference types is determined by their kind: instance class,
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // interface, or array class. The meet of two types of the same
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // kind is their least common ancestor. The meet of two types of
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // different kinds is always java.lang.Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 assert(t1 != t2, "checked in caller");
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (t1->equals(top_type())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return t2;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 } else if (t2->equals(top_type())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // Special case null_type. null_type meet any reference type T
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // is T. null_type meet null_type is null_type.
a61af66fc99e Initial load
duke
parents:
diff changeset
264 if (t1->equals(null_type())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!t2->is_primitive_type() || t2->equals(null_type())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return t2;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 } else if (t2->equals(null_type())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if (!t1->is_primitive_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // At least one of the two types is a non-top primitive type.
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // The other type is not equal to it. Fall to bottom.
a61af66fc99e Initial load
duke
parents:
diff changeset
276 return bottom_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Both types are non-top non-primitive types. That is,
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // both types are either instanceKlasses or arrayKlasses.
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ciKlass* object_klass = analyzer->env()->Object_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 ciKlass* k1 = t1->as_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 ciKlass* k2 = t2->as_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
283 if (k1->equals(object_klass) || k2->equals(object_klass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return object_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 } else if (!k1->is_loaded() || !k2->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // Unloaded classes fall to java.lang.Object at a merge.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 return object_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 } else if (k1->is_interface() != k2->is_interface()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // When an interface meets a non-interface, we get Object;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // This is what the verifier does.
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return object_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 } else if (k1->is_array_klass() || k2->is_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // When an array meets a non-array, we get Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // When objArray meets typeArray, we also get Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // And when typeArray meets different typeArray, we again get Object.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // But when objArray meets objArray, we look carefully at element types.
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // Meet the element types, then construct the corresponding array type.
a61af66fc99e Initial load
duke
parents:
diff changeset
299 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // Do an easy shortcut if one type is a super of the other.
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (elem == elem1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return k1;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 } else if (elem == elem2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return k2;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return ciObjArrayKlass::make(elem);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return object_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 // Must be two plain old instance klasses.
a61af66fc99e Initial load
duke
parents:
diff changeset
317 assert(k1->is_instance_klass(), "previous cases handle non-instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
318 assert(k2->is_instance_klass(), "previous cases handle non-instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return k1->least_common_ancestor(k2);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // ciTypeFlow::StateVector::StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
327 //
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // Build a new state vector
a61af66fc99e Initial load
duke
parents:
diff changeset
329 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 _outer = analyzer;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 _stack_size = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 _monitor_count = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Allocate the _types array
a61af66fc99e Initial load
duke
parents:
diff changeset
334 int max_cells = analyzer->max_cells();
a61af66fc99e Initial load
duke
parents:
diff changeset
335 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 for (int i=0; i<max_cells; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 _types[i] = top_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 _trap_bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 _trap_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // ciTypeFlow::get_start_state
a61af66fc99e Initial load
duke
parents:
diff changeset
345 //
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // Set this vector to the method entry state.
a61af66fc99e Initial load
duke
parents:
diff changeset
347 const ciTypeFlow::StateVector* ciTypeFlow::get_start_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 StateVector* state = new StateVector(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (is_osr_flow()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 ciTypeFlow* non_osr_flow = method()->get_flow_analysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (non_osr_flow->failing()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 record_failure(non_osr_flow->failure_reason());
a61af66fc99e Initial load
duke
parents:
diff changeset
353 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 JsrSet* jsrs = new JsrSet(NULL, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 Block* non_osr_block = non_osr_flow->existing_block_at(start_bci(), jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (non_osr_block == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 record_failure("cannot reach OSR point");
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // load up the non-OSR state at this point
a61af66fc99e Initial load
duke
parents:
diff changeset
362 non_osr_block->copy_state_into(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 int non_osr_start = non_osr_block->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 if (non_osr_start != start_bci()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // must flow forward from it
a61af66fc99e Initial load
duke
parents:
diff changeset
366 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369 Block* block = block_at(non_osr_start, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 assert(block->limit() == start_bci(), "must flow forward to start");
a61af66fc99e Initial load
duke
parents:
diff changeset
371 flow_block(block, state, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return state;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // Note: The code below would be an incorrect for an OSR flow,
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // even if it were possible for an OSR entry point to be at bci zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // "Push" the method signature into the first few locals.
a61af66fc99e Initial load
duke
parents:
diff changeset
378 state->set_stack_size(-max_locals());
a61af66fc99e Initial load
duke
parents:
diff changeset
379 if (!method()->is_static()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 state->push(method()->holder());
a61af66fc99e Initial load
duke
parents:
diff changeset
381 assert(state->tos() == state->local(0), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 for (ciSignatureStream str(method()->signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
384 !str.at_return_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 str.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 state->push_translate(str.type());
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // Set the rest of the locals to bottom.
a61af66fc99e Initial load
duke
parents:
diff changeset
389 Cell cell = state->next_cell(state->tos());
a61af66fc99e Initial load
duke
parents:
diff changeset
390 state->set_stack_size(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 int limit = state->limit_cell();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 for (; cell < limit; cell = state->next_cell(cell)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 state->set_type_at(cell, state->bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // Lock an object, if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
396 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 return state;
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // ciTypeFlow::StateVector::copy_into
a61af66fc99e Initial load
duke
parents:
diff changeset
402 //
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // Copy our value into some other StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
404 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
a61af66fc99e Initial load
duke
parents:
diff changeset
405 const {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 copy->set_stack_size(stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
407 copy->set_monitor_count(monitor_count());
a61af66fc99e Initial load
duke
parents:
diff changeset
408 Cell limit = limit_cell();
a61af66fc99e Initial load
duke
parents:
diff changeset
409 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 copy->set_type_at(c, type_at(c));
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // ciTypeFlow::StateVector::meet
a61af66fc99e Initial load
duke
parents:
diff changeset
416 //
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Meets this StateVector with another, destructively modifying this
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // one. Returns true if any modification takes place.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 bool ciTypeFlow::StateVector::meet(const ciTypeFlow::StateVector* incoming) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 if (monitor_count() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 set_monitor_count(incoming->monitor_count());
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
423 assert(monitor_count() == incoming->monitor_count(), "monitors must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 if (stack_size() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 set_stack_size(incoming->stack_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
427 Cell limit = limit_cell();
a61af66fc99e Initial load
duke
parents:
diff changeset
428 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
429 { for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 assert(type_at(c) == top_type(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
431 } }
a61af66fc99e Initial load
duke
parents:
diff changeset
432 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // Make a simple copy of the incoming state.
a61af66fc99e Initial load
duke
parents:
diff changeset
434 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 set_type_at(c, incoming->type_at(c));
a61af66fc99e Initial load
duke
parents:
diff changeset
436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
437 return true; // it is always different the first time
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
439 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
440 if (stack_size() != incoming->stack_size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 _outer->method()->print_codes();
a61af66fc99e Initial load
duke
parents:
diff changeset
442 tty->print_cr("!!!! Stack size conflict");
a61af66fc99e Initial load
duke
parents:
diff changeset
443 tty->print_cr("Current state:");
a61af66fc99e Initial load
duke
parents:
diff changeset
444 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
445 tty->print_cr("Incoming state:");
a61af66fc99e Initial load
duke
parents:
diff changeset
446 ((StateVector*)incoming)->print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
449 assert(stack_size() == incoming->stack_size(), "sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 bool different = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 Cell limit = limit_cell();
a61af66fc99e Initial load
duke
parents:
diff changeset
453 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 ciType* t1 = type_at(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 ciType* t2 = incoming->type_at(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 if (!t1->equals(t2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 ciType* new_type = type_meet(t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (!t1->equals(new_type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 set_type_at(c, new_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
460 different = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464 return different;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // ciTypeFlow::StateVector::meet_exception
a61af66fc99e Initial load
duke
parents:
diff changeset
469 //
a61af66fc99e Initial load
duke
parents:
diff changeset
470 // Meets this StateVector with another, destructively modifying this
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // one. The incoming state is coming via an exception. Returns true
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // if any modification takes place.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 bool ciTypeFlow::StateVector::meet_exception(ciInstanceKlass* exc,
a61af66fc99e Initial load
duke
parents:
diff changeset
474 const ciTypeFlow::StateVector* incoming) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if (monitor_count() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 set_monitor_count(incoming->monitor_count());
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 assert(monitor_count() == incoming->monitor_count(), "monitors must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 if (stack_size() == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
481 set_stack_size(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 assert(stack_size() == 1, "must have one-element stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 bool different = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
487
a61af66fc99e Initial load
duke
parents:
diff changeset
488 // Meet locals from incoming array.
a61af66fc99e Initial load
duke
parents:
diff changeset
489 Cell limit = local(_outer->max_locals()-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
490 for (Cell c = start_cell(); c <= limit; c = next_cell(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 ciType* t1 = type_at(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
492 ciType* t2 = incoming->type_at(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
493 if (!t1->equals(t2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
494 ciType* new_type = type_meet(t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (!t1->equals(new_type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 set_type_at(c, new_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
497 different = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // Handle stack separately. When an exception occurs, the
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // only stack entry is the exception instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
504 ciType* tos_type = type_at_tos();
a61af66fc99e Initial load
duke
parents:
diff changeset
505 if (!tos_type->equals(exc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
506 ciType* new_type = type_meet(tos_type, exc);
a61af66fc99e Initial load
duke
parents:
diff changeset
507 if (!tos_type->equals(new_type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 set_type_at_tos(new_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
509 different = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
510 }
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513 return different;
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
517 // ciTypeFlow::StateVector::push_translate
a61af66fc99e Initial load
duke
parents:
diff changeset
518 void ciTypeFlow::StateVector::push_translate(ciType* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 BasicType basic_type = type->basic_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
a61af66fc99e Initial load
duke
parents:
diff changeset
521 basic_type == T_BYTE || basic_type == T_SHORT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
523 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 push(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
525 if (type->is_two_word()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
526 push(half_type(type));
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528 }
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
532 // ciTypeFlow::StateVector::do_aaload
a61af66fc99e Initial load
duke
parents:
diff changeset
533 void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
535 ciObjArrayKlass* array_klass = pop_objArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (array_klass == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // Did aaload on a null reference; push a null and ignore the exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // This instruction will never continue normally. All we have to do
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // is report a value that will meet correctly with any downstream
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // reference types on paths that will truly be executed. This null type
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // meets with any reference type to yield that same reference type.
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // (The compiler will generate an unconditonal exception here.)
a61af66fc99e Initial load
duke
parents:
diff changeset
543 push(null_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
544 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if (!array_klass->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // Only fails for some -Xcomp runs
a61af66fc99e Initial load
duke
parents:
diff changeset
548 trap(str, array_klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
549 Deoptimization::make_trap_request
a61af66fc99e Initial load
duke
parents:
diff changeset
550 (Deoptimization::Reason_unloaded,
a61af66fc99e Initial load
duke
parents:
diff changeset
551 Deoptimization::Action_reinterpret));
a61af66fc99e Initial load
duke
parents:
diff changeset
552 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 ciKlass* element_klass = array_klass->element_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
555 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 Untested("unloaded array element class in ciTypeFlow");
a61af66fc99e Initial load
duke
parents:
diff changeset
557 trap(str, element_klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
558 Deoptimization::make_trap_request
a61af66fc99e Initial load
duke
parents:
diff changeset
559 (Deoptimization::Reason_unloaded,
a61af66fc99e Initial load
duke
parents:
diff changeset
560 Deoptimization::Action_reinterpret));
a61af66fc99e Initial load
duke
parents:
diff changeset
561 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 push_object(element_klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // ciTypeFlow::StateVector::do_checkcast
a61af66fc99e Initial load
duke
parents:
diff changeset
569 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
570 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 ciKlass* klass = str->get_klass(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
572 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // VM's interpreter will not load 'klass' if object is NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // Type flow after this block may still be needed in two situations:
a61af66fc99e Initial load
duke
parents:
diff changeset
575 // 1) C2 uses do_null_assert() and continues compilation for later blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
576 // 2) C2 does an OSR compile in a later block (see bug 4778368).
a61af66fc99e Initial load
duke
parents:
diff changeset
577 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
578 do_null_assert(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
579 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
581 push_object(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // ciTypeFlow::StateVector::do_getfield
a61af66fc99e Initial load
duke
parents:
diff changeset
587 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 // could add assert here for type of object.
a61af66fc99e Initial load
duke
parents:
diff changeset
589 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
590 do_getstatic(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
594 // ciTypeFlow::StateVector::do_getstatic
a61af66fc99e Initial load
duke
parents:
diff changeset
595 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
597 ciField* field = str->get_field(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 trap(str, field->holder(), str->get_field_holder_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
600 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
601 ciType* field_type = field->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
602 if (!field_type->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // Normally, we need the field's type to be loaded if we are to
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // do anything interesting with its value.
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // We used to do this: trap(str, str->get_field_signature_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
606 //
a61af66fc99e Initial load
duke
parents:
diff changeset
607 // There is one good reason not to trap here. Execution can
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // get past this "getfield" or "getstatic" if the value of
a61af66fc99e Initial load
duke
parents:
diff changeset
609 // the field is null. As long as the value is null, the class
a61af66fc99e Initial load
duke
parents:
diff changeset
610 // does not need to be loaded! The compiler must assume that
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // the value of the unloaded class reference is null; if the code
a61af66fc99e Initial load
duke
parents:
diff changeset
612 // ever sees a non-null value, loading has occurred.
a61af66fc99e Initial load
duke
parents:
diff changeset
613 //
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // This actually happens often enough to be annoying. If the
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // compiler throws an uncommon trap at this bytecode, you can
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // get an endless loop of recompilations, when all the code
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // needs to do is load a series of null values. Also, a trap
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // here can make an OSR entry point unreachable, triggering the
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // assert on non_osr_block in ciTypeFlow::get_start_state.
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // (See bug 4379915.)
a61af66fc99e Initial load
duke
parents:
diff changeset
621 do_null_assert(field_type->as_klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
622 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 push_translate(field_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // ciTypeFlow::StateVector::do_invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
630 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
a61af66fc99e Initial load
duke
parents:
diff changeset
631 bool has_receiver) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
633 ciMethod* method = str->get_method(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
634 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // We weren't able to find the method.
a61af66fc99e Initial load
duke
parents:
diff changeset
636 ciKlass* unloaded_holder = method->holder();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 trap(str, unloaded_holder, str->get_method_holder_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
638 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
639 ciSignature* signature = method->signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
640 ciSignatureStream sigstr(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 int arg_size = signature->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
642 int stack_base = stack_size() - arg_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
644 for( ; !sigstr.at_return_type(); sigstr.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 ciType* type = sigstr.type();
a61af66fc99e Initial load
duke
parents:
diff changeset
646 ciType* stack_type = type_at(stack(stack_base + i++));
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // Do I want to check this type?
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // assert(stack_type->is_subtype_of(type), "bad type for field value");
a61af66fc99e Initial load
duke
parents:
diff changeset
649 if (type->is_two_word()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 ciType* stack_type2 = type_at(stack(stack_base + i++));
a61af66fc99e Initial load
duke
parents:
diff changeset
651 assert(stack_type2->equals(half_type(type)), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 }
a61af66fc99e Initial load
duke
parents:
diff changeset
654 assert(arg_size == i, "must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
655 for (int j = 0; j < arg_size; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
656 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if (has_receiver) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // Check this?
a61af66fc99e Initial load
duke
parents:
diff changeset
660 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662 assert(!sigstr.is_done(), "must have return type");
a61af66fc99e Initial load
duke
parents:
diff changeset
663 ciType* return_type = sigstr.type();
a61af66fc99e Initial load
duke
parents:
diff changeset
664 if (!return_type->is_void()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 if (!return_type->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 // As in do_getstatic(), generally speaking, we need the return type to
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // be loaded if we are to do anything interesting with its value.
a61af66fc99e Initial load
duke
parents:
diff changeset
668 // We used to do this: trap(str, str->get_method_signature_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
669 //
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // We do not trap here since execution can get past this invoke if
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // the return value is null. As long as the value is null, the class
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // does not need to be loaded! The compiler must assume that
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // the value of the unloaded class reference is null; if the code
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // ever sees a non-null value, loading has occurred.
a61af66fc99e Initial load
duke
parents:
diff changeset
675 //
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // See do_getstatic() for similar explanation, as well as bug 4684993.
a61af66fc99e Initial load
duke
parents:
diff changeset
677 do_null_assert(return_type->as_klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
678 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
679 push_translate(return_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 }
a61af66fc99e Initial load
duke
parents:
diff changeset
681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // ciTypeFlow::StateVector::do_jsr
a61af66fc99e Initial load
duke
parents:
diff changeset
687 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 push(ciReturnAddress::make(str->next_bci()));
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
692 // ciTypeFlow::StateVector::do_ldc
a61af66fc99e Initial load
duke
parents:
diff changeset
693 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
694 ciConstant con = str->get_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
695 BasicType basic_type = con.basic_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
696 if (basic_type == T_ILLEGAL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 // OutOfMemoryError in the CI while loading constant
a61af66fc99e Initial load
duke
parents:
diff changeset
698 push_null();
a61af66fc99e Initial load
duke
parents:
diff changeset
699 outer()->record_failure("ldc did not link");
a61af66fc99e Initial load
duke
parents:
diff changeset
700 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (basic_type == T_OBJECT || basic_type == T_ARRAY) {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 ciObject* obj = con.as_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
704 if (obj->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 push_null();
a61af66fc99e Initial load
duke
parents:
diff changeset
706 } else if (obj->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 // The type of ldc <class> is java.lang.Class
a61af66fc99e Initial load
duke
parents:
diff changeset
708 push_object(outer()->env()->Class_klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
709 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 push_object(obj->klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
712 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 push_translate(ciType::make(basic_type));
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
718 // ciTypeFlow::StateVector::do_multianewarray
a61af66fc99e Initial load
duke
parents:
diff changeset
719 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 int dimensions = str->get_dimensions();
a61af66fc99e Initial load
duke
parents:
diff changeset
721 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
722 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
723 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
724 trap(str, array_klass, str->get_klass_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
725 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 for (int i = 0; i < dimensions; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
729 push_object(array_klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732
a61af66fc99e Initial load
duke
parents:
diff changeset
733 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // ciTypeFlow::StateVector::do_new
a61af66fc99e Initial load
duke
parents:
diff changeset
735 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
737 ciKlass* klass = str->get_klass(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
738 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
739 trap(str, klass, str->get_klass_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
740 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
741 push_object(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
746 // ciTypeFlow::StateVector::do_newarray
a61af66fc99e Initial load
duke
parents:
diff changeset
747 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
748 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
749 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
750 push_object(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // ciTypeFlow::StateVector::do_putfield
a61af66fc99e Initial load
duke
parents:
diff changeset
755 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
756 do_putstatic(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
757 if (_trap_bci != -1) return; // unloaded field holder, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // could add assert here for type of object.
a61af66fc99e Initial load
duke
parents:
diff changeset
759 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
760 }
a61af66fc99e Initial load
duke
parents:
diff changeset
761
a61af66fc99e Initial load
duke
parents:
diff changeset
762 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
763 // ciTypeFlow::StateVector::do_putstatic
a61af66fc99e Initial load
duke
parents:
diff changeset
764 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
765 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
766 ciField* field = str->get_field(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
767 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 trap(str, field->holder(), str->get_field_holder_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
769 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
770 ciType* field_type = field->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
771 ciType* type = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // Do I want to check this type?
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // assert(type->is_subtype_of(field_type), "bad type for field value");
a61af66fc99e Initial load
duke
parents:
diff changeset
774 if (field_type->is_two_word()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
775 ciType* type2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
776 assert(type2->is_two_word(), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
777 assert(type == half_type(type2), "must be 2nd half");
a61af66fc99e Initial load
duke
parents:
diff changeset
778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // ciTypeFlow::StateVector::do_ret
a61af66fc99e Initial load
duke
parents:
diff changeset
784 void ciTypeFlow::StateVector::do_ret(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 Cell index = local(str->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787 ciType* address = type_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
788 assert(address->is_return_address(), "bad return address");
a61af66fc99e Initial load
duke
parents:
diff changeset
789 set_type_at(index, bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
791
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
793 // ciTypeFlow::StateVector::trap
a61af66fc99e Initial load
duke
parents:
diff changeset
794 //
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // Stop interpretation of this path with a trap.
a61af66fc99e Initial load
duke
parents:
diff changeset
796 void ciTypeFlow::StateVector::trap(ciBytecodeStream* str, ciKlass* klass, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 _trap_bci = str->cur_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
798 _trap_index = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
799
a61af66fc99e Initial load
duke
parents:
diff changeset
800 // Log information about this trap:
a61af66fc99e Initial load
duke
parents:
diff changeset
801 CompileLog* log = outer()->env()->log();
a61af66fc99e Initial load
duke
parents:
diff changeset
802 if (log != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 int mid = log->identify(outer()->method());
a61af66fc99e Initial load
duke
parents:
diff changeset
804 int kid = (klass == NULL)? -1: log->identify(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 log->begin_elem("uncommon_trap method='%d' bci='%d'", mid, str->cur_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
806 char buf[100];
a61af66fc99e Initial load
duke
parents:
diff changeset
807 log->print(" %s", Deoptimization::format_trap_request(buf, sizeof(buf),
a61af66fc99e Initial load
duke
parents:
diff changeset
808 index));
a61af66fc99e Initial load
duke
parents:
diff changeset
809 if (kid >= 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
810 log->print(" klass='%d'", kid);
a61af66fc99e Initial load
duke
parents:
diff changeset
811 log->end_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
812 }
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814
a61af66fc99e Initial load
duke
parents:
diff changeset
815 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
816 // ciTypeFlow::StateVector::do_null_assert
a61af66fc99e Initial load
duke
parents:
diff changeset
817 // Corresponds to graphKit::do_null_assert.
a61af66fc99e Initial load
duke
parents:
diff changeset
818 void ciTypeFlow::StateVector::do_null_assert(ciKlass* unloaded_klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
819 if (unloaded_klass->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
820 // We failed to link, but we can still compute with this class,
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // since it is loaded somewhere. The compiler will uncommon_trap
a61af66fc99e Initial load
duke
parents:
diff changeset
822 // if the object is not null, but the typeflow pass can not assume
a61af66fc99e Initial load
duke
parents:
diff changeset
823 // that the object will be null, otherwise it may incorrectly tell
a61af66fc99e Initial load
duke
parents:
diff changeset
824 // the parser that an object is known to be null. 4761344, 4807707
a61af66fc99e Initial load
duke
parents:
diff changeset
825 push_object(unloaded_klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
826 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
827 // The class is not loaded anywhere. It is safe to model the
a61af66fc99e Initial load
duke
parents:
diff changeset
828 // null in the typestates, because we can compile in a null check
a61af66fc99e Initial load
duke
parents:
diff changeset
829 // which will deoptimize us if someone manages to load the
a61af66fc99e Initial load
duke
parents:
diff changeset
830 // class later.
a61af66fc99e Initial load
duke
parents:
diff changeset
831 push_null();
a61af66fc99e Initial load
duke
parents:
diff changeset
832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
837 // ciTypeFlow::StateVector::apply_one_bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
838 //
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // Apply the effect of one bytecode to this StateVector
a61af66fc99e Initial load
duke
parents:
diff changeset
840 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
841 _trap_bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
842 _trap_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
843
a61af66fc99e Initial load
duke
parents:
diff changeset
844 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
a61af66fc99e Initial load
duke
parents:
diff changeset
846 Bytecodes::name(str->cur_bc()));
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848
a61af66fc99e Initial load
duke
parents:
diff changeset
849 switch(str->cur_bc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 case Bytecodes::_aaload: do_aaload(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 case Bytecodes::_aastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
853 {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
855 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
856 pop_objArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
857 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
858 }
a61af66fc99e Initial load
duke
parents:
diff changeset
859 case Bytecodes::_aconst_null:
a61af66fc99e Initial load
duke
parents:
diff changeset
860 {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 push_null();
a61af66fc99e Initial load
duke
parents:
diff changeset
862 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864 case Bytecodes::_aload: load_local_object(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
865 case Bytecodes::_aload_0: load_local_object(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
866 case Bytecodes::_aload_1: load_local_object(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
867 case Bytecodes::_aload_2: load_local_object(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
868 case Bytecodes::_aload_3: load_local_object(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
869
a61af66fc99e Initial load
duke
parents:
diff changeset
870 case Bytecodes::_anewarray:
a61af66fc99e Initial load
duke
parents:
diff changeset
871 {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
873 bool will_link;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 ciKlass* element_klass = str->get_klass(will_link);
a61af66fc99e Initial load
duke
parents:
diff changeset
875 if (!will_link) {
a61af66fc99e Initial load
duke
parents:
diff changeset
876 trap(str, element_klass, str->get_klass_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
877 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 push_object(ciObjArrayKlass::make(element_klass));
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
883 case Bytecodes::_ifnonnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
884 case Bytecodes::_ifnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
885 {
a61af66fc99e Initial load
duke
parents:
diff changeset
886 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
887 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
888 }
a61af66fc99e Initial load
duke
parents:
diff changeset
889 case Bytecodes::_monitorenter:
a61af66fc99e Initial load
duke
parents:
diff changeset
890 {
a61af66fc99e Initial load
duke
parents:
diff changeset
891 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
892 set_monitor_count(monitor_count() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
893 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895 case Bytecodes::_monitorexit:
a61af66fc99e Initial load
duke
parents:
diff changeset
896 {
a61af66fc99e Initial load
duke
parents:
diff changeset
897 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
898 assert(monitor_count() > 0, "must be a monitor to exit from");
a61af66fc99e Initial load
duke
parents:
diff changeset
899 set_monitor_count(monitor_count() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
900 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902 case Bytecodes::_arraylength:
a61af66fc99e Initial load
duke
parents:
diff changeset
903 {
a61af66fc99e Initial load
duke
parents:
diff changeset
904 pop_array();
a61af66fc99e Initial load
duke
parents:
diff changeset
905 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
906 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
908 case Bytecodes::_astore: store_local_object(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
909 case Bytecodes::_astore_0: store_local_object(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
910 case Bytecodes::_astore_1: store_local_object(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
911 case Bytecodes::_astore_2: store_local_object(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
912 case Bytecodes::_astore_3: store_local_object(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 case Bytecodes::_athrow:
a61af66fc99e Initial load
duke
parents:
diff changeset
915 {
a61af66fc99e Initial load
duke
parents:
diff changeset
916 NEEDS_CLEANUP;
a61af66fc99e Initial load
duke
parents:
diff changeset
917 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
918 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
920 case Bytecodes::_baload:
a61af66fc99e Initial load
duke
parents:
diff changeset
921 case Bytecodes::_caload:
a61af66fc99e Initial load
duke
parents:
diff changeset
922 case Bytecodes::_iaload:
a61af66fc99e Initial load
duke
parents:
diff changeset
923 case Bytecodes::_saload:
a61af66fc99e Initial load
duke
parents:
diff changeset
924 {
a61af66fc99e Initial load
duke
parents:
diff changeset
925 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
926 ciTypeArrayKlass* array_klass = pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
927 // Put assert here for right type?
a61af66fc99e Initial load
duke
parents:
diff changeset
928 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
929 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
931 case Bytecodes::_bastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
932 case Bytecodes::_castore:
a61af66fc99e Initial load
duke
parents:
diff changeset
933 case Bytecodes::_iastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
934 case Bytecodes::_sastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
935 {
a61af66fc99e Initial load
duke
parents:
diff changeset
936 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
937 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
938 pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
939 // assert here?
a61af66fc99e Initial load
duke
parents:
diff changeset
940 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942 case Bytecodes::_bipush:
a61af66fc99e Initial load
duke
parents:
diff changeset
943 case Bytecodes::_iconst_m1:
a61af66fc99e Initial load
duke
parents:
diff changeset
944 case Bytecodes::_iconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
945 case Bytecodes::_iconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
946 case Bytecodes::_iconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
947 case Bytecodes::_iconst_3:
a61af66fc99e Initial load
duke
parents:
diff changeset
948 case Bytecodes::_iconst_4:
a61af66fc99e Initial load
duke
parents:
diff changeset
949 case Bytecodes::_iconst_5:
a61af66fc99e Initial load
duke
parents:
diff changeset
950 case Bytecodes::_sipush:
a61af66fc99e Initial load
duke
parents:
diff changeset
951 {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
953 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
954 }
a61af66fc99e Initial load
duke
parents:
diff changeset
955 case Bytecodes::_checkcast: do_checkcast(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
956
a61af66fc99e Initial load
duke
parents:
diff changeset
957 case Bytecodes::_d2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
958 {
a61af66fc99e Initial load
duke
parents:
diff changeset
959 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
960 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
961 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963 case Bytecodes::_d2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
964 {
a61af66fc99e Initial load
duke
parents:
diff changeset
965 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
966 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
967 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
969 case Bytecodes::_d2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
970 {
a61af66fc99e Initial load
duke
parents:
diff changeset
971 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
972 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
973 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
974 }
a61af66fc99e Initial load
duke
parents:
diff changeset
975 case Bytecodes::_dadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
976 case Bytecodes::_ddiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
977 case Bytecodes::_dmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
978 case Bytecodes::_drem:
a61af66fc99e Initial load
duke
parents:
diff changeset
979 case Bytecodes::_dsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
980 {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
982 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
983 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
984 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
986 case Bytecodes::_daload:
a61af66fc99e Initial load
duke
parents:
diff changeset
987 {
a61af66fc99e Initial load
duke
parents:
diff changeset
988 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
989 ciTypeArrayKlass* array_klass = pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
990 // Put assert here for right type?
a61af66fc99e Initial load
duke
parents:
diff changeset
991 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
992 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
993 }
a61af66fc99e Initial load
duke
parents:
diff changeset
994 case Bytecodes::_dastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
995 {
a61af66fc99e Initial load
duke
parents:
diff changeset
996 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
997 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
998 pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
999 // assert here?
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 case Bytecodes::_dcmpg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 case Bytecodes::_dcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 case Bytecodes::_dconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 case Bytecodes::_dconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 case Bytecodes::_dload: load_local_double(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 case Bytecodes::_dload_0: load_local_double(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 case Bytecodes::_dload_1: load_local_double(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 case Bytecodes::_dload_2: load_local_double(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 case Bytecodes::_dload_3: load_local_double(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 case Bytecodes::_dneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 pop_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 case Bytecodes::_dstore: store_local_double(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 case Bytecodes::_dstore_0: store_local_double(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 case Bytecodes::_dstore_1: store_local_double(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 case Bytecodes::_dstore_2: store_local_double(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 case Bytecodes::_dstore_3: store_local_double(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1038
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 case Bytecodes::_dup:
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 push(type_at_tos());
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 case Bytecodes::_dup_x1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 case Bytecodes::_dup_x2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 ciType* value3 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 push(value3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 case Bytecodes::_dup2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 case Bytecodes::_dup2_x1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 ciType* value3 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 push(value3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 case Bytecodes::_dup2_x2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 ciType* value3 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 ciType* value4 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 push(value4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 push(value3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 case Bytecodes::_f2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 case Bytecodes::_f2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 case Bytecodes::_f2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 case Bytecodes::_fadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 case Bytecodes::_fdiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 case Bytecodes::_fmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 case Bytecodes::_frem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 case Bytecodes::_fsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 case Bytecodes::_faload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 ciTypeArrayKlass* array_klass = pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 // Put assert here.
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 case Bytecodes::_fastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 ciTypeArrayKlass* array_klass = pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 // Put assert here.
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 case Bytecodes::_fcmpg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 case Bytecodes::_fcmpl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 case Bytecodes::_fconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 case Bytecodes::_fconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 case Bytecodes::_fconst_2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 case Bytecodes::_fload: load_local_float(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 case Bytecodes::_fload_0: load_local_float(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 case Bytecodes::_fload_1: load_local_float(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 case Bytecodes::_fload_2: load_local_float(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 case Bytecodes::_fload_3: load_local_float(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1165
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 case Bytecodes::_fneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 pop_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 case Bytecodes::_fstore: store_local_float(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 case Bytecodes::_fstore_0: store_local_float(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 case Bytecodes::_fstore_1: store_local_float(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 case Bytecodes::_fstore_2: store_local_float(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 case Bytecodes::_fstore_3: store_local_float(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1182
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 case Bytecodes::_getfield: do_getfield(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 case Bytecodes::_getstatic: do_getstatic(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1185
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 case Bytecodes::_goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 case Bytecodes::_goto_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 case Bytecodes::_nop:
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 // do nothing.
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 case Bytecodes::_i2b:
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 case Bytecodes::_i2c:
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 case Bytecodes::_i2s:
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 case Bytecodes::_ineg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 case Bytecodes::_i2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 case Bytecodes::_i2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 case Bytecodes::_i2l:
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 case Bytecodes::_iadd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 case Bytecodes::_iand:
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 case Bytecodes::_idiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 case Bytecodes::_imul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 case Bytecodes::_ior:
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 case Bytecodes::_irem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 case Bytecodes::_ishl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 case Bytecodes::_ishr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 case Bytecodes::_isub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 case Bytecodes::_iushr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 case Bytecodes::_ixor:
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 case Bytecodes::_if_acmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 case Bytecodes::_if_acmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 case Bytecodes::_if_icmpeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 case Bytecodes::_if_icmpgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 case Bytecodes::_if_icmple:
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 case Bytecodes::_if_icmplt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 case Bytecodes::_ifeq:
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 case Bytecodes::_iflt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 case Bytecodes::_ifgt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 case Bytecodes::_tableswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 case Bytecodes::_iinc:
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 check_int(local(str->get_index()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 case Bytecodes::_iload: load_local_int(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 case Bytecodes::_iload_0: load_local_int(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 case Bytecodes::_iload_1: load_local_int(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 case Bytecodes::_iload_2: load_local_int(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 case Bytecodes::_iload_3: load_local_int(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1279
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 case Bytecodes::_instanceof:
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // Check for uncommon trap:
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 do_checkcast(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 pop_object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 case Bytecodes::_invokeinterface: do_invoke(str, true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 case Bytecodes::_invokespecial: do_invoke(str, true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 case Bytecodes::_invokestatic: do_invoke(str, false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1291
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 case Bytecodes::_invokevirtual: do_invoke(str, true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1293
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 case Bytecodes::_istore: store_local_int(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 case Bytecodes::_istore_0: store_local_int(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 case Bytecodes::_istore_1: store_local_int(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 case Bytecodes::_istore_2: store_local_int(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 case Bytecodes::_istore_3: store_local_int(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1299
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 case Bytecodes::_jsr_w: do_jsr(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 case Bytecodes::_l2d:
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 push_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 case Bytecodes::_l2f:
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 push_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 case Bytecodes::_l2i:
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 case Bytecodes::_ladd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 case Bytecodes::_land:
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 case Bytecodes::_ldiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 case Bytecodes::_lmul:
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 case Bytecodes::_lor:
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 case Bytecodes::_lrem:
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 case Bytecodes::_lsub:
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 case Bytecodes::_lxor:
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 case Bytecodes::_laload:
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 ciTypeArrayKlass* array_klass = pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 // Put assert here for right type?
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 case Bytecodes::_lastore:
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 pop_typeArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 // assert here?
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 case Bytecodes::_lcmp:
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 push_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 case Bytecodes::_lconst_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 case Bytecodes::_lconst_1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 case Bytecodes::_ldc:
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 case Bytecodes::_ldc_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 case Bytecodes::_ldc2_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 do_ldc(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1371
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 case Bytecodes::_lload: load_local_long(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 case Bytecodes::_lload_0: load_local_long(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 case Bytecodes::_lload_1: load_local_long(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 case Bytecodes::_lload_2: load_local_long(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 case Bytecodes::_lload_3: load_local_long(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1377
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 case Bytecodes::_lneg:
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 case Bytecodes::_lshl:
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 case Bytecodes::_lshr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 case Bytecodes::_lushr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 pop_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 pop_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 push_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 case Bytecodes::_lstore_0: store_local_long(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 case Bytecodes::_lstore_1: store_local_long(1); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 case Bytecodes::_lstore_2: store_local_long(2); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 case Bytecodes::_lstore_3: store_local_long(3); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 case Bytecodes::_multianewarray: do_multianewarray(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 case Bytecodes::_new: do_new(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1407
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 case Bytecodes::_newarray: do_newarray(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1409
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 case Bytecodes::_pop:
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 case Bytecodes::_pop2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 case Bytecodes::_putfield: do_putfield(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 case Bytecodes::_putstatic: do_putstatic(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1424
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 case Bytecodes::_ret: do_ret(str); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 case Bytecodes::_swap:
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 ciType* value1 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 ciType* value2 = pop_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 push(value1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 push(value2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 case Bytecodes::_wide:
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 // The iterator should skip this.
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1443
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1447
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 return (_trap_bci != -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1450
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 // ciTypeFlow::StateVector::print_cell_on
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 ciType* type = type_at(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 if (type == top_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 st->print("top");
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 } else if (type == bottom_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 st->print("bottom");
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 } else if (type == null_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 st->print("null");
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 } else if (type == long2_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 st->print("long2");
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 } else if (type == double2_type()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 st->print("double2");
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 } else if (is_int(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 st->print("int");
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 } else if (is_long(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 st->print("long");
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 } else if (is_float(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 st->print("float");
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 } else if (is_double(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 st->print("double");
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 } else if (type->is_return_address()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 st->print("address(%d)", type->as_return_address()->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 if (type->is_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 type->as_klass()->name()->print_symbol_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 st->print("UNEXPECTED TYPE");
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 type->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1485
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 // ciTypeFlow::StateVector::print_on
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 void ciTypeFlow::StateVector::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 int num_locals = _outer->max_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 int num_stack = stack_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 int num_monitors = monitor_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 st->print_cr(" State : locals %d, stack %d, monitors %d", num_locals, num_stack, num_monitors);
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 if (num_stack >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 for (i = 0; i < num_locals; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 st->print(" local %2d : ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 print_cell_on(st, local(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 for (i = 0; i < num_stack; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 st->print(" stack %2d : ", i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 print_cell_on(st, stack(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1508
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 // ciTypeFlow::Block
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 // A basic block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1512
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 // ciTypeFlow::Block::Block
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 ciTypeFlow::Block::Block(ciTypeFlow* outer,
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 ciBlock *ciblk,
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 ciTypeFlow::JsrSet* jsrs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 _ciblock = ciblk;
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 _exceptions = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 _exc_klasses = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 _successors = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 _state = new (outer->arena()) StateVector(outer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 JsrSet* new_jsrs =
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 new (outer->arena()) JsrSet(outer->arena(), jsrs->size());
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 jsrs->copy_into(new_jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 _jsrs = new_jsrs;
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 _next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 _on_work_list = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 _pre_order = -1; assert(!has_pre_order(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 _private_copy = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 _trap_bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 _trap_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1533
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 tty->print_cr(">> Created new block");
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1538
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 assert(this->outer() == outer, "outer link set up");
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 assert(!outer->have_block_count(), "must not have mapped blocks yet");
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1542
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 // ciTypeFlow::Block::clone_loop_head
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 ciTypeFlow::Block*
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 ciTypeFlow::Block::clone_loop_head(ciTypeFlow* analyzer,
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 int branch_bci,
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 ciTypeFlow::Block* target,
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 ciTypeFlow::JsrSet* jsrs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 // Loop optimizations are not performed on Tier1 compiles. Do nothing.
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 if (analyzer->env()->comp_level() < CompLevel_full_optimization) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 return target;
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1555
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 // The current block ends with a branch.
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 // If the target block appears to be the test-clause of a for loop, and
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 // it is not too large, and it has not yet been cloned, clone it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 // The pre-existing copy becomes the private clone used only by
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 // the initial iteration of the loop. (We know we are simulating
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 // the initial iteration right now, since we have never calculated
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 // successors before for this block.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1564
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 if (branch_bci <= start()
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 && (target->limit() - target->start()) <= CICloneLoopTestLimit
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 && target->private_copy_count() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 // Setting the private_copy bit ensures that the target block cannot be
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 // reached by any other paths, such as fall-in from the loop body.
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 // The private copy will be accessible only on successor lists
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 // created up to this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 target->set_private_copy(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 tty->print(">> Cloning a test-clause block ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 // If the target is the current block, then later on a new copy of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 // target block will be created when its bytecodes are reached by
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 // an alternate path. (This is the case for loops with the loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 // head at the bci-wise bottom of the loop, as with pre-1.4.2 javac.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 // Otherwise, duplicate the target block now and use it immediately.
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 // (The case for loops with the loop head at the bci-wise top of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 // loop, as with 1.4.2 javac.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 // In either case, the new copy of the block will remain public.
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 if (target != this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 target = analyzer->block_at(branch_bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 return target;
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1594
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 // ciTypeFlow::Block::successors
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 // Get the successors for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 GrowableArray<ciTypeFlow::Block*>*
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 ciTypeFlow::Block::successors(ciBytecodeStream* str,
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 ciTypeFlow::StateVector* state,
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 ciTypeFlow::JsrSet* jsrs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 if (_successors == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 tty->print(">> Computing successors for block ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1609
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 ciTypeFlow* analyzer = outer();
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 Arena* arena = analyzer->arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 Block* block = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 bool has_successor = !has_trap() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 (control() != ciBlock::fall_through_bci || limit() < analyzer->code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 if (!has_successor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 // No successors
a61af66fc99e Initial load
duke
parents:
diff changeset
1619 } else if (control() == ciBlock::fall_through_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 assert(str->cur_bci() == limit(), "bad block end");
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 // This block simply falls through to the next.
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1624
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 Block* block = analyzer->block_at(limit(), _jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 assert(_successors->length() == FALL_THROUGH, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 _successors->append(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 int current_bci = str->cur_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 int next_bci = str->next_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 int branch_bci = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 Block* target = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 assert(str->next_bci() == limit(), "bad block end");
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 // This block is not a simple fall-though. Interpret
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 // the current bytecode to find our successors.
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 switch (str->cur_bc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 case Bytecodes::_ifeq: case Bytecodes::_ifne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 case Bytecodes::_iflt: case Bytecodes::_ifge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 case Bytecodes::_ifgt: case Bytecodes::_ifle:
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 case Bytecodes::_if_icmpeq: case Bytecodes::_if_icmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 case Bytecodes::_if_icmplt: case Bytecodes::_if_icmpge:
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 case Bytecodes::_if_icmpgt: case Bytecodes::_if_icmple:
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 case Bytecodes::_if_acmpeq: case Bytecodes::_if_acmpne:
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 case Bytecodes::_ifnull: case Bytecodes::_ifnonnull:
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 // Our successors are the branch target and the next bci.
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 branch_bci = str->get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 clone_loop_head(analyzer, branch_bci, this, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 new (arena) GrowableArray<Block*>(arena, 2, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 assert(_successors->length() == IF_NOT_TAKEN, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 _successors->append(analyzer->block_at(next_bci, jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 assert(_successors->length() == IF_TAKEN, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 _successors->append(analyzer->block_at(branch_bci, jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1655
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 case Bytecodes::_goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 branch_bci = str->get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 assert(_successors->length() == GOTO_TARGET, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 target = analyzer->block_at(branch_bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 // If the target block has not been visited yet, and looks like
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 // a two-way branch, attempt to clone it if it is a loop head.
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 if (target->_successors != NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 && target->_successors->length() == (IF_TAKEN + 1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 target = clone_loop_head(analyzer, branch_bci, target, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 _successors->append(target);
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1670
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 case Bytecodes::_jsr:
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 branch_bci = str->get_dest();
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 assert(_successors->length() == GOTO_TARGET, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 _successors->append(analyzer->block_at(branch_bci, jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1678
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 case Bytecodes::_goto_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 case Bytecodes::_jsr_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 assert(_successors->length() == GOTO_TARGET, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 _successors->append(analyzer->block_at(str->get_far_dest(), jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1686
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 case Bytecodes::_tableswitch: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 Bytecode_tableswitch *tableswitch =
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 Bytecode_tableswitch_at(str->cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
1690
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 int len = tableswitch->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 new (arena) GrowableArray<Block*>(arena, len+1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 int bci = current_bci + tableswitch->default_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 Block* block = analyzer->block_at(bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 assert(_successors->length() == SWITCH_DEFAULT, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 _successors->append(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 while (--len >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 int bci = current_bci + tableswitch->dest_offset_at(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 block = analyzer->block_at(bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 assert(_successors->length() >= SWITCH_CASES, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 _successors->append_if_missing(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1706
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 case Bytecodes::_lookupswitch: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 Bytecode_lookupswitch *lookupswitch =
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 Bytecode_lookupswitch_at(str->cur_bcp());
a61af66fc99e Initial load
duke
parents:
diff changeset
1710
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 int npairs = lookupswitch->number_of_pairs();
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 int bci = current_bci + lookupswitch->default_offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 Block* block = analyzer->block_at(bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 assert(_successors->length() == SWITCH_DEFAULT, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 _successors->append(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 while(--npairs >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 LookupswitchPair *pair = lookupswitch->pair_at(npairs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 int bci = current_bci + pair->offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 Block* block = analyzer->block_at(bci, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 assert(_successors->length() >= SWITCH_CASES, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 _successors->append_if_missing(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1727
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 case Bytecodes::_athrow: case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 case Bytecodes::_lreturn: case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 case Bytecodes::_dreturn: case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 // No successors
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1736
a61af66fc99e Initial load
duke
parents:
diff changeset
1737 case Bytecodes::_ret: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 _successors =
a61af66fc99e Initial load
duke
parents:
diff changeset
1739 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1740
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 Cell local = state->local(str->get_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 ciType* return_address = state->type_at(local);
a61af66fc99e Initial load
duke
parents:
diff changeset
1743 assert(return_address->is_return_address(), "verify: wrong type");
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 int bci = return_address->as_return_address()->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 assert(_successors->length() == GOTO_TARGET, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 _successors->append(analyzer->block_at(bci, jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1749
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 case Bytecodes::_wide:
a61af66fc99e Initial load
duke
parents:
diff changeset
1751 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 return _successors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1759
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 // ciTypeFlow::Block:compute_exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 // Compute the exceptional successors and types for this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 void ciTypeFlow::Block::compute_exceptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 assert(_exceptions == NULL && _exc_klasses == NULL, "repeat");
a61af66fc99e Initial load
duke
parents:
diff changeset
1766
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 tty->print(">> Computing exceptions for block ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1772
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 ciTypeFlow* analyzer = outer();
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 Arena* arena = analyzer->arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
1775
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 // Any bci in the block will do.
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 ciExceptionHandlerStream str(analyzer->method(), start());
a61af66fc99e Initial load
duke
parents:
diff changeset
1778
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 // Allocate our growable arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 int exc_count = str.count();
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 _exceptions = new (arena) GrowableArray<Block*>(arena, exc_count, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 _exc_klasses = new (arena) GrowableArray<ciInstanceKlass*>(arena, exc_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1784
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 for ( ; !str.is_done(); str.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1786 ciExceptionHandler* handler = str.handler();
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 int bci = handler->handler_bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 ciInstanceKlass* klass = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1789 if (bci == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 // There is no catch all. It is possible to exit the method.
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 if (handler->is_catch_all()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 klass = analyzer->env()->Throwable_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 klass = handler->catch_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
1797 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 _exceptions->append(analyzer->block_at(bci, _jsrs));
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 _exc_klasses->append(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1802
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 // ciTypeFlow::Block::is_simpler_than
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 // A relation used to order our work list. We work on a block earlier
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 // if it has a smaller jsr stack or it occurs earlier in the program
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 // text.
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 // Note: maybe we should redo this functionality to make blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
1811 // which correspond to exceptions lower priority.
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 bool ciTypeFlow::Block::is_simpler_than(ciTypeFlow::Block* other) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 if (other == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 int size1 = _jsrs->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 int size2 = other->_jsrs->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 if (size1 < size2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1820 } else if (size2 < size1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 #if 0
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 if (size1 > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1825 int r1 = _jsrs->record_at(0)->return_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 int r2 = _jsrs->record_at(0)->return_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 if (r1 < r2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 } else if (r2 < r1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1830 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 int e1 = _jsrs->record_at(0)->return_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
1833 int e2 = _jsrs->record_at(0)->return_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
1834 if (e1 < e2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1835 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 } else if (e2 < e1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1837 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1841 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1842 return (start() <= other->start());
a61af66fc99e Initial load
duke
parents:
diff changeset
1843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1844 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1846
a61af66fc99e Initial load
duke
parents:
diff changeset
1847 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1848 // ciTypeFlow::Block::set_private_copy
a61af66fc99e Initial load
duke
parents:
diff changeset
1849 // Use this only to make a pre-existing public block into a private copy.
a61af66fc99e Initial load
duke
parents:
diff changeset
1850 void ciTypeFlow::Block::set_private_copy(bool z) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1851 assert(z || (z == is_private_copy()), "cannot make a private copy public");
a61af66fc99e Initial load
duke
parents:
diff changeset
1852 _private_copy = z;
a61af66fc99e Initial load
duke
parents:
diff changeset
1853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1854
a61af66fc99e Initial load
duke
parents:
diff changeset
1855 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1856 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1857 // ciTypeFlow::Block::print_value_on
a61af66fc99e Initial load
duke
parents:
diff changeset
1858 void ciTypeFlow::Block::print_value_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1859 if (has_pre_order()) st->print("#%-2d ", pre_order());
a61af66fc99e Initial load
duke
parents:
diff changeset
1860 st->print("[%d - %d)", start(), limit());
a61af66fc99e Initial load
duke
parents:
diff changeset
1861 if (_jsrs->size() > 0) { st->print("/"); _jsrs->print_on(st); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1862 if (is_private_copy()) st->print("/private_copy");
a61af66fc99e Initial load
duke
parents:
diff changeset
1863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1864
a61af66fc99e Initial load
duke
parents:
diff changeset
1865 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1866 // ciTypeFlow::Block::print_on
a61af66fc99e Initial load
duke
parents:
diff changeset
1867 void ciTypeFlow::Block::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1868 if ((Verbose || WizardMode)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1869 outer()->method()->print_codes_on(start(), limit(), st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1871 st->print_cr(" ==================================================== ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1872 st->print (" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1873 print_value_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 _state->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1876 if (_successors == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1877 st->print_cr(" No successor information");
a61af66fc99e Initial load
duke
parents:
diff changeset
1878 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1879 int num_successors = _successors->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1880 st->print_cr(" Successors : %d", num_successors);
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 for (int i = 0; i < num_successors; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 Block* successor = _successors->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 st->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1884 successor->print_value_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1885 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 if (_exceptions == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 st->print_cr(" No exception information");
a61af66fc99e Initial load
duke
parents:
diff changeset
1890 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1891 int num_exceptions = _exceptions->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 st->print_cr(" Exceptions : %d", num_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
1893 for (int i = 0; i < num_exceptions; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 Block* exc_succ = _exceptions->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1895 ciInstanceKlass* exc_klass = _exc_klasses->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1896 st->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 exc_succ->print_value_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 st->print(" -- ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 exc_klass->name()->print_symbol_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1903 if (has_trap()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 st->print_cr(" Traps on %d with trap index %d", trap_bci(), trap_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1906 st->print_cr(" ==================================================== ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1908 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1909
a61af66fc99e Initial load
duke
parents:
diff changeset
1910 // ciTypeFlow
a61af66fc99e Initial load
duke
parents:
diff changeset
1911 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1912 // This is a pass over the bytecodes which computes the following:
a61af66fc99e Initial load
duke
parents:
diff changeset
1913 // basic block structure
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 // interpreter type-states (a la the verifier)
a61af66fc99e Initial load
duke
parents:
diff changeset
1915
a61af66fc99e Initial load
duke
parents:
diff changeset
1916 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1917 // ciTypeFlow::ciTypeFlow
a61af66fc99e Initial load
duke
parents:
diff changeset
1918 ciTypeFlow::ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 _env = env;
a61af66fc99e Initial load
duke
parents:
diff changeset
1920 _method = method;
a61af66fc99e Initial load
duke
parents:
diff changeset
1921 _methodBlocks = method->get_method_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
1922 _max_locals = method->max_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
1923 _max_stack = method->max_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
1924 _code_size = method->code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
1925 _osr_bci = osr_bci;
a61af66fc99e Initial load
duke
parents:
diff changeset
1926 _failure_reason = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1927 assert(start_bci() >= 0 && start_bci() < code_size() , "correct osr_bci argument");
a61af66fc99e Initial load
duke
parents:
diff changeset
1928
a61af66fc99e Initial load
duke
parents:
diff changeset
1929 _work_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1930 _next_pre_order = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1931
a61af66fc99e Initial load
duke
parents:
diff changeset
1932 _ciblock_count = _methodBlocks->num_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
1933 _idx_to_blocklist = NEW_ARENA_ARRAY(arena(), GrowableArray<Block*>*, _ciblock_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
1934 for (int i = 0; i < _ciblock_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1935 _idx_to_blocklist[i] = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1937 _block_map = NULL; // until all blocks are seen
a61af66fc99e Initial load
duke
parents:
diff changeset
1938 _jsr_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1939 _jsr_records = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1941
a61af66fc99e Initial load
duke
parents:
diff changeset
1942 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1943 // ciTypeFlow::work_list_next
a61af66fc99e Initial load
duke
parents:
diff changeset
1944 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1945 // Get the next basic block from our work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1946 ciTypeFlow::Block* ciTypeFlow::work_list_next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 assert(!work_list_empty(), "work list must not be empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
1948 Block* next_block = _work_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
1949 _work_list = next_block->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1950 next_block->set_next(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 next_block->set_on_work_list(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1952 if (!next_block->has_pre_order()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 // Assign "pre_order" as each new block is taken from the work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1954 // This number may be used by following phases to order block visits.
a61af66fc99e Initial load
duke
parents:
diff changeset
1955 assert(!have_block_count(), "must not have mapped blocks yet")
a61af66fc99e Initial load
duke
parents:
diff changeset
1956 next_block->set_pre_order(_next_pre_order++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 return next_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1960
a61af66fc99e Initial load
duke
parents:
diff changeset
1961 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1962 // ciTypeFlow::add_to_work_list
a61af66fc99e Initial load
duke
parents:
diff changeset
1963 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1964 // Add a basic block to our work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1965 void ciTypeFlow::add_to_work_list(ciTypeFlow::Block* block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1966 assert(!block->is_on_work_list(), "must not already be on work list");
a61af66fc99e Initial load
duke
parents:
diff changeset
1967
a61af66fc99e Initial load
duke
parents:
diff changeset
1968 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1969 tty->print(">> Adding block%s ", block->has_pre_order() ? " (again)" : "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1970 block->print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
1971 tty->print_cr(" to the work list : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1972 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1973
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 block->set_on_work_list(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 if (block->is_simpler_than(_work_list)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1976 block->set_next(_work_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
1977 _work_list = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1979 Block *temp = _work_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 while (!block->is_simpler_than(temp->next())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1981 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 tty->print(".");
a61af66fc99e Initial load
duke
parents:
diff changeset
1983 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1984 temp = temp->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1986 block->set_next(temp->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 temp->set_next(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
1988 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1989 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1993
a61af66fc99e Initial load
duke
parents:
diff changeset
1994 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1995 // ciTypeFlow::block_at
a61af66fc99e Initial load
duke
parents:
diff changeset
1996 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 // Return the block beginning at bci which has a JsrSet compatible
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 // with jsrs.
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 ciTypeFlow::Block* ciTypeFlow::block_at(int bci, ciTypeFlow::JsrSet* jsrs, CreateOption option) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 // First find the right ciBlock.
a61af66fc99e Initial load
duke
parents:
diff changeset
2001 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2002 tty->print(">> Requesting block for %d/", bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2003 jsrs->print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2004 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2006
a61af66fc99e Initial load
duke
parents:
diff changeset
2007 ciBlock* ciblk = _methodBlocks->block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2008 assert(ciblk->start_bci() == bci, "bad ciBlock boundaries");
a61af66fc99e Initial load
duke
parents:
diff changeset
2009 Block* block = get_block_for(ciblk->index(), jsrs, option);
a61af66fc99e Initial load
duke
parents:
diff changeset
2010
a61af66fc99e Initial load
duke
parents:
diff changeset
2011 assert(block == NULL? (option == no_create): block->is_private_copy() == (option == create_private_copy), "create option consistent with result");
a61af66fc99e Initial load
duke
parents:
diff changeset
2012
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 if (block != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 tty->print(">> Found block ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2016 block->print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2017 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2019 tty->print_cr(">> No such block.");
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2022
a61af66fc99e Initial load
duke
parents:
diff changeset
2023 return block;
a61af66fc99e Initial load
duke
parents:
diff changeset
2024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2025
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 // ciTypeFlow::make_jsr_record
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2029 // Make a JsrRecord for a given (entry, return) pair, if such a record
a61af66fc99e Initial load
duke
parents:
diff changeset
2030 // does not already exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 ciTypeFlow::JsrRecord* ciTypeFlow::make_jsr_record(int entry_address,
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 int return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 if (_jsr_records == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2034 _jsr_records = new (arena()) GrowableArray<JsrRecord*>(arena(),
a61af66fc99e Initial load
duke
parents:
diff changeset
2035 _jsr_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
2038 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2039 JsrRecord* record = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2040 int len = _jsr_records->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2041 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 JsrRecord* record = _jsr_records->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2043 if (record->entry_address() == entry_address &&
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 record->return_address() == return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2045 return record;
a61af66fc99e Initial load
duke
parents:
diff changeset
2046 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2047 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2048
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 record = new (arena()) JsrRecord(entry_address, return_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 _jsr_records->append(record);
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 return record;
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2053
a61af66fc99e Initial load
duke
parents:
diff changeset
2054 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2055 // ciTypeFlow::flow_exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2057 // Merge the current state into all exceptional successors at the
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 // current point in the code.
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 void ciTypeFlow::flow_exceptions(GrowableArray<ciTypeFlow::Block*>* exceptions,
a61af66fc99e Initial load
duke
parents:
diff changeset
2060 GrowableArray<ciInstanceKlass*>* exc_klasses,
a61af66fc99e Initial load
duke
parents:
diff changeset
2061 ciTypeFlow::StateVector* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2062 int len = exceptions->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2063 assert(exc_klasses->length() == len, "must have same length");
a61af66fc99e Initial load
duke
parents:
diff changeset
2064 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2065 Block* block = exceptions->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2066 ciInstanceKlass* exception_klass = exc_klasses->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2067
a61af66fc99e Initial load
duke
parents:
diff changeset
2068 if (!exception_klass->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2069 // Do not compile any code for unloaded exception types.
a61af66fc99e Initial load
duke
parents:
diff changeset
2070 // Following compiler passes are responsible for doing this also.
a61af66fc99e Initial load
duke
parents:
diff changeset
2071 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2073
a61af66fc99e Initial load
duke
parents:
diff changeset
2074 if (block->meet_exception(exception_klass, state)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2075 // Block was modified. Add it to the work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
2076 if (!block->is_on_work_list()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2077 add_to_work_list(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
2078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2079 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2082
a61af66fc99e Initial load
duke
parents:
diff changeset
2083 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2084 // ciTypeFlow::flow_successors
a61af66fc99e Initial load
duke
parents:
diff changeset
2085 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2086 // Merge the current state into all successors at the current point
a61af66fc99e Initial load
duke
parents:
diff changeset
2087 // in the code.
a61af66fc99e Initial load
duke
parents:
diff changeset
2088 void ciTypeFlow::flow_successors(GrowableArray<ciTypeFlow::Block*>* successors,
a61af66fc99e Initial load
duke
parents:
diff changeset
2089 ciTypeFlow::StateVector* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2090 int len = successors->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2091 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2092 Block* block = successors->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2093 if (block->meet(state)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2094 // Block was modified. Add it to the work list.
a61af66fc99e Initial load
duke
parents:
diff changeset
2095 if (!block->is_on_work_list()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2096 add_to_work_list(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
2097 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2098 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2099 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2101
a61af66fc99e Initial load
duke
parents:
diff changeset
2102 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2103 // ciTypeFlow::can_trap
a61af66fc99e Initial load
duke
parents:
diff changeset
2104 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2105 // Tells if a given instruction is able to generate an exception edge.
a61af66fc99e Initial load
duke
parents:
diff changeset
2106 bool ciTypeFlow::can_trap(ciBytecodeStream& str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2107 // Cf. GenerateOopMap::do_exception_edge.
a61af66fc99e Initial load
duke
parents:
diff changeset
2108 if (!Bytecodes::can_trap(str.cur_bc())) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2109
a61af66fc99e Initial load
duke
parents:
diff changeset
2110 switch (str.cur_bc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2111 case Bytecodes::_ldc:
a61af66fc99e Initial load
duke
parents:
diff changeset
2112 case Bytecodes::_ldc_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
2113 case Bytecodes::_ldc2_w:
a61af66fc99e Initial load
duke
parents:
diff changeset
2114 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
2115 // These bytecodes can trap for rewriting. We need to assume that
a61af66fc99e Initial load
duke
parents:
diff changeset
2116 // they do not throw exceptions to make the monitor analysis work.
a61af66fc99e Initial load
duke
parents:
diff changeset
2117 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2118
a61af66fc99e Initial load
duke
parents:
diff changeset
2119 case Bytecodes::_ireturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
2120 case Bytecodes::_lreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
2121 case Bytecodes::_freturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
2122 case Bytecodes::_dreturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
2123 case Bytecodes::_areturn:
a61af66fc99e Initial load
duke
parents:
diff changeset
2124 case Bytecodes::_return:
a61af66fc99e Initial load
duke
parents:
diff changeset
2125 // We can assume the monitor stack is empty in this analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
2126 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2127
a61af66fc99e Initial load
duke
parents:
diff changeset
2128 case Bytecodes::_monitorexit:
a61af66fc99e Initial load
duke
parents:
diff changeset
2129 // We can assume monitors are matched in this analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
2130 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
2131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2132
a61af66fc99e Initial load
duke
parents:
diff changeset
2133 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
2134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2135
a61af66fc99e Initial load
duke
parents:
diff changeset
2136
a61af66fc99e Initial load
duke
parents:
diff changeset
2137 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2138 // ciTypeFlow::flow_block
a61af66fc99e Initial load
duke
parents:
diff changeset
2139 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2140 // Interpret the effects of the bytecodes on the incoming state
a61af66fc99e Initial load
duke
parents:
diff changeset
2141 // vector of a basic block. Push the changed state to succeeding
a61af66fc99e Initial load
duke
parents:
diff changeset
2142 // basic blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
2143 void ciTypeFlow::flow_block(ciTypeFlow::Block* block,
a61af66fc99e Initial load
duke
parents:
diff changeset
2144 ciTypeFlow::StateVector* state,
a61af66fc99e Initial load
duke
parents:
diff changeset
2145 ciTypeFlow::JsrSet* jsrs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2146 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2147 tty->print("\n>> ANALYZING BLOCK : ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2148 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2149 block->print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2151 assert(block->has_pre_order(), "pre-order is assigned before 1st flow");
a61af66fc99e Initial load
duke
parents:
diff changeset
2152
a61af66fc99e Initial load
duke
parents:
diff changeset
2153 int start = block->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
2154 int limit = block->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
2155 int control = block->control();
a61af66fc99e Initial load
duke
parents:
diff changeset
2156 if (control != ciBlock::fall_through_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2157 limit = control;
a61af66fc99e Initial load
duke
parents:
diff changeset
2158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2159
a61af66fc99e Initial load
duke
parents:
diff changeset
2160 // Grab the state from the current block.
a61af66fc99e Initial load
duke
parents:
diff changeset
2161 block->copy_state_into(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2162
a61af66fc99e Initial load
duke
parents:
diff changeset
2163 GrowableArray<Block*>* exceptions = block->exceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
2164 GrowableArray<ciInstanceKlass*>* exc_klasses = block->exc_klasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
2165 bool has_exceptions = exceptions->length() > 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2166
a61af66fc99e Initial load
duke
parents:
diff changeset
2167 ciBytecodeStream str(method());
a61af66fc99e Initial load
duke
parents:
diff changeset
2168 str.reset_to_bci(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
2169 Bytecodes::Code code;
a61af66fc99e Initial load
duke
parents:
diff changeset
2170 while ((code = str.next()) != ciBytecodeStream::EOBC() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
2171 str.cur_bci() < limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2172 // Check for exceptional control flow from this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
2173 if (has_exceptions && can_trap(str)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2174 flow_exceptions(exceptions, exc_klasses, state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2176 // Apply the effects of the current bytecode to our state.
a61af66fc99e Initial load
duke
parents:
diff changeset
2177 bool res = state->apply_one_bytecode(&str);
a61af66fc99e Initial load
duke
parents:
diff changeset
2178
a61af66fc99e Initial load
duke
parents:
diff changeset
2179 // Watch for bailouts.
a61af66fc99e Initial load
duke
parents:
diff changeset
2180 if (failing()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2181
a61af66fc99e Initial load
duke
parents:
diff changeset
2182 if (res) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2183
a61af66fc99e Initial load
duke
parents:
diff changeset
2184 // We have encountered a trap. Record it in this block.
a61af66fc99e Initial load
duke
parents:
diff changeset
2185 block->set_trap(state->trap_bci(), state->trap_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
2186
a61af66fc99e Initial load
duke
parents:
diff changeset
2187 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2188 tty->print_cr(">> Found trap");
a61af66fc99e Initial load
duke
parents:
diff changeset
2189 block->print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2191
a61af66fc99e Initial load
duke
parents:
diff changeset
2192 // Record (no) successors.
a61af66fc99e Initial load
duke
parents:
diff changeset
2193 block->successors(&str, state, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2194
a61af66fc99e Initial load
duke
parents:
diff changeset
2195 // Discontinue interpretation of this Block.
a61af66fc99e Initial load
duke
parents:
diff changeset
2196 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2199
a61af66fc99e Initial load
duke
parents:
diff changeset
2200 GrowableArray<Block*>* successors = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2201 if (control != ciBlock::fall_through_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2202 // Check for exceptional control flow from this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
2203 if (has_exceptions && can_trap(str)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2204 flow_exceptions(exceptions, exc_klasses, state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2206
a61af66fc99e Initial load
duke
parents:
diff changeset
2207 // Fix the JsrSet to reflect effect of the bytecode.
a61af66fc99e Initial load
duke
parents:
diff changeset
2208 block->copy_jsrs_into(jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2209 jsrs->apply_control(this, &str, state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2210
a61af66fc99e Initial load
duke
parents:
diff changeset
2211 // Find successor edges based on old state and new JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
2212 successors = block->successors(&str, state, jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2213
a61af66fc99e Initial load
duke
parents:
diff changeset
2214 // Apply the control changes to the state.
a61af66fc99e Initial load
duke
parents:
diff changeset
2215 state->apply_one_bytecode(&str);
a61af66fc99e Initial load
duke
parents:
diff changeset
2216 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2217 // Fall through control
a61af66fc99e Initial load
duke
parents:
diff changeset
2218 successors = block->successors(&str, NULL, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
2219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2220
a61af66fc99e Initial load
duke
parents:
diff changeset
2221 // Pass our state to successors.
a61af66fc99e Initial load
duke
parents:
diff changeset
2222 flow_successors(successors, state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2224
a61af66fc99e Initial load
duke
parents:
diff changeset
2225 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2226 // ciTypeFlow::flow_types
a61af66fc99e Initial load
duke
parents:
diff changeset
2227 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2228 // Perform the type flow analysis, creating and cloning Blocks as
a61af66fc99e Initial load
duke
parents:
diff changeset
2229 // necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
2230 void ciTypeFlow::flow_types() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2231 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
2232 StateVector* temp_vector = new StateVector(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2233 JsrSet* temp_set = new JsrSet(NULL, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
2234
a61af66fc99e Initial load
duke
parents:
diff changeset
2235 // Create the method entry block.
a61af66fc99e Initial load
duke
parents:
diff changeset
2236 Block* block = block_at(start_bci(), temp_set);
a61af66fc99e Initial load
duke
parents:
diff changeset
2237 block->set_pre_order(_next_pre_order++);
a61af66fc99e Initial load
duke
parents:
diff changeset
2238 assert(block->is_start(), "start block must have order #0");
a61af66fc99e Initial load
duke
parents:
diff changeset
2239
a61af66fc99e Initial load
duke
parents:
diff changeset
2240 // Load the initial state into it.
a61af66fc99e Initial load
duke
parents:
diff changeset
2241 const StateVector* start_state = get_start_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
2242 if (failing()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2243 block->meet(start_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
2244 add_to_work_list(block);
a61af66fc99e Initial load
duke
parents:
diff changeset
2245
a61af66fc99e Initial load
duke
parents:
diff changeset
2246 // Trickle away.
a61af66fc99e Initial load
duke
parents:
diff changeset
2247 while (!work_list_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2248 Block* block = work_list_next();
a61af66fc99e Initial load
duke
parents:
diff changeset
2249 flow_block(block, temp_vector, temp_set);
a61af66fc99e Initial load
duke
parents:
diff changeset
2250
a61af66fc99e Initial load
duke
parents:
diff changeset
2251
a61af66fc99e Initial load
duke
parents:
diff changeset
2252 // NodeCountCutoff is the number of nodes at which the parser
a61af66fc99e Initial load
duke
parents:
diff changeset
2253 // will bail out. Probably if we already have lots of BBs,
a61af66fc99e Initial load
duke
parents:
diff changeset
2254 // the parser will generate at least twice that many nodes and bail out.
a61af66fc99e Initial load
duke
parents:
diff changeset
2255 // Therefore, this is a conservatively large limit at which to
a61af66fc99e Initial load
duke
parents:
diff changeset
2256 // bail out in the pre-parse typeflow pass.
a61af66fc99e Initial load
duke
parents:
diff changeset
2257 int block_limit = MaxNodeLimit / 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
2258
a61af66fc99e Initial load
duke
parents:
diff changeset
2259 if (_next_pre_order >= block_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2260 // Too many basic blocks. Bail out.
a61af66fc99e Initial load
duke
parents:
diff changeset
2261 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2262 // This can happen when try/finally constructs are nested to depth N,
a61af66fc99e Initial load
duke
parents:
diff changeset
2263 // and there is O(2**N) cloning of jsr bodies. See bug 4697245!
a61af66fc99e Initial load
duke
parents:
diff changeset
2264 record_failure("too many basic blocks");
a61af66fc99e Initial load
duke
parents:
diff changeset
2265 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2267
a61af66fc99e Initial load
duke
parents:
diff changeset
2268 // Watch for bailouts.
a61af66fc99e Initial load
duke
parents:
diff changeset
2269 if (failing()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2272
a61af66fc99e Initial load
duke
parents:
diff changeset
2273 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2274 // ciTypeFlow::map_blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
2275 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2276 // Create the block map, which indexes blocks in pre_order.
a61af66fc99e Initial load
duke
parents:
diff changeset
2277 void ciTypeFlow::map_blocks() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2278 assert(_block_map == NULL, "single initialization");
a61af66fc99e Initial load
duke
parents:
diff changeset
2279 int pre_order_limit = _next_pre_order;
a61af66fc99e Initial load
duke
parents:
diff changeset
2280 _block_map = NEW_ARENA_ARRAY(arena(), Block*, pre_order_limit);
a61af66fc99e Initial load
duke
parents:
diff changeset
2281 assert(pre_order_limit == block_count(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2282 int po;
a61af66fc99e Initial load
duke
parents:
diff changeset
2283 for (po = 0; po < pre_order_limit; po++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2284 debug_only(_block_map[po] = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
2285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2286 ciMethodBlocks *mblks = _methodBlocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
2287 ciBlock* current = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2288 int limit_bci = code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
2289 for (int bci = 0; bci < limit_bci; bci++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2290 ciBlock* ciblk = mblks->block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2291 if (ciblk != NULL && ciblk != current) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2292 current = ciblk;
a61af66fc99e Initial load
duke
parents:
diff changeset
2293 int curidx = ciblk->index();
a61af66fc99e Initial load
duke
parents:
diff changeset
2294 int block_count = (_idx_to_blocklist[curidx] == NULL) ? 0 : _idx_to_blocklist[curidx]->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2295 for (int i = 0; i < block_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2296 Block* block = _idx_to_blocklist[curidx]->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2297 if (!block->has_pre_order()) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2298 int po = block->pre_order();
a61af66fc99e Initial load
duke
parents:
diff changeset
2299 assert(_block_map[po] == NULL, "unique ref to block");
a61af66fc99e Initial load
duke
parents:
diff changeset
2300 assert(0 <= po && po < pre_order_limit, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2301 _block_map[po] = block;
a61af66fc99e Initial load
duke
parents:
diff changeset
2302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2305 for (po = 0; po < pre_order_limit; po++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2306 assert(_block_map[po] != NULL, "must not drop any blocks");
a61af66fc99e Initial load
duke
parents:
diff changeset
2307 Block* block = _block_map[po];
a61af66fc99e Initial load
duke
parents:
diff changeset
2308 // Remove dead blocks from successor lists:
a61af66fc99e Initial load
duke
parents:
diff changeset
2309 for (int e = 0; e <= 1; e++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2310 GrowableArray<Block*>* l = e? block->exceptions(): block->successors();
a61af66fc99e Initial load
duke
parents:
diff changeset
2311 for (int i = 0; i < l->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2312 Block* s = l->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2313 if (!s->has_pre_order()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2314 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2315 tty->print("Removing dead %s successor of #%d: ", (e? "exceptional": "normal"), block->pre_order());
a61af66fc99e Initial load
duke
parents:
diff changeset
2316 s->print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2317 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2319 l->remove(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
2320 --i;
a61af66fc99e Initial load
duke
parents:
diff changeset
2321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2326
a61af66fc99e Initial load
duke
parents:
diff changeset
2327 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2328 // ciTypeFlow::get_block_for
a61af66fc99e Initial load
duke
parents:
diff changeset
2329 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2330 // Find a block with this ciBlock which has a compatible JsrSet.
a61af66fc99e Initial load
duke
parents:
diff changeset
2331 // If no such block exists, create it, unless the option is no_create.
a61af66fc99e Initial load
duke
parents:
diff changeset
2332 // If the option is create_private_copy, always create a fresh private copy.
a61af66fc99e Initial load
duke
parents:
diff changeset
2333 ciTypeFlow::Block* ciTypeFlow::get_block_for(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs, CreateOption option) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2334 Arena* a = arena();
a61af66fc99e Initial load
duke
parents:
diff changeset
2335 GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex];
a61af66fc99e Initial load
duke
parents:
diff changeset
2336 if (blocks == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2337 // Query only?
a61af66fc99e Initial load
duke
parents:
diff changeset
2338 if (option == no_create) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2339
a61af66fc99e Initial load
duke
parents:
diff changeset
2340 // Allocate the growable array.
a61af66fc99e Initial load
duke
parents:
diff changeset
2341 blocks = new (a) GrowableArray<Block*>(a, 4, 0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
2342 _idx_to_blocklist[ciBlockIndex] = blocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
2343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2344
a61af66fc99e Initial load
duke
parents:
diff changeset
2345 if (option != create_private_copy) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2346 int len = blocks->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2347 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2348 Block* block = blocks->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2349 if (!block->is_private_copy() && block->is_compatible_with(jsrs)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2350 return block;
a61af66fc99e Initial load
duke
parents:
diff changeset
2351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2354
a61af66fc99e Initial load
duke
parents:
diff changeset
2355 // Query only?
a61af66fc99e Initial load
duke
parents:
diff changeset
2356 if (option == no_create) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2357
a61af66fc99e Initial load
duke
parents:
diff changeset
2358 // We did not find a compatible block. Create one.
a61af66fc99e Initial load
duke
parents:
diff changeset
2359 Block* new_block = new (a) Block(this, _methodBlocks->block(ciBlockIndex), jsrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2360 if (option == create_private_copy) new_block->set_private_copy(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
2361 blocks->append(new_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
2362 return new_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
2363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2364
a61af66fc99e Initial load
duke
parents:
diff changeset
2365 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2366 // ciTypeFlow::private_copy_count
a61af66fc99e Initial load
duke
parents:
diff changeset
2367 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2368 int ciTypeFlow::private_copy_count(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
2369 GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex];
a61af66fc99e Initial load
duke
parents:
diff changeset
2370
a61af66fc99e Initial load
duke
parents:
diff changeset
2371 if (blocks == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2372 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2374
a61af66fc99e Initial load
duke
parents:
diff changeset
2375 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2376 int len = blocks->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2377 for (int i = 0; i < len; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2378 Block* block = blocks->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2379 if (block->is_private_copy() && block->is_compatible_with(jsrs)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2380 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2383
a61af66fc99e Initial load
duke
parents:
diff changeset
2384 return count;
a61af66fc99e Initial load
duke
parents:
diff changeset
2385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2386
a61af66fc99e Initial load
duke
parents:
diff changeset
2387 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2388 // ciTypeFlow::do_flow
a61af66fc99e Initial load
duke
parents:
diff changeset
2389 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2390 // Perform type inference flow analysis.
a61af66fc99e Initial load
duke
parents:
diff changeset
2391 void ciTypeFlow::do_flow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2392 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2393 tty->print_cr("\nPerforming flow analysis on method");
a61af66fc99e Initial load
duke
parents:
diff changeset
2394 method()->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
2395 if (is_osr_flow()) tty->print(" at OSR bci %d", start_bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
2396 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2397 method()->print_codes();
a61af66fc99e Initial load
duke
parents:
diff changeset
2398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2399 if (CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2400 tty->print_cr("Initial CI Blocks");
a61af66fc99e Initial load
duke
parents:
diff changeset
2401 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2403 flow_types();
a61af66fc99e Initial load
duke
parents:
diff changeset
2404 // Watch for bailouts.
a61af66fc99e Initial load
duke
parents:
diff changeset
2405 if (failing()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2406 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2408 if (CIPrintTypeFlow || CITraceTypeFlow) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2409 print_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
2410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2411 map_blocks();
a61af66fc99e Initial load
duke
parents:
diff changeset
2412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2413
a61af66fc99e Initial load
duke
parents:
diff changeset
2414 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2415 // ciTypeFlow::record_failure()
a61af66fc99e Initial load
duke
parents:
diff changeset
2416 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
a61af66fc99e Initial load
duke
parents:
diff changeset
2417 // This is required because there is not a 1-1 relation between the ciEnv and
a61af66fc99e Initial load
duke
parents:
diff changeset
2418 // the TypeFlow passes within a compilation task. For example, if the compiler
a61af66fc99e Initial load
duke
parents:
diff changeset
2419 // is considering inlining a method, it will request a TypeFlow. If that fails,
a61af66fc99e Initial load
duke
parents:
diff changeset
2420 // the compilation as a whole may continue without the inlining. Some TypeFlow
a61af66fc99e Initial load
duke
parents:
diff changeset
2421 // requests are not optional; if they fail the requestor is responsible for
a61af66fc99e Initial load
duke
parents:
diff changeset
2422 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
a61af66fc99e Initial load
duke
parents:
diff changeset
2423 void ciTypeFlow::record_failure(const char* reason) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2424 if (env()->log() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2425 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
a61af66fc99e Initial load
duke
parents:
diff changeset
2426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2427 if (_failure_reason == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2428 // Record the first failure reason.
a61af66fc99e Initial load
duke
parents:
diff changeset
2429 _failure_reason = reason;
a61af66fc99e Initial load
duke
parents:
diff changeset
2430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2432
a61af66fc99e Initial load
duke
parents:
diff changeset
2433 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2434 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2435 // ciTypeFlow::print_on
a61af66fc99e Initial load
duke
parents:
diff changeset
2436 void ciTypeFlow::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
2437 // Walk through CI blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
2438 st->print_cr("********************************************************");
a61af66fc99e Initial load
duke
parents:
diff changeset
2439 st->print ("TypeFlow for ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2440 method()->name()->print_symbol_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
2441 int limit_bci = code_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
2442 st->print_cr(" %d bytes", limit_bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2443 ciMethodBlocks *mblks = _methodBlocks;
a61af66fc99e Initial load
duke
parents:
diff changeset
2444 ciBlock* current = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2445 for (int bci = 0; bci < limit_bci; bci++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2446 ciBlock* blk = mblks->block_containing(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
2447 if (blk != NULL && blk != current) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2448 current = blk;
a61af66fc99e Initial load
duke
parents:
diff changeset
2449 current->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
2450
a61af66fc99e Initial load
duke
parents:
diff changeset
2451 GrowableArray<Block*>* blocks = _idx_to_blocklist[blk->index()];
a61af66fc99e Initial load
duke
parents:
diff changeset
2452 int num_blocks = (blocks == NULL) ? 0 : blocks->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
2453
a61af66fc99e Initial load
duke
parents:
diff changeset
2454 if (num_blocks == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2455 st->print_cr(" No Blocks");
a61af66fc99e Initial load
duke
parents:
diff changeset
2456 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2457 for (int i = 0; i < num_blocks; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2458 Block* block = blocks->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2459 block->print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
2460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2462 st->print_cr("--------------------------------------------------------");
a61af66fc99e Initial load
duke
parents:
diff changeset
2463 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2466 st->print_cr("********************************************************");
a61af66fc99e Initial load
duke
parents:
diff changeset
2467 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
2468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2469 #endif