< prev index next >

src/hotspot/share/opto/type.cpp

Print this page




  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 "ci/ciMethodData.hpp"
  27 #include "ci/ciTypeFlow.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "compiler/compileLog.hpp"


  31 #include "libadt/dict.hpp"
  32 #include "memory/oopFactory.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/instanceKlass.hpp"
  35 #include "oops/instanceMirrorKlass.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/typeArrayKlass.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/node.hpp"
  40 #include "opto/opcodes.hpp"
  41 #include "opto/type.hpp"
  42 
  43 // Portions of code courtesy of Clifford Click
  44 
  45 // Optimization - Graph Style
  46 
  47 // Dictionary of types shared among compilations.
  48 Dict* Type::_shared_type_dict = NULL;
  49 
  50 // Array which maps compiler types to Basic Types


3027   bool      xk = false;
3028   ciObject* o = NULL;
3029   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3030 }
3031 
3032 
3033 //------------------------------cast_to_ptr_type-------------------------------
3034 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3035   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3036   if( ptr == _ptr ) return this;
3037   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3038 }
3039 
3040 //-----------------------------cast_to_instance_id----------------------------
3041 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3042   // There are no instances of a general oop.
3043   // Return self unchanged.
3044   return this;
3045 }
3046 




3047 //-----------------------------cast_to_exactness-------------------------------
3048 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3049   // There is no such thing as an exact general oop.
3050   // Return self unchanged.
3051   return this;
3052 }
3053 
3054 
3055 //------------------------------as_klass_type----------------------------------
3056 // Return the klass type corresponding to this instance or array type.
3057 // It is the type that is loaded from an object of this type.
3058 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3059   ciKlass* k = klass();
3060   bool    xk = klass_is_exact();
3061   if (k == NULL)
3062     return TypeKlassPtr::OBJECT;
3063   else
3064     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
3065 }
3066 


3529 }
3530 
3531 
3532 //-----------------------------cast_to_exactness-------------------------------
3533 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3534   if( klass_is_exact == _klass_is_exact ) return this;
3535   if (!UseExactTypes)  return this;
3536   if (!_klass->is_loaded())  return this;
3537   ciInstanceKlass* ik = _klass->as_instance_klass();
3538   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3539   if( ik->is_interface() )              return this;  // cannot set xk
3540   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3541 }
3542 
3543 //-----------------------------cast_to_instance_id----------------------------
3544 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3545   if( instance_id == _instance_id ) return this;
3546   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3547 }
3548 





3549 //------------------------------xmeet_unloaded---------------------------------
3550 // Compute the MEET of two InstPtrs when at least one is unloaded.
3551 // Assume classes are different since called after check for same name/class-loader
3552 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3553     int off = meet_offset(tinst->offset());
3554     PTR ptr = meet_ptr(tinst->ptr());
3555     int instance_id = meet_instance_id(tinst->instance_id());
3556     const TypePtr* speculative = xmeet_speculative(tinst);
3557     int depth = meet_inline_depth(tinst->inline_depth());
3558 
3559     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3560     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3561     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3562       //
3563       // Meet unloaded class with java/lang/Object
3564       //
3565       // Meet
3566       //          |                     Unloaded Class
3567       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3568       //  ===================================================================


4055 //------------------------------cast_to_ptr_type-------------------------------
4056 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4057   if( ptr == _ptr ) return this;
4058   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4059 }
4060 
4061 
4062 //-----------------------------cast_to_exactness-------------------------------
4063 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4064   if( klass_is_exact == _klass_is_exact ) return this;
4065   if (!UseExactTypes)  return this;
4066   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4067   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4068 }
4069 
4070 //-----------------------------cast_to_instance_id----------------------------
4071 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4072   if( instance_id == _instance_id ) return this;
4073   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4074 }






