< prev index next >

src/share/vm/opto/type.cpp

Print this page




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


1793     break;
1794   case T_OBJECT:
1795   case T_VALUETYPE:
1796   case T_ARRAY:
1797   case T_BOOLEAN:
1798   case T_CHAR:
1799   case T_FLOAT:
1800   case T_BYTE:
1801   case T_SHORT:
1802   case T_INT:
1803     field_array[TypeFunc::Parms] = get_const_type(return_type);
1804     break;
1805   case T_VOID:
1806     break;
1807   default:
1808     ShouldNotReachHere();
1809   }
1810   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1811 }
1812 

























1813 // Make a TypeTuple from the domain of a method signature
1814 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1815   uint arg_cnt = sig->size();
1816 













1817   uint pos = TypeFunc::Parms;
1818   const Type **field_array;
1819   if (recv != NULL) {
1820     arg_cnt++;
1821     field_array = fields(arg_cnt);




1822     // Use get_const_type here because it respects UseUniqueSubclasses:




1823     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);

1824   } else {
1825     field_array = fields(arg_cnt);
1826   }
1827 
1828   int i = 0;
1829   while (pos < TypeFunc::Parms + arg_cnt) {
1830     ciType* type = sig->type_at(i);
1831 
1832     switch (type->basic_type()) {
1833     case T_LONG:
1834       field_array[pos++] = TypeLong::LONG;
1835       field_array[pos++] = Type::HALF;
1836       break;
1837     case T_DOUBLE:
1838       field_array[pos++] = Type::DOUBLE;
1839       field_array[pos++] = Type::HALF;
1840       break;
1841     case T_OBJECT:
1842     case T_VALUETYPE:
1843     case T_ARRAY:
1844     case T_BOOLEAN:
1845     case T_CHAR:
1846     case T_FLOAT:
1847     case T_BYTE:
1848     case T_SHORT:
1849     case T_INT:
1850       field_array[pos++] = get_const_type(type);
1851       break;










1852     default:
1853       ShouldNotReachHere();
1854     }
1855     i++;
1856   }

1857 
1858   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1859 }
1860 
1861 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1862   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1863 }
1864 
1865 //------------------------------fields-----------------------------------------
1866 // Subroutine call type with space allocated for argument types
1867 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1868 const Type **TypeTuple::fields( uint arg_cnt ) {
1869   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1870   flds[TypeFunc::Control  ] = Type::CONTROL;
1871   flds[TypeFunc::I_O      ] = Type::ABIO;
1872   flds[TypeFunc::Memory   ] = Type::MEMORY;
1873   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1874   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1875 
1876   return flds;
1877 }
1878 


