9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_Instruction.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_IR.hpp"
28 #include "c1/c1_ValueStack.hpp"
29 #include "ci/ciObjArrayKlass.hpp"
30 #include "ci/ciTypeArrayKlass.hpp"
31 #include "utilities/bitMap.inline.hpp"
32
33
34 // Implementation of Instruction
35
36
37 int Instruction::dominator_depth() {
38 int result = -1;
39 if (block()) {
40 result = block()->dominator_depth();
41 }
42 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
43 return result;
44 }
45
46 Instruction::Condition Instruction::mirror(Condition cond) {
47 switch (cond) {
48 case eql: return eql;
88 Instruction* p = nullptr;
89 Instruction* q = block();
90 while (q != this) {
91 assert(q != nullptr, "this is not in the block's instruction list");
92 p = q; q = q->next();
93 }
94 return p;
95 }
96
97
98 void Instruction::state_values_do(ValueVisitor* f) {
99 if (state_before() != nullptr) {
100 state_before()->values_do(f);
101 }
102 if (exception_state() != nullptr) {
103 exception_state()->values_do(f);
104 }
105 }
106
107 ciType* Instruction::exact_type() const {
108 ciType* t = declared_type();
109 if (t != nullptr && t->is_klass()) {
110 return t->as_klass()->exact_klass();
111 }
112 return nullptr;
113 }
114
115
116 #ifndef PRODUCT
117 void Instruction::check_state(ValueStack* state) {
118 if (state != nullptr) {
119 state->verify();
120 }
121 }
122
123
124 void Instruction::print() {
125 InstructionPrinter ip;
126 print(ip);
127 }
128
129
130 void Instruction::print_line() {
131 InstructionPrinter ip;
132 ip.print_line(this);
133 }
134
155 }
156 }
157
158 if (!this->check_flag(NeedsRangeCheckFlag)) {
159 return false;
160 }
161
162 return true;
163 }
164
165
166 ciType* Constant::exact_type() const {
167 if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
168 return type()->as_ObjectType()->exact_type();
169 }
170 return nullptr;
171 }
172
173 ciType* LoadIndexed::exact_type() const {
174 ciType* array_type = array()->exact_type();
175 if (array_type != nullptr) {
176 assert(array_type->is_array_klass(), "what else?");
177 ciArrayKlass* ak = (ciArrayKlass*)array_type;
178
179 if (ak->element_type()->is_instance_klass()) {
180 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
181 if (ik->is_loaded() && ik->is_final()) {
182 return ik;
183 }
184 }
185 }
186 return Instruction::exact_type();
187 }
188
189
190 ciType* LoadIndexed::declared_type() const {
191 ciType* array_type = array()->declared_type();
192 if (array_type == nullptr || !array_type->is_loaded()) {
193 return nullptr;
194 }
195 assert(array_type->is_array_klass(), "what else?");
196 ciArrayKlass* ak = (ciArrayKlass*)array_type;
197 return ak->element_type();
198 }
199
200
201 ciType* LoadField::declared_type() const {
202 return field()->type();
203 }
204
205
206 ciType* NewTypeArray::exact_type() const {
207 return ciTypeArrayKlass::make(elt_type());
208 }
209
210 ciType* NewObjectArray::exact_type() const {
211 return ciObjArrayKlass::make(klass());
212 }
213
214 ciType* NewArray::declared_type() const {
215 return exact_type();
216 }
217
218 ciType* NewInstance::exact_type() const {
219 return klass();
220 }
221
222 ciType* NewInstance::declared_type() const {
223 return exact_type();
224 }
225
226 ciType* CheckCast::declared_type() const {
227 return klass();
228 }
229
230 // Implementation of ArithmeticOp
231
301 }
302
303
304 void StateSplit::state_values_do(ValueVisitor* f) {
305 Instruction::state_values_do(f);
306 if (state() != nullptr) state()->values_do(f);
307 }
308
309
310 void BlockBegin::state_values_do(ValueVisitor* f) {
311 StateSplit::state_values_do(f);
312
313 if (is_set(BlockBegin::exception_entry_flag)) {
314 for (int i = 0; i < number_of_exception_states(); i++) {
315 exception_state_at(i)->values_do(f);
316 }
317 }
318 }
319
320
321 // Implementation of Invoke
322
323
324 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
325 ciMethod* target, ValueStack* state_before)
326 : StateSplit(result_type, state_before)
327 , _code(code)
328 , _recv(recv)
329 , _args(args)
330 , _target(target)
331 {
332 set_flag(TargetIsLoadedFlag, target->is_loaded());
333 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
334
335 assert(args != nullptr, "args must exist");
336 #ifdef ASSERT
337 AssertValues assert_value;
338 values_do(&assert_value);
339 #endif
340
341 // provide an initial guess of signature size.
342 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
343 if (has_receiver()) {
344 _signature->append(as_BasicType(receiver()->type()));
345 }
346 for (int i = 0; i < number_of_arguments(); i++) {
347 ValueType* t = argument_at(i)->type();
348 BasicType bt = as_BasicType(t);
349 _signature->append(bt);
350 }
351 }
352
353
354 void Invoke::state_values_do(ValueVisitor* f) {
355 StateSplit::state_values_do(f);
356 if (state_before() != nullptr) state_before()->values_do(f);
357 if (state() != nullptr) state()->values_do(f);
358 }
359
360 ciType* Invoke::declared_type() const {
361 ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
362 ciType *t = declared_signature->return_type();
363 assert(t->basic_type() != T_VOID, "need return value of void method?");
364 return t;
365 }
366
367 // Implementation of Constant
972 ip1.print_instr(x);
973
974 stringStream strStream2;
975 InstructionPrinter ip2(1, &strStream2);
976 ip2.print_instr(y);
977
978 stringStream ss;
979 ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
980
981 _message = ss.as_string();
982 }
983 #endif
984
985 void RangeCheckPredicate::check_state() {
986 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
987 }
988
989 void ProfileInvoke::state_values_do(ValueVisitor* f) {
990 if (state() != nullptr) state()->values_do(f);
991 }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_Instruction.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_IR.hpp"
28 #include "c1/c1_ValueStack.hpp"
29 #include "ci/ciFlatArrayKlass.hpp"
30 #include "ci/ciInlineKlass.hpp"
31 #include "ci/ciObjArrayKlass.hpp"
32 #include "ci/ciTypeArrayKlass.hpp"
33 #include "utilities/bitMap.inline.hpp"
34
35
36 // Implementation of Instruction
37
38
39 int Instruction::dominator_depth() {
40 int result = -1;
41 if (block()) {
42 result = block()->dominator_depth();
43 }
44 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
45 return result;
46 }
47
48 Instruction::Condition Instruction::mirror(Condition cond) {
49 switch (cond) {
50 case eql: return eql;
90 Instruction* p = nullptr;
91 Instruction* q = block();
92 while (q != this) {
93 assert(q != nullptr, "this is not in the block's instruction list");
94 p = q; q = q->next();
95 }
96 return p;
97 }
98
99
100 void Instruction::state_values_do(ValueVisitor* f) {
101 if (state_before() != nullptr) {
102 state_before()->values_do(f);
103 }
104 if (exception_state() != nullptr) {
105 exception_state()->values_do(f);
106 }
107 }
108
109 ciType* Instruction::exact_type() const {
110 ciType* t = declared_type();
111 if (t != nullptr && t->is_klass()) {
112 return t->as_klass()->exact_klass();
113 }
114 return nullptr;
115 }
116
117 ciKlass* Instruction::as_loaded_klass_or_null() const {
118 ciType* type = declared_type();
119 if (type != nullptr && type->is_klass()) {
120 ciKlass* klass = type->as_klass();
121 if (klass->is_loaded()) {
122 return klass;
123 }
124 }
125 return nullptr;
126 }
127
128 bool Instruction::is_loaded_flat_array() const {
129 if (UseArrayFlattening) {
130 ciType* type = declared_type();
131 return type != nullptr && type->is_flat_array_klass();
132 }
133 return false;
134 }
135
136 bool Instruction::maybe_flat_array() {
137 if (UseArrayFlattening) {
138 ciType* type = declared_type();
139 if (type != nullptr) {
140 if (type->is_ref_array_klass()) {
141 return false;
142 } else if (type->is_flat_array_klass()) {
143 return true;
144 } else if (type->is_obj_array_klass()) {
145 // This is the unrefined array type
146 ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
147 if (element_klass->can_be_inline_klass() && (!element_klass->is_inlinetype() || element_klass->as_inline_klass()->maybe_flat_in_array())) {
148 return true;
149 }
150 } else if (type->is_klass() && type->as_klass()->is_java_lang_Object()) {
151 // This can happen as a parameter to System.arraycopy()
152 return true;
153 }
154 } else {
155 // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
156 // flat array, so we should do a runtime check.
157 return true;
158 }
159 }
160 return false;
161 }
162
163 bool Instruction::maybe_null_free_array() {
164 ciType* type = declared_type();
165 if (type != nullptr) {
166 if (type->is_obj_array_klass()) {
167 // Due to array covariance, the runtime type might be a null-free array.
168 if (type->as_obj_array_klass()->can_be_inline_array_klass()) {
169 return true;
170 }
171 }
172 } else {
173 // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
174 // null-free array, so we should do a runtime check.
175 return true;
176 }
177 return false;
178 }
179
180 #ifndef PRODUCT
181 void Instruction::check_state(ValueStack* state) {
182 if (state != nullptr) {
183 state->verify();
184 }
185 }
186
187
188 void Instruction::print() {
189 InstructionPrinter ip;
190 print(ip);
191 }
192
193
194 void Instruction::print_line() {
195 InstructionPrinter ip;
196 ip.print_line(this);
197 }
198
219 }
220 }
221
222 if (!this->check_flag(NeedsRangeCheckFlag)) {
223 return false;
224 }
225
226 return true;
227 }
228
229
230 ciType* Constant::exact_type() const {
231 if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
232 return type()->as_ObjectType()->exact_type();
233 }
234 return nullptr;
235 }
236
237 ciType* LoadIndexed::exact_type() const {
238 ciType* array_type = array()->exact_type();
239 if (delayed() == nullptr && array_type != nullptr) {
240 assert(array_type->is_array_klass(), "what else?");
241 ciArrayKlass* ak = (ciArrayKlass*)array_type;
242
243 if (ak->element_type()->is_instance_klass()) {
244 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
245 if (ik->is_loaded() && ik->is_final()) {
246 return ik;
247 }
248 }
249 }
250 return Instruction::exact_type();
251 }
252
253 ciType* LoadIndexed::declared_type() const {
254 if (delayed() != nullptr) {
255 return delayed()->field()->type();
256 }
257 ciType* array_type = array()->declared_type();
258 if (array_type == nullptr || !array_type->is_loaded()) {
259 return nullptr;
260 }
261 assert(array_type->is_array_klass(), "what else?");
262 ciArrayKlass* ak = (ciArrayKlass*)array_type;
263 return ak->element_type();
264 }
265
266 bool StoreIndexed::is_exact_flat_array_store() const {
267 if (array()->is_loaded_flat_array() && value()->as_Constant() == nullptr && value()->declared_type() != nullptr) {
268 ciKlass* element_klass = array()->declared_type()->as_flat_array_klass()->element_klass();
269 ciKlass* actual_klass = value()->declared_type()->as_klass();
270
271 // The following check can fail with inlining:
272 // void test45_inline(Object[] oa, Object o, int index) { oa[index] = o; }
273 // void test45(MyValue1[] va, int index, MyValue2 v) { test45_inline(va, v, index); }
274 if (element_klass == actual_klass) {
275 return true;
276 }
277 }
278 return false;
279 }
280
281 ciType* LoadField::declared_type() const {
282 return field()->type();
283 }
284
285
286 ciType* NewTypeArray::exact_type() const {
287 return ciTypeArrayKlass::make(elt_type());
288 }
289
290 ciType* NewObjectArray::exact_type() const {
291 return ciArrayKlass::make(klass());
292 }
293
294 ciType* NewMultiArray::exact_type() const {
295 return _klass;
296 }
297
298 ciType* NewArray::declared_type() const {
299 return exact_type();
300 }
301
302 ciType* NewInstance::exact_type() const {
303 return klass();
304 }
305
306 ciType* NewInstance::declared_type() const {
307 return exact_type();
308 }
309
310 ciType* CheckCast::declared_type() const {
311 return klass();
312 }
313
314 // Implementation of ArithmeticOp
315
385 }
386
387
388 void StateSplit::state_values_do(ValueVisitor* f) {
389 Instruction::state_values_do(f);
390 if (state() != nullptr) state()->values_do(f);
391 }
392
393
394 void BlockBegin::state_values_do(ValueVisitor* f) {
395 StateSplit::state_values_do(f);
396
397 if (is_set(BlockBegin::exception_entry_flag)) {
398 for (int i = 0; i < number_of_exception_states(); i++) {
399 exception_state_at(i)->values_do(f);
400 }
401 }
402 }
403
404
405 StoreField::StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
406 ValueStack* state_before, bool needs_patching)
407 : AccessField(obj, offset, field, is_static, state_before, needs_patching)
408 , _value(value)
409 , _enclosing_field(nullptr)
410 {
411 #ifdef ASSERT
412 AssertValues assert_value;
413 values_do(&assert_value);
414 #endif
415 pin();
416 }
417
418 StoreIndexed::StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value,
419 ValueStack* state_before, bool check_boolean, bool mismatched)
420 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
421 , _value(value), _check_boolean(check_boolean)
422 {
423 #ifdef ASSERT
424 AssertValues assert_value;
425 values_do(&assert_value);
426 #endif
427 pin();
428 }
429
430
431 // Implementation of Invoke
432
433
434 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
435 ciMethod* target, ValueStack* state_before)
436 : StateSplit(result_type, state_before)
437 , _code(code)
438 , _recv(recv)
439 , _args(args)
440 , _target(target)
441 {
442 set_flag(TargetIsLoadedFlag, target->is_loaded());
443 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
444
445 assert(args != nullptr, "args must exist");
446 #ifdef ASSERT
447 AssertValues assert_value;
448 values_do(&assert_value);
449 #endif
450
451 // provide an initial guess of signature size.
452 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
453 if (has_receiver()) {
454 _signature->append(as_BasicType(receiver()->type()));
455 }
456 for (int i = 0; i < number_of_arguments(); i++) {
457 Value v = argument_at(i);
458 ValueType* t = v->type();
459 BasicType bt = as_BasicType(t);
460 _signature->append(bt);
461 }
462 }
463
464
465 void Invoke::state_values_do(ValueVisitor* f) {
466 StateSplit::state_values_do(f);
467 if (state_before() != nullptr) state_before()->values_do(f);
468 if (state() != nullptr) state()->values_do(f);
469 }
470
471 ciType* Invoke::declared_type() const {
472 ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
473 ciType *t = declared_signature->return_type();
474 assert(t->basic_type() != T_VOID, "need return value of void method?");
475 return t;
476 }
477
478 // Implementation of Constant
1083 ip1.print_instr(x);
1084
1085 stringStream strStream2;
1086 InstructionPrinter ip2(1, &strStream2);
1087 ip2.print_instr(y);
1088
1089 stringStream ss;
1090 ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
1091
1092 _message = ss.as_string();
1093 }
1094 #endif
1095
1096 void RangeCheckPredicate::check_state() {
1097 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
1098 }
1099
1100 void ProfileInvoke::state_values_do(ValueVisitor* f) {
1101 if (state() != nullptr) state()->values_do(f);
1102 }
1103
|