4075 
4076 //-----------------------------narrow_size_type-------------------------------
4077 // Local cache for arrayOopDesc::max_array_length(etype),
4078 // which is kind of slow (and cached elsewhere by other users).
4079 static jint max_array_length_cache[T_CONFLICT+1];
4080 static jint max_array_length(BasicType etype) {
4081   jint& cache = max_array_length_cache[etype];
4082   jint res = cache;
4083   if (res == 0) {
4084     switch (etype) {
4085     case T_NARROWOOP:
4086       etype = T_OBJECT;
4087       break;
4088     case T_NARROWKLASS:
4089     case T_CONFLICT:
4090     case T_ILLEGAL:
4091     case T_VOID:
4092       etype = T_BYTE;           // will produce conservatively high value
4093       break;
4094     default:




  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 "ci/ciMethodData.hpp"
  27 #include "ci/ciTypeFlow.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "gc/shared/barrierSet.hpp"
  32 #include "gc/shared/c2/barrierSetC2.hpp"
  33 #include "libadt/dict.hpp"
  34 #include "memory/oopFactory.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/instanceMirrorKlass.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/typeArrayKlass.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/node.hpp"
  42 #include "opto/opcodes.hpp"
  43 #include "opto/type.hpp"
  44 
  45 // Portions of code courtesy of Clifford Click
  46 
  47 // Optimization - Graph Style
  48 
  49 // Dictionary of types shared among compilations.
  50 Dict* Type::_shared_type_dict = NULL;
  51 
  52 // Array which maps compiler types to Basic Types


3029   bool      xk = false;
3030   ciObject* o = NULL;
3031   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3032 }
3033 
3034 
3035 //------------------------------cast_to_ptr_type-------------------------------
3036 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3037   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3038   if( ptr == _ptr ) return this;
3039   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3040 }
3041 
3042 //-----------------------------cast_to_instance_id----------------------------
3043 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3044   // There are no instances of a general oop.
3045   // Return self unchanged.
3046   return this;
3047 }
3048 
3049 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
3050   return this;
3051 }
3052 
3053 //-----------------------------cast_to_exactness-------------------------------
3054 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3055   // There is no such thing as an exact general oop.
3056   // Return self unchanged.
3057   return this;
3058 }
3059 
3060 
3061 //------------------------------as_klass_type----------------------------------
3062 // Return the klass type corresponding to this instance or array type.
3063 // It is the type that is loaded from an object of this type.
3064 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3065   ciKlass* k = klass();
3066   bool    xk = klass_is_exact();
3067   if (k == NULL)
3068     return TypeKlassPtr::OBJECT;
3069   else
3070     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
3071 }
3072 


3535 }
3536 
3537 
3538 //-----------------------------cast_to_exactness-------------------------------
3539 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3540   if( klass_is_exact == _klass_is_exact ) return this;
3541   if (!UseExactTypes)  return this;
3542   if (!_klass->is_loaded())  return this;
3543   ciInstanceKlass* ik = _klass->as_instance_klass();
3544   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3545   if( ik->is_interface() )              return this;  // cannot set xk
3546   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3547 }
3548 
3549 //-----------------------------cast_to_instance_id----------------------------
3550 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3551   if( instance_id == _instance_id ) return this;
3552   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3553 }
3554 
3555 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3556   if (const_oop() == NULL) return this;
3557   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3558 }
3559 
3560 //------------------------------xmeet_unloaded---------------------------------
3561 // Compute the MEET of two InstPtrs when at least one is unloaded.
3562 // Assume classes are different since called after check for same name/class-loader
3563 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3564     int off = meet_offset(tinst->offset());
3565     PTR ptr = meet_ptr(tinst->ptr());
3566     int instance_id = meet_instance_id(tinst->instance_id());
3567     const TypePtr* speculative = xmeet_speculative(tinst);
3568     int depth = meet_inline_depth(tinst->inline_depth());
3569 
3570     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3571     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3572     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3573       //
3574       // Meet unloaded class with java/lang/Object
3575       //
3576       // Meet
3577       //          |                     Unloaded Class
3578       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3579       //  ===================================================================


4066 //------------------------------cast_to_ptr_type-------------------------------
4067 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4068   if( ptr == _ptr ) return this;
4069   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4070 }
4071 
4072 
4073 //-----------------------------cast_to_exactness-------------------------------
4074 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4075   if( klass_is_exact == _klass_is_exact ) return this;
4076   if (!UseExactTypes)  return this;
4077   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4078   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4079 }
4080 
4081 //-----------------------------cast_to_instance_id----------------------------
4082 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4083   if( instance_id == _instance_id ) return this;
4084   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4085 }
4086 
4087 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4088   if (const_oop() == NULL) return this;
4089   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4090 }
4091 
4092 
4093 //-----------------------------narrow_size_type-------------------------------
4094 // Local cache for arrayOopDesc::max_array_length(etype),
4095 // which is kind of slow (and cached elsewhere by other users).
4096 static jint max_array_length_cache[T_CONFLICT+1];
4097 static jint max_array_length(BasicType etype) {
4098   jint& cache = max_array_length_cache[etype];
4099   jint res = cache;
4100   if (res == 0) {
4101     switch (etype) {
4102     case T_NARROWOOP:
4103       etype = T_OBJECT;
4104       break;
4105     case T_NARROWKLASS:
4106     case T_CONFLICT:
4107     case T_ILLEGAL:
4108     case T_VOID:
4109       etype = T_BYTE;           // will produce conservatively high value
4110       break;
4111     default:


< prev index next >