5349     if( _klass_is_exact ) st->print(":exact");
5350     break;
5351   }
5352 
5353   if( _offset ) {               // Dump offset, if any
5354     if( _offset == OffsetBot )      { st->print("+any"); }
5355     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5356     else                            { st->print("+%d", _offset); }
5357   }
5358 
5359   st->print(" *");
5360 }
5361 #endif
5362 
5363 
5364 
5365 //=============================================================================
5366 // Convenience common pre-built types.
5367 
5368 //------------------------------make-------------------------------------------
5369 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5370   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5371 }
5372 
5373 //------------------------------make-------------------------------------------
5374 const TypeFunc *TypeFunc::make(ciMethod* method) {
5375   Compile* C = Compile::current();
5376   const TypeFunc* tf = C->last_tf(method); // check cache
5377   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5378   const TypeTuple *domain;






5379   if (method->is_static()) {
5380     domain = TypeTuple::make_domain(NULL, method->signature());

5381   } else {
5382     domain = TypeTuple::make_domain(method->holder(), method->signature());

5383   }
5384   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5385   tf = TypeFunc::make(domain, range);
5386   C->set_last_tf(method, tf);  // fill cache
5387   return tf;
5388 }
5389 
5390 //------------------------------meet-------------------------------------------
5391 // Compute the MEET of two types.  It returns a new Type object.
5392 const Type *TypeFunc::xmeet( const Type *t ) const {
5393   // Perform a fast test for common case; meeting the same types together.
5394   if( this == t ) return this;  // Meeting same type-rep?
5395 
5396   // Current "this->_base" is Func
5397   switch (t->base()) {          // switch on original type
5398 
5399   case Bottom:                  // Ye Olde Default
5400     return t;
5401 
5402   default:                      // All else is a mistake
5403     typerr(t);
5404 
5405   case Top:
5406     break;
5407   }
5408   return this;                  // Return the double constant
5409 }
5410 
5411 //------------------------------xdual------------------------------------------
5412 // Dual: compute field-by-field dual
5413 const Type *TypeFunc::xdual() const {
5414   return this;
5415 }
5416 
5417 //------------------------------eq---------------------------------------------
5418 // Structural equality check for Type representations
5419 bool TypeFunc::eq( const Type *t ) const {
5420   const TypeFunc *a = (const TypeFunc*)t;
5421   return _domain == a->_domain &&

5422     _range == a->_range;
5423 }
5424 
5425 //------------------------------hash-------------------------------------------
5426 // Type-specific hashing function.
5427 int TypeFunc::hash(void) const {
5428   return (intptr_t)_domain + (intptr_t)_range;
5429 }
5430 
5431 //------------------------------dump2------------------------------------------
5432 // Dump Function Type
5433 #ifndef PRODUCT
5434 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5435   if( _range->cnt() <= Parms )
5436     st->print("void");
5437   else {
5438     uint i;
5439     for (i = Parms; i < _range->cnt()-1; i++) {
5440       _range->field_at(i)->dump2(d,depth,st);
5441       st->print("/");
5442     }
5443     _range->field_at(i)->dump2(d,depth,st);
5444   }
5445   st->print(" ");
5446   st->print("( ");
5447   if( !depth || d[this] ) {     // Check for recursive dump
5448     st->print("...)");
5449     return;
5450   }
5451   d.Insert((void*)this,(void*)this);    // Stop recursion
5452   if (Parms < _domain->cnt())
5453     _domain->field_at(Parms)->dump2(d,depth-1,st);
5454   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5455     st->print(", ");
5456     _domain->field_at(i)->dump2(d,depth-1,st);
5457   }
5458   st->print(" )");
5459 }
5460 #endif
5461 
5462 //------------------------------singleton--------------------------------------
5463 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5464 // constants (Ldi nodes).  Singletons are integer, float or double constants
5465 // or a single symbol.
5466 bool TypeFunc::singleton(void) const {
5467   return false;                 // Never a singleton
5468 }
5469 
5470 bool TypeFunc::empty(void) const {
5471   return false;                 // Never empty
5472 }
5473 
5474 
5475 BasicType TypeFunc::return_type() const{
5476   if (range()->cnt() == TypeFunc::Parms) {


   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 "ci/ciField.hpp"
  27 #include "ci/ciMethodData.hpp"
  28 #include "ci/ciTypeFlow.hpp"
  29 #include "ci/ciValueKlass.hpp"
  30 #include "classfile/symbolTable.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "gc/shared/gcLocker.hpp"
  34 #include "libadt/dict.hpp"
  35 #include "memory/oopFactory.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/instanceKlass.hpp"
  38 #include "oops/instanceMirrorKlass.hpp"
  39 #include "oops/objArrayKlass.hpp"
  40 #include "oops/typeArrayKlass.hpp"
  41 #include "opto/matcher.hpp"
  42 #include "opto/node.hpp"
  43 #include "opto/opcodes.hpp"
  44 #include "opto/type.hpp"
  45 
  46 // Portions of code courtesy of Clifford Click


1794     break;
1795   case T_OBJECT:
1796   case T_VALUETYPE:
1797   case T_ARRAY:
1798   case T_BOOLEAN:
1799   case T_CHAR:
1800   case T_FLOAT:
1801   case T_BYTE:
1802   case T_SHORT:
1803   case T_INT:
1804     field_array[TypeFunc::Parms] = get_const_type(return_type);
1805     break;
1806   case T_VOID:
1807     break;
1808   default:
1809     ShouldNotReachHere();
1810   }
1811   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1812 }
1813 
1814 static int extra_value_fields(ciValueKlass* vk) {
1815   int vt_extra = vk->nof_nonstatic_fields() - 1;
1816   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1817     ciField* f = vk->nonstatic_field_at(j);
1818     BasicType bt = f->type()->basic_type();
1819     assert(bt != T_VALUETYPE, "embedded");
1820     if (bt == T_LONG || bt == T_DOUBLE) {
1821       vt_extra++;
1822     }
1823   }
1824   return vt_extra;
1825 }
1826 
1827 static void collect_value_fields(ciValueKlass* vk, const Type**& field_array, uint& pos) {
1828   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1829     ciField* f = vk->nonstatic_field_at(j);
1830     BasicType bt = f->type()->basic_type();
1831     assert(bt < T_VALUETYPE && bt >= T_BOOLEAN, "not yet supported");
1832     field_array[pos++] = Type::get_const_type(f->type());
1833     if (bt == T_LONG || bt == T_DOUBLE) {
1834       field_array[pos++] = Type::HALF;
1835     }
1836   }
1837 }
1838 
1839 // Make a TypeTuple from the domain of a method signature
1840 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool is_cc) {
1841   uint arg_cnt = sig->size();
1842 
1843   int vt_extra = 0;
1844   if (is_cc) {
1845     for (int i = 0; i < sig->count(); i++) {
1846       ciType* type = sig->type_at(i);
1847       if (type->basic_type() == T_VALUETYPE) {
1848         assert(type->is_valuetype(), "");
1849         ciValueKlass* vk = (ciValueKlass*)type;
1850         vt_extra += extra_value_fields(vk);
1851       }
1852     }
1853     assert(((int)arg_cnt) + vt_extra >= 0, "");
1854   }
1855 
1856   uint pos = TypeFunc::Parms;
1857   const Type **field_array;
1858   if (recv != NULL) {
1859     arg_cnt++;
1860     if (is_cc && recv->is_valuetype()) {
1861       ciValueKlass* vk = (ciValueKlass*)recv;
1862       vt_extra += extra_value_fields(vk);
1863     }
1864     field_array = fields(arg_cnt + vt_extra);
1865     // Use get_const_type here because it respects UseUniqueSubclasses:
1866     if (is_cc && recv->is_valuetype()) {
1867       ciValueKlass* vk = (ciValueKlass*)recv;
1868       collect_value_fields(vk, field_array, pos);
1869     } else {
1870       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1871     }
1872   } else {
1873     field_array = fields(arg_cnt + vt_extra);
1874   }
1875 
1876   int i = 0;
1877   while (pos < TypeFunc::Parms + arg_cnt + vt_extra) {
1878     ciType* type = sig->type_at(i);
1879 
1880     switch (type->basic_type()) {
1881     case T_LONG:
1882       field_array[pos++] = TypeLong::LONG;
1883       field_array[pos++] = Type::HALF;
1884       break;
1885     case T_DOUBLE:
1886       field_array[pos++] = Type::DOUBLE;
1887       field_array[pos++] = Type::HALF;
1888       break;
1889     case T_OBJECT:

1890     case T_ARRAY:
1891     case T_BOOLEAN:
1892     case T_CHAR:
1893     case T_FLOAT:
1894     case T_BYTE:
1895     case T_SHORT:
1896     case T_INT:
1897       field_array[pos++] = get_const_type(type);
1898       break;
1899     case T_VALUETYPE: {
1900       assert(type->is_valuetype(), "");
1901       if (is_cc) {
1902         ciValueKlass* vk = (ciValueKlass*)type;
1903         collect_value_fields(vk, field_array, pos);
1904       } else {
1905         field_array[pos++] = get_const_type(type);
1906       }
1907       break;
1908     }
1909     default:
1910       ShouldNotReachHere();
1911     }
1912     i++;
1913   }
1914   assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "");
1915 
1916   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
1917 }
1918 
1919 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1920   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1921 }
1922 
1923 //------------------------------fields-----------------------------------------
1924 // Subroutine call type with space allocated for argument types
1925 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1926 const Type **TypeTuple::fields( uint arg_cnt ) {
1927   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1928   flds[TypeFunc::Control  ] = Type::CONTROL;
1929   flds[TypeFunc::I_O      ] = Type::ABIO;
1930   flds[TypeFunc::Memory   ] = Type::MEMORY;
1931   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1932   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1933 
1934   return flds;
1935 }
1936 


