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 "precompiled.hpp"
26 #include "c1/c1_IR.hpp"
27 #include "c1/c1_Instruction.hpp"
28 #include "c1/c1_InstructionPrinter.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciObjArrayKlass.hpp"
31 #include "ci/ciTypeArrayKlass.hpp"
32 #include "utilities/bitMap.inline.hpp"
33
34
35 // Implementation of Instruction
36
37
38 int Instruction::dominator_depth() {
39 int result = -1;
40 if (block()) {
41 result = block()->dominator_depth();
42 }
43 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
44 return result;
45 }
46
47 Instruction::Condition Instruction::mirror(Condition cond) {
48 switch (cond) {
49 case eql: return eql;
89 Instruction* p = nullptr;
90 Instruction* q = block();
91 while (q != this) {
92 assert(q != nullptr, "this is not in the block's instruction list");
93 p = q; q = q->next();
94 }
95 return p;
96 }
97
98
99 void Instruction::state_values_do(ValueVisitor* f) {
100 if (state_before() != nullptr) {
101 state_before()->values_do(f);
102 }
103 if (exception_state() != nullptr) {
104 exception_state()->values_do(f);
105 }
106 }
107
108 ciType* Instruction::exact_type() const {
109 ciType* t = declared_type();
110 if (t != nullptr && t->is_klass()) {
111 return t->as_klass()->exact_klass();
112 }
113 return nullptr;
114 }
115
116
117 #ifndef PRODUCT
118 void Instruction::check_state(ValueStack* state) {
119 if (state != nullptr) {
120 state->verify();
121 }
122 }
123
124
125 void Instruction::print() {
126 InstructionPrinter ip;
127 print(ip);
128 }
129
130
131 void Instruction::print_line() {
132 InstructionPrinter ip;
133 ip.print_line(this);
134 }
135
156 }
157 }
158
159 if (!this->check_flag(NeedsRangeCheckFlag)) {
160 return false;
161 }
162
163 return true;
164 }
165
166
167 ciType* Constant::exact_type() const {
168 if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
169 return type()->as_ObjectType()->exact_type();
170 }
171 return nullptr;
172 }
173
174 ciType* LoadIndexed::exact_type() const {
175 ciType* array_type = array()->exact_type();
176 if (array_type != nullptr) {
177 assert(array_type->is_array_klass(), "what else?");
178 ciArrayKlass* ak = (ciArrayKlass*)array_type;
179
180 if (ak->element_type()->is_instance_klass()) {
181 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
182 if (ik->is_loaded() && ik->is_final()) {
183 return ik;
184 }
185 }
186 }
187 return Instruction::exact_type();
188 }
189
190
191 ciType* LoadIndexed::declared_type() const {
192 ciType* array_type = array()->declared_type();
193 if (array_type == nullptr || !array_type->is_loaded()) {
194 return nullptr;
195 }
196 assert(array_type->is_array_klass(), "what else?");
197 ciArrayKlass* ak = (ciArrayKlass*)array_type;
198 return ak->element_type();
199 }
200
201
202 ciType* LoadField::declared_type() const {
203 return field()->type();
204 }
205
206
207 ciType* NewTypeArray::exact_type() const {
208 return ciTypeArrayKlass::make(elt_type());
209 }
210
211 ciType* NewObjectArray::exact_type() const {
212 return ciObjArrayKlass::make(klass());
213 }
214
215 ciType* NewArray::declared_type() const {
216 return exact_type();
217 }
218
219 ciType* NewInstance::exact_type() const {
220 return klass();
221 }
222
223 ciType* NewInstance::declared_type() const {
224 return exact_type();
225 }
226
227 ciType* CheckCast::declared_type() const {
228 return klass();
229 }
230
231 // Implementation of ArithmeticOp
232
302 }
303
304
305 void StateSplit::state_values_do(ValueVisitor* f) {
306 Instruction::state_values_do(f);
307 if (state() != nullptr) state()->values_do(f);
308 }
309
310
311 void BlockBegin::state_values_do(ValueVisitor* f) {
312 StateSplit::state_values_do(f);
313
314 if (is_set(BlockBegin::exception_entry_flag)) {
315 for (int i = 0; i < number_of_exception_states(); i++) {
316 exception_state_at(i)->values_do(f);
317 }
318 }
319 }
320
321
322 // Implementation of Invoke
323
324
325 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
326 ciMethod* target, ValueStack* state_before)
327 : StateSplit(result_type, state_before)
328 , _code(code)
329 , _recv(recv)
330 , _args(args)
331 , _target(target)
332 {
333 set_flag(TargetIsLoadedFlag, target->is_loaded());
334 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
335
336 assert(args != nullptr, "args must exist");
337 #ifdef ASSERT
338 AssertValues assert_value;
339 values_do(&assert_value);
340 #endif
341
342 // provide an initial guess of signature size.
343 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
344 if (has_receiver()) {
345 _signature->append(as_BasicType(receiver()->type()));
346 }
347 for (int i = 0; i < number_of_arguments(); i++) {
348 ValueType* t = argument_at(i)->type();
349 BasicType bt = as_BasicType(t);
350 _signature->append(bt);
351 }
352 }
353
354
355 void Invoke::state_values_do(ValueVisitor* f) {
356 StateSplit::state_values_do(f);
357 if (state_before() != nullptr) state_before()->values_do(f);
358 if (state() != nullptr) state()->values_do(f);
359 }
360
361 ciType* Invoke::declared_type() const {
362 ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
363 ciType *t = declared_signature->return_type();
364 assert(t->basic_type() != T_VOID, "need return value of void method?");
365 return t;
366 }
367
368 // Implementation of Constant
971 ip1.print_instr(x);
972
973 stringStream strStream2;
974 InstructionPrinter ip2(1, &strStream2);
975 ip2.print_instr(y);
976
977 stringStream ss;
978 ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
979
980 _message = ss.as_string();
981 }
982 #endif
983
984 void RangeCheckPredicate::check_state() {
985 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
986 }
987
988 void ProfileInvoke::state_values_do(ValueVisitor* f) {
989 if (state() != nullptr) state()->values_do(f);
990 }
|
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 "precompiled.hpp"
26 #include "c1/c1_IR.hpp"
27 #include "c1/c1_Instruction.hpp"
28 #include "c1/c1_InstructionPrinter.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciFlatArrayKlass.hpp"
31 #include "ci/ciInlineKlass.hpp"
32 #include "ci/ciObjArrayKlass.hpp"
33 #include "ci/ciTypeArrayKlass.hpp"
34 #include "utilities/bitMap.inline.hpp"
35
36
37 // Implementation of Instruction
38
39
40 int Instruction::dominator_depth() {
41 int result = -1;
42 if (block()) {
43 result = block()->dominator_depth();
44 }
45 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
46 return result;
47 }
48
49 Instruction::Condition Instruction::mirror(Condition cond) {
50 switch (cond) {
51 case eql: return eql;
91 Instruction* p = nullptr;
92 Instruction* q = block();
93 while (q != this) {
94 assert(q != nullptr, "this is not in the block's instruction list");
95 p = q; q = q->next();
96 }
97 return p;
98 }
99
100
101 void Instruction::state_values_do(ValueVisitor* f) {
102 if (state_before() != nullptr) {
103 state_before()->values_do(f);
104 }
105 if (exception_state() != nullptr) {
106 exception_state()->values_do(f);
107 }
108 }
109
110 ciType* Instruction::exact_type() const {
111 ciType* t = declared_type();
112 if (t != nullptr && t->is_klass()) {
113 return t->as_klass()->exact_klass();
114 }
115 return nullptr;
116 }
117
118 ciKlass* Instruction::as_loaded_klass_or_null() const {
119 ciType* type = declared_type();
120 if (type != nullptr && type->is_klass()) {
121 ciKlass* klass = type->as_klass();
122 if (klass->is_loaded()) {
123 return klass;
124 }
125 }
126 return nullptr;
127 }
128
129 bool Instruction::is_loaded_flat_array() const {
130 if (UseFlatArray) {
131 ciType* type = declared_type();
132 return type != nullptr && type->is_flat_array_klass();
133 }
134 return false;
135 }
136
137 bool Instruction::maybe_flat_array() {
138 if (UseFlatArray) {
139 ciType* type = declared_type();
140 if (type != nullptr) {
141 if (type->is_obj_array_klass()) {
142 // TODO 8325106 Fix comment
143 // The runtime type of [LMyValue might be [QMyValue due to [QMyValue <: [LMyValue.
144 ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
145 if (element_klass->can_be_inline_klass() && (!element_klass->is_inlinetype() || element_klass->as_inline_klass()->flat_in_array())) {
146 return true;
147 }
148 } else if (type->is_flat_array_klass()) {
149 return true;
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 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
412 #ifdef ASSERT
413 AssertValues assert_value;
414 values_do(&assert_value);
415 #endif
416 pin();
417 }
418
419 StoreIndexed::StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value,
420 ValueStack* state_before, bool check_boolean, bool mismatched)
421 : AccessIndexed(array, index, length, elt_type, state_before, mismatched)
422 , _value(value), _check_boolean(check_boolean)
423 {
424 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
425 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
426 #ifdef ASSERT
427 AssertValues assert_value;
428 values_do(&assert_value);
429 #endif
430 pin();
431 }
432
433
434 // Implementation of Invoke
435
436
437 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
438 ciMethod* target, ValueStack* state_before)
439 : StateSplit(result_type, state_before)
440 , _code(code)
441 , _recv(recv)
442 , _args(args)
443 , _target(target)
444 {
445 set_flag(TargetIsLoadedFlag, target->is_loaded());
446 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
447
448 assert(args != nullptr, "args must exist");
449 #ifdef ASSERT
450 AssertValues assert_value;
451 values_do(&assert_value);
452 #endif
453
454 // provide an initial guess of signature size.
455 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
456 if (has_receiver()) {
457 _signature->append(as_BasicType(receiver()->type()));
458 }
459 for (int i = 0; i < number_of_arguments(); i++) {
460 Value v = argument_at(i);
461 ValueType* t = v->type();
462 BasicType bt = as_BasicType(t);
463 _signature->append(bt);
464 }
465 }
466
467
468 void Invoke::state_values_do(ValueVisitor* f) {
469 StateSplit::state_values_do(f);
470 if (state_before() != nullptr) state_before()->values_do(f);
471 if (state() != nullptr) state()->values_do(f);
472 }
473
474 ciType* Invoke::declared_type() const {
475 ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
476 ciType *t = declared_signature->return_type();
477 assert(t->basic_type() != T_VOID, "need return value of void method?");
478 return t;
479 }
480
481 // Implementation of Constant
1084 ip1.print_instr(x);
1085
1086 stringStream strStream2;
1087 InstructionPrinter ip2(1, &strStream2);
1088 ip2.print_instr(y);
1089
1090 stringStream ss;
1091 ss.print("Assertion %s %s %s in method %s", strStream1.freeze(), ip2.cond_name(cond), strStream2.freeze(), strStream.freeze());
1092
1093 _message = ss.as_string();
1094 }
1095 #endif
1096
1097 void RangeCheckPredicate::check_state() {
1098 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
1099 }
1100
1101 void ProfileInvoke::state_values_do(ValueVisitor* f) {
1102 if (state() != nullptr) state()->values_do(f);
1103 }
1104
|