< prev index next >

src/hotspot/share/c1/c1_Instruction.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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 "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 
  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;
  49     case neq: return neq;
  50     case lss: return gtr;
  51     case leq: return geq;


  95 }
  96 
  97 
  98 void Instruction::state_values_do(ValueVisitor* f) {
  99   if (state_before() != NULL) {
 100     state_before()->values_do(f);
 101   }
 102   if (exception_state() != NULL){
 103     exception_state()->values_do(f);
 104   }
 105 }
 106 
 107 ciType* Instruction::exact_type() const {
 108   ciType* t =  declared_type();
 109   if (t != NULL && t->is_klass()) {
 110     return t->as_klass()->exact_klass();
 111   }
 112   return NULL;
 113 }
 114 

















































































 115 
 116 #ifndef PRODUCT
 117 void Instruction::check_state(ValueStack* state) {
 118   if (state != NULL) {
 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 


 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 == NULL || !array_type->is_loaded()) {
 193     return NULL;
 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 
 232 bool ArithmeticOp::is_commutative() const {
 233   switch (op()) {
 234     case Bytecodes::_iadd: // fall through
 235     case Bytecodes::_ladd: // fall through
 236     case Bytecodes::_fadd: // fall through
 237     case Bytecodes::_dadd: // fall through
 238     case Bytecodes::_imul: // fall through
 239     case Bytecodes::_lmul: // fall through
 240     case Bytecodes::_fmul: // fall through
 241     case Bytecodes::_dmul: return true;
 242     default              : return false;
 243   }
 244 }
 245 


 305   Instruction::state_values_do(f);
 306   if (state() != NULL) 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                int vtable_index, ciMethod* target, ValueStack* state_before)
 326   : StateSplit(result_type, state_before)
 327   , _code(code)
 328   , _recv(recv)
 329   , _args(args)
 330   , _vtable_index(vtable_index)
 331   , _target(target)
 332 {
 333   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 334   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 335   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());

 336 
 337   assert(args != NULL, "args must exist");
 338 #ifdef ASSERT
 339   AssertValues assert_value;
 340   values_do(&assert_value);
 341 #endif
 342 
 343   // provide an initial guess of signature size.
 344   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 345   if (has_receiver()) {
 346     _signature->append(as_BasicType(receiver()->type()));
 347   }
 348   for (int i = 0; i < number_of_arguments(); i++) {
 349     ValueType* t = argument_at(i)->type();
 350     BasicType bt = as_BasicType(t);
 351     _signature->append(bt);
 352   }
 353 }
 354 
 355 


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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 "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 "ci/ciValueArrayKlass.hpp"
  33 #include "ci/ciValueKlass.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;
  51     case neq: return neq;
  52     case lss: return gtr;
  53     case leq: return geq;


  97 }
  98 
  99 
 100 void Instruction::state_values_do(ValueVisitor* f) {
 101   if (state_before() != NULL) {
 102     state_before()->values_do(f);
 103   }
 104   if (exception_state() != NULL){
 105     exception_state()->values_do(f);
 106   }
 107 }
 108 
 109 ciType* Instruction::exact_type() const {
 110   ciType* t =  declared_type();
 111   if (t != NULL && t->is_klass()) {
 112     return t->as_klass()->exact_klass();
 113   }
 114   return NULL;
 115 }
 116 
 117 ciKlass* Instruction::as_loaded_klass_or_null() const {
 118   ciType* type = declared_type();
 119   if (type != NULL && type->is_klass()) {
 120     ciKlass* klass = type->as_klass();
 121     if (klass->is_loaded()) {
 122       return klass;
 123     }
 124   }
 125   return NULL;
 126 }
 127 
 128 bool Instruction::is_loaded_flattened_array() const {
 129   if (ValueArrayFlatten) {
 130     ciType* type = declared_type();
 131     if (type != NULL && type->is_value_array_klass()) {
 132       ciValueArrayKlass* vak = type->as_value_array_klass();
 133       ArrayStorageProperties props = vak->storage_properties();
 134       return (!props.is_empty() && props.is_null_free() && props.is_flattened());
 135     }
 136   }
 137 
 138   return false;
 139 }
 140 
 141 bool Instruction::maybe_flattened_array() {
 142   if (ValueArrayFlatten) {
 143     ciType* type = declared_type();
 144     if (type != NULL) {
 145       if (type->is_obj_array_klass()) {
 146         // Check for array covariance. One of the following declared types may be a flattened array:
 147         ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
 148         if (!element_klass->is_loaded() ||
 149             element_klass->is_java_lang_Object() ||                                                // (ValueType[] <: Object[])
 150             element_klass->is_interface() ||                                                       // (ValueType[] <: <any interface>[])
 151             (element_klass->is_valuetype() && element_klass->as_value_klass()->flatten_array())) { // (ValueType[] <: ValueType?[])
 152           // We will add a runtime check for flat-ness.
 153           return true;
 154         }
 155       } else if (type->is_value_array_klass()) {
 156         ciKlass* element_klass = type->as_value_array_klass()->element_klass();
 157         if (!element_klass->is_loaded() ||
 158             (element_klass->is_valuetype() && element_klass->as_value_klass()->flatten_array())) { // (ValueType[] <: ValueType?[])
 159           // We will add a runtime check for flat-ness.
 160           return true;
 161         }
 162       } else if (type->is_klass() && type->as_klass()->is_java_lang_Object()) {
 163         // This can happen as a parameter to System.arraycopy()
 164         return true;
 165       }
 166     } else {
 167       // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
 168       // flattened array, so we should do a runtime check.
 169       return true;
 170     }
 171   }
 172 
 173   return false;
 174 }
 175 
 176 bool Instruction::maybe_null_free_array() {
 177   ciType* type = declared_type();
 178   if (type != NULL) {
 179     if (type->is_obj_array_klass()) {
 180       // Check for array covariance. One of the following declared types may be a null-free array:
 181       ciKlass* element_klass = type->as_obj_array_klass()->element_klass();
 182       if (!element_klass->is_loaded() ||
 183           element_klass->is_java_lang_Object() ||   // (ValueType[] <: Object[])
 184           element_klass->is_interface() ||          // (ValueType[] <: <any interface>[])
 185           element_klass->is_valuetype()) {          // (ValueType[] <: ValueType?[])
 186           // We will add a runtime check for flat-ness.
 187           return true;
 188       }
 189     }
 190   } else {
 191     // Type info gets lost during Phi merging (Phi, IfOp, etc), but we might be storing into a
 192     // flattened array, so we should do a runtime check.
 193     return true;
 194   }
 195 
 196   return false;
 197 }
 198 
 199 #ifndef PRODUCT
 200 void Instruction::check_state(ValueStack* state) {
 201   if (state != NULL) {
 202     state->verify();
 203   }
 204 }
 205 
 206 
 207 void Instruction::print() {
 208   InstructionPrinter ip;
 209   print(ip);
 210 }
 211 
 212 
 213 void Instruction::print_line() {
 214   InstructionPrinter ip;
 215   ip.print_line(this);
 216 }
 217 


 263       ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
 264       if (ik->is_loaded() && ik->is_final()) {
 265         return ik;
 266       }
 267     }
 268   }
 269   return Instruction::exact_type();
 270 }
 271 
 272 
 273 ciType* LoadIndexed::declared_type() const {
 274   ciType* array_type = array()->declared_type();
 275   if (array_type == NULL || !array_type->is_loaded()) {
 276     return NULL;
 277   }
 278   assert(array_type->is_array_klass(), "what else?");
 279   ciArrayKlass* ak = (ciArrayKlass*)array_type;
 280   return ak->element_type();
 281 }
 282 
 283 bool StoreIndexed::is_exact_flattened_array_store() const {
 284   if (array()->is_loaded_flattened_array() && value()->as_Constant() == NULL && value()->declared_type() != NULL) {
 285     ciKlass* element_klass = array()->declared_type()->as_value_array_klass()->element_klass();
 286     ciKlass* actual_klass = value()->declared_type()->as_klass();
 287 
 288     // The following check can fail with inlining:
 289     //     void test45_inline(Object[] oa, Object o, int index) { oa[index] = o; }
 290     //     void test45(MyValue1[] va, int index, MyValue2 v) { test45_inline(va, v, index); }
 291     if (element_klass == actual_klass) {
 292       return true;
 293     }
 294   }
 295   return false;
 296 }
 297 
 298 ciType* LoadField::declared_type() const {
 299   return field()->type();
 300 }
 301 
 302 
 303 ciType* NewTypeArray::exact_type() const {
 304   return ciTypeArrayKlass::make(elt_type());
 305 }
 306 
 307 ciType* NewObjectArray::exact_type() const {
 308   ciKlass* element_klass = klass();
 309   if (is_never_null() && element_klass->is_valuetype()) {
 310     if (element_klass->as_value_klass()->flatten_array()) {
 311       return ciValueArrayKlass::make(element_klass);
 312     } else {
 313       return ciObjArrayKlass::make(element_klass, /*never_null =*/true);
 314     }
 315   } else {
 316     return ciObjArrayKlass::make(element_klass);
 317   }
 318 }
 319 
 320 ciType* NewMultiArray::exact_type() const {
 321   return _klass;
 322 }
 323 
 324 ciType* NewArray::declared_type() const {
 325   return exact_type();
 326 }
 327 
 328 ciType* NewInstance::exact_type() const {
 329   return klass();
 330 }
 331 
 332 ciType* NewInstance::declared_type() const {
 333   return exact_type();
 334 }
 335 
 336 Value NewValueTypeInstance::depends_on() {
 337   if (_depends_on != this) {
 338     if (_depends_on->as_NewValueTypeInstance() != NULL) {
 339       return _depends_on->as_NewValueTypeInstance()->depends_on();
 340     }
 341   }
 342   return _depends_on;
 343 }
 344 
 345 ciType* NewValueTypeInstance::exact_type() const {
 346   return klass();
 347 }
 348 
 349 ciType* NewValueTypeInstance::declared_type() const {
 350   return exact_type();
 351 }
 352 
 353 ciType* CheckCast::declared_type() const {
 354   return klass();
 355 }
 356 
 357 // Implementation of ArithmeticOp
 358 
 359 bool ArithmeticOp::is_commutative() const {
 360   switch (op()) {
 361     case Bytecodes::_iadd: // fall through
 362     case Bytecodes::_ladd: // fall through
 363     case Bytecodes::_fadd: // fall through
 364     case Bytecodes::_dadd: // fall through
 365     case Bytecodes::_imul: // fall through
 366     case Bytecodes::_lmul: // fall through
 367     case Bytecodes::_fmul: // fall through
 368     case Bytecodes::_dmul: return true;
 369     default              : return false;
 370   }
 371 }
 372 


 432   Instruction::state_values_do(f);
 433   if (state() != NULL) state()->values_do(f);
 434 }
 435 
 436 
 437 void BlockBegin::state_values_do(ValueVisitor* f) {
 438   StateSplit::state_values_do(f);
 439 
 440   if (is_set(BlockBegin::exception_entry_flag)) {
 441     for (int i = 0; i < number_of_exception_states(); i++) {
 442       exception_state_at(i)->values_do(f);
 443     }
 444   }
 445 }
 446 
 447 
 448 // Implementation of Invoke
 449 
 450 
 451 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
 452                int vtable_index, ciMethod* target, ValueStack* state_before, bool never_null)
 453   : StateSplit(result_type, state_before)
 454   , _code(code)
 455   , _recv(recv)
 456   , _args(args)
 457   , _vtable_index(vtable_index)
 458   , _target(target)
 459 {
 460   set_flag(TargetIsLoadedFlag,   target->is_loaded());
 461   set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
 462   set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
 463   set_never_null(never_null);
 464 
 465   assert(args != NULL, "args must exist");
 466 #ifdef ASSERT
 467   AssertValues assert_value;
 468   values_do(&assert_value);
 469 #endif
 470 
 471   // provide an initial guess of signature size.
 472   _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
 473   if (has_receiver()) {
 474     _signature->append(as_BasicType(receiver()->type()));
 475   }
 476   for (int i = 0; i < number_of_arguments(); i++) {
 477     ValueType* t = argument_at(i)->type();
 478     BasicType bt = as_BasicType(t);
 479     _signature->append(bt);
 480   }
 481 }
 482 
 483 


< prev index next >