5407     if( _klass_is_exact ) st->print(":exact");
5408     break;
5409   }
5410 
5411   if( _offset ) {               // Dump offset, if any
5412     if( _offset == OffsetBot )      { st->print("+any"); }
5413     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5414     else                            { st->print("+%d", _offset); }
5415   }
5416 
5417   st->print(" *");
5418 }
5419 #endif
5420 
5421 
5422 
5423 //=============================================================================
5424 // Convenience common pre-built types.
5425 
5426 //------------------------------make-------------------------------------------
5427 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple* domain_cc, const TypeTuple *range ) {
5428   return (TypeFunc*)(new TypeFunc(domain, domain_cc, range))->hashcons();
5429 }
5430 
5431 //------------------------------make-------------------------------------------
5432 const TypeFunc *TypeFunc::make(ciMethod* method) {
5433   Compile* C = Compile::current();
5434   const TypeFunc* tf = C->last_tf(method); // check cache
5435   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5436   const TypeTuple *domain_sig, *domain_cc;
5437   // Value type arguments are not passed by reference, instead each
5438   // field of the value type is passed as an argument. We maintain 2
5439   // views of the argument list here: one based on the signature (with
5440   // a value type argument as a single slot), one based on the actual
5441   // calling convention (with a value type argument as a list of its
5442   // fields).
5443   if (method->is_static()) {
5444     domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5445     domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5446   } else {
5447     domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5448     domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5449   }
5450   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5451   tf = TypeFunc::make(domain_sig, domain_cc, range);
5452   C->set_last_tf(method, tf);  // fill cache
5453   return tf;
5454 }
5455 
5456 //------------------------------meet-------------------------------------------
5457 // Compute the MEET of two types.  It returns a new Type object.
5458 const Type *TypeFunc::xmeet( const Type *t ) const {
5459   // Perform a fast test for common case; meeting the same types together.
5460   if( this == t ) return this;  // Meeting same type-rep?
5461 
5462   // Current "this->_base" is Func
5463   switch (t->base()) {          // switch on original type
5464 
5465   case Bottom:                  // Ye Olde Default
5466     return t;
5467 
5468   default:                      // All else is a mistake
5469     typerr(t);
5470 
5471   case Top:
5472     break;
5473   }
5474   return this;                  // Return the double constant
5475 }
5476 
5477 //------------------------------xdual------------------------------------------
5478 // Dual: compute field-by-field dual
5479 const Type *TypeFunc::xdual() const {
5480   return this;
5481 }
5482 
5483 //------------------------------eq---------------------------------------------
5484 // Structural equality check for Type representations
5485 bool TypeFunc::eq( const Type *t ) const {
5486   const TypeFunc *a = (const TypeFunc*)t;
5487   return _domain_sig == a->_domain_sig &&
5488     _domain_cc == a->_domain_cc &&
5489     _range == a->_range;
5490 }
5491 
5492 //------------------------------hash-------------------------------------------
5493 // Type-specific hashing function.
5494 int TypeFunc::hash(void) const {
5495   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range;
5496 }
5497 
5498 //------------------------------dump2------------------------------------------
5499 // Dump Function Type
5500 #ifndef PRODUCT
5501 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5502   if( _range->cnt() <= Parms )
5503     st->print("void");
5504   else {
5505     uint i;
5506     for (i = Parms; i < _range->cnt()-1; i++) {
5507       _range->field_at(i)->dump2(d,depth,st);
5508       st->print("/");
5509     }
5510     _range->field_at(i)->dump2(d,depth,st);
5511   }
5512   st->print(" ");
5513   st->print("( ");
5514   if( !depth || d[this] ) {     // Check for recursive dump
5515     st->print("...)");
5516     return;
5517   }
5518   d.Insert((void*)this,(void*)this);    // Stop recursion
5519   if (Parms < _domain_sig->cnt())
5520     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5521   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5522     st->print(", ");
5523     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5524   }
5525   st->print(" )");
5526 }
5527 #endif
5528 
5529 //------------------------------singleton--------------------------------------
5530 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5531 // constants (Ldi nodes).  Singletons are integer, float or double constants
5532 // or a single symbol.
5533 bool TypeFunc::singleton(void) const {
5534   return false;                 // Never a singleton
5535 }
5536 
5537 bool TypeFunc::empty(void) const {
5538   return false;                 // Never empty
5539 }
5540 
5541 
5542 BasicType TypeFunc::return_type() const{
5543   if (range()->cnt() == TypeFunc::Parms) {
< prev index next >