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
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 // Make a TypeTuple from the domain of a method signature
1815 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1816 uint arg_cnt = sig->size();
1817
1818 uint pos = TypeFunc::Parms;
1819 const Type **field_array;
1820 if (recv != NULL) {
1821 arg_cnt++;
1822 field_array = fields(arg_cnt);
1823 // Use get_const_type here because it respects UseUniqueSubclasses:
1824 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1825 } else {
1826 field_array = fields(arg_cnt);
1827 }
1828
1829 int i = 0;
1830 while (pos < TypeFunc::Parms + arg_cnt) {
1831 ciType* type = sig->type_at(i);
1832
1833 switch (type->basic_type()) {
1834 case T_LONG:
1835 field_array[pos++] = TypeLong::LONG;
1836 field_array[pos++] = Type::HALF;
1837 break;
1838 case T_DOUBLE:
1839 field_array[pos++] = Type::DOUBLE;
1840 field_array[pos++] = Type::HALF;
1841 break;
1842 case T_OBJECT:
1843 case T_VALUETYPE:
1844 case T_ARRAY:
1845 case T_BOOLEAN:
1846 case T_CHAR:
1847 case T_FLOAT:
1848 case T_BYTE:
1849 case T_SHORT:
1850 case T_INT:
1851 field_array[pos++] = get_const_type(type);
1852 break;
1853 default:
1854 ShouldNotReachHere();
1855 }
1856 i++;
1857 }
1858
1859 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1860 }
1861
1862 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1863 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1864 }
1865
1866 //------------------------------fields-----------------------------------------
1867 // Subroutine call type with space allocated for argument types
1868 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1869 const Type **TypeTuple::fields( uint arg_cnt ) {
1870 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1871 flds[TypeFunc::Control ] = Type::CONTROL;
1872 flds[TypeFunc::I_O ] = Type::ABIO;
1873 flds[TypeFunc::Memory ] = Type::MEMORY;
1874 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1875 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1876
1877 return flds;
1878 }
1879
5368 if( _klass_is_exact ) st->print(":exact");
5369 break;
5370 }
5371
5372 if( _offset ) { // Dump offset, if any
5373 if( _offset == OffsetBot ) { st->print("+any"); }
5374 else if( _offset == OffsetTop ) { st->print("+unknown"); }
5375 else { st->print("+%d", _offset); }
5376 }
5377
5378 st->print(" *");
5379 }
5380 #endif
5381
5382
5383
5384 //=============================================================================
5385 // Convenience common pre-built types.
5386
5387 //------------------------------make-------------------------------------------
5388 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5389 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5390 }
5391
5392 //------------------------------make-------------------------------------------
5393 const TypeFunc *TypeFunc::make(ciMethod* method) {
5394 Compile* C = Compile::current();
5395 const TypeFunc* tf = C->last_tf(method); // check cache
5396 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5397 const TypeTuple *domain;
5398 if (method->is_static()) {
5399 domain = TypeTuple::make_domain(NULL, method->signature());
5400 } else {
5401 domain = TypeTuple::make_domain(method->holder(), method->signature());
5402 }
5403 const TypeTuple *range = TypeTuple::make_range(method->signature());
5404 tf = TypeFunc::make(domain, range);
5405 C->set_last_tf(method, tf); // fill cache
5406 return tf;
5407 }
5408
5409 //------------------------------meet-------------------------------------------
5410 // Compute the MEET of two types. It returns a new Type object.
5411 const Type *TypeFunc::xmeet( const Type *t ) const {
5412 // Perform a fast test for common case; meeting the same types together.
5413 if( this == t ) return this; // Meeting same type-rep?
5414
5415 // Current "this->_base" is Func
5416 switch (t->base()) { // switch on original type
5417
5418 case Bottom: // Ye Olde Default
5419 return t;
5420
5421 default: // All else is a mistake
5422 typerr(t);
5423
5424 case Top:
5425 break;
5426 }
5427 return this; // Return the double constant
5428 }
5429
5430 //------------------------------xdual------------------------------------------
5431 // Dual: compute field-by-field dual
5432 const Type *TypeFunc::xdual() const {
5433 return this;
5434 }
5435
5436 //------------------------------eq---------------------------------------------
5437 // Structural equality check for Type representations
5438 bool TypeFunc::eq( const Type *t ) const {
5439 const TypeFunc *a = (const TypeFunc*)t;
5440 return _domain == a->_domain &&
5441 _range == a->_range;
5442 }
5443
5444 //------------------------------hash-------------------------------------------
5445 // Type-specific hashing function.
5446 int TypeFunc::hash(void) const {
5447 return (intptr_t)_domain + (intptr_t)_range;
5448 }
5449
5450 //------------------------------dump2------------------------------------------
5451 // Dump Function Type
5452 #ifndef PRODUCT
5453 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5454 if( _range->cnt() <= Parms )
5455 st->print("void");
5456 else {
5457 uint i;
5458 for (i = Parms; i < _range->cnt()-1; i++) {
5459 _range->field_at(i)->dump2(d,depth,st);
5460 st->print("/");
5461 }
5462 _range->field_at(i)->dump2(d,depth,st);
5463 }
5464 st->print(" ");
5465 st->print("( ");
5466 if( !depth || d[this] ) { // Check for recursive dump
5467 st->print("...)");
5468 return;
5469 }
5470 d.Insert((void*)this,(void*)this); // Stop recursion
5471 if (Parms < _domain->cnt())
5472 _domain->field_at(Parms)->dump2(d,depth-1,st);
5473 for (uint i = Parms+1; i < _domain->cnt(); i++) {
5474 st->print(", ");
5475 _domain->field_at(i)->dump2(d,depth-1,st);
5476 }
5477 st->print(" )");
5478 }
5479 #endif
5480
5481 //------------------------------singleton--------------------------------------
5482 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5483 // constants (Ldi nodes). Singletons are integer, float or double constants
5484 // or a single symbol.
5485 bool TypeFunc::singleton(void) const {
5486 return false; // Never a singleton
5487 }
5488
5489 bool TypeFunc::empty(void) const {
5490 return false; // Never empty
5491 }
5492
5493
5494 BasicType TypeFunc::return_type() const{
5495 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
1795 break;
1796 case T_OBJECT:
1797 case T_VALUETYPE:
1798 case T_ARRAY:
1799 case T_BOOLEAN:
1800 case T_CHAR:
1801 case T_FLOAT:
1802 case T_BYTE:
1803 case T_SHORT:
1804 case T_INT:
1805 field_array[TypeFunc::Parms] = get_const_type(return_type);
1806 break;
1807 case T_VOID:
1808 break;
1809 default:
1810 ShouldNotReachHere();
1811 }
1812 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1813 }
1814
1815 static void collect_value_fields(ciValueKlass* vk, const Type**& field_array, uint& pos) {
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 && bt >= T_BOOLEAN, "not yet supported");
1820 field_array[pos++] = Type::get_const_type(f->type());
1821 if (bt == T_LONG || bt == T_DOUBLE) {
1822 field_array[pos++] = Type::HALF;
1823 }
1824 }
1825 }
1826
1827 // Make a TypeTuple from the domain of a method signature
1828 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
1829 uint arg_cnt = sig->size();
1830
1831 int vt_extra = 0;
1832 if (vt_fields_as_args) {
1833 for (int i = 0; i < sig->count(); i++) {
1834 ciType* type = sig->type_at(i);
1835 if (type->basic_type() == T_VALUETYPE) {
1836 assert(type->is_valuetype(), "inconsistent type");
1837 ciValueKlass* vk = (ciValueKlass*)type;
1838 vt_extra += vk->extra_value_args();
1839 }
1840 }
1841 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
1842 }
1843
1844 uint pos = TypeFunc::Parms;
1845 const Type **field_array;
1846 if (recv != NULL) {
1847 arg_cnt++;
1848 if (vt_fields_as_args && recv->is_valuetype()) {
1849 ciValueKlass* vk = (ciValueKlass*)recv;
1850 vt_extra += vk->extra_value_args();
1851 }
1852 field_array = fields(arg_cnt + vt_extra);
1853 // Use get_const_type here because it respects UseUniqueSubclasses:
1854 if (vt_fields_as_args && recv->is_valuetype()) {
1855 ciValueKlass* vk = (ciValueKlass*)recv;
1856 collect_value_fields(vk, field_array, pos);
1857 } else {
1858 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1859 }
1860 } else {
1861 field_array = fields(arg_cnt + vt_extra);
1862 }
1863
1864 int i = 0;
1865 while (pos < TypeFunc::Parms + arg_cnt + vt_extra) {
1866 ciType* type = sig->type_at(i);
1867
1868 switch (type->basic_type()) {
1869 case T_LONG:
1870 field_array[pos++] = TypeLong::LONG;
1871 field_array[pos++] = Type::HALF;
1872 break;
1873 case T_DOUBLE:
1874 field_array[pos++] = Type::DOUBLE;
1875 field_array[pos++] = Type::HALF;
1876 break;
1877 case T_OBJECT:
1878 case T_ARRAY:
1879 case T_BOOLEAN:
1880 case T_CHAR:
1881 case T_FLOAT:
1882 case T_BYTE:
1883 case T_SHORT:
1884 case T_INT:
1885 field_array[pos++] = get_const_type(type);
1886 break;
1887 case T_VALUETYPE: {
1888 assert(type->is_valuetype(), "inconsistent type");
1889 if (vt_fields_as_args) {
1890 ciValueKlass* vk = (ciValueKlass*)type;
1891 collect_value_fields(vk, field_array, pos);
1892 } else {
1893 field_array[pos++] = get_const_type(type);
1894 }
1895 break;
1896 }
1897 default:
1898 ShouldNotReachHere();
1899 }
1900 i++;
1901 }
1902 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments");
1903
1904 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons();
1905 }
1906
1907 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1908 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1909 }
1910
1911 //------------------------------fields-----------------------------------------
1912 // Subroutine call type with space allocated for argument types
1913 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1914 const Type **TypeTuple::fields( uint arg_cnt ) {
1915 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1916 flds[TypeFunc::Control ] = Type::CONTROL;
1917 flds[TypeFunc::I_O ] = Type::ABIO;
1918 flds[TypeFunc::Memory ] = Type::MEMORY;
1919 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1920 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1921
1922 return flds;
1923 }
1924
5413 if( _klass_is_exact ) st->print(":exact");
5414 break;
5415 }
5416
5417 if( _offset ) { // Dump offset, if any
5418 if( _offset == OffsetBot ) { st->print("+any"); }
5419 else if( _offset == OffsetTop ) { st->print("+unknown"); }
5420 else { st->print("+%d", _offset); }
5421 }
5422
5423 st->print(" *");
5424 }
5425 #endif
5426
5427
5428
5429 //=============================================================================
5430 // Convenience common pre-built types.
5431
5432 //------------------------------make-------------------------------------------
5433 const TypeFunc *TypeFunc::make( const TypeTuple *domain_sig, const TypeTuple* domain_cc, const TypeTuple *range ) {
5434 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range))->hashcons();
5435 }
5436
5437 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5438 return make(domain, domain, range);
5439 }
5440
5441 //------------------------------make-------------------------------------------
5442 const TypeFunc *TypeFunc::make(ciMethod* method) {
5443 Compile* C = Compile::current();
5444 const TypeFunc* tf = C->last_tf(method); // check cache
5445 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5446 const TypeTuple *domain_sig, *domain_cc;
5447 // Value type arguments are not passed by reference, instead each
5448 // field of the value type is passed as an argument. We maintain 2
5449 // views of the argument list here: one based on the signature (with
5450 // a value type argument as a single slot), one based on the actual
5451 // calling convention (with a value type argument as a list of its
5452 // fields).
5453 if (method->is_static()) {
5454 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5455 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5456 } else {
5457 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5458 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5459 }
5460 const TypeTuple *range = TypeTuple::make_range(method->signature());
5461 tf = TypeFunc::make(domain_sig, domain_cc, range);
5462 C->set_last_tf(method, tf); // fill cache
5463 return tf;
5464 }
5465
5466 //------------------------------meet-------------------------------------------
5467 // Compute the MEET of two types. It returns a new Type object.
5468 const Type *TypeFunc::xmeet( const Type *t ) const {
5469 // Perform a fast test for common case; meeting the same types together.
5470 if( this == t ) return this; // Meeting same type-rep?
5471
5472 // Current "this->_base" is Func
5473 switch (t->base()) { // switch on original type
5474
5475 case Bottom: // Ye Olde Default
5476 return t;
5477
5478 default: // All else is a mistake
5479 typerr(t);
5480
5481 case Top:
5482 break;
5483 }
5484 return this; // Return the double constant
5485 }
5486
5487 //------------------------------xdual------------------------------------------
5488 // Dual: compute field-by-field dual
5489 const Type *TypeFunc::xdual() const {
5490 return this;
5491 }
5492
5493 //------------------------------eq---------------------------------------------
5494 // Structural equality check for Type representations
5495 bool TypeFunc::eq( const Type *t ) const {
5496 const TypeFunc *a = (const TypeFunc*)t;
5497 return _domain_sig == a->_domain_sig &&
5498 _domain_cc == a->_domain_cc &&
5499 _range == a->_range;
5500 }
5501
5502 //------------------------------hash-------------------------------------------
5503 // Type-specific hashing function.
5504 int TypeFunc::hash(void) const {
5505 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range;
5506 }
5507
5508 //------------------------------dump2------------------------------------------
5509 // Dump Function Type
5510 #ifndef PRODUCT
5511 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5512 if( _range->cnt() <= Parms )
5513 st->print("void");
5514 else {
5515 uint i;
5516 for (i = Parms; i < _range->cnt()-1; i++) {
5517 _range->field_at(i)->dump2(d,depth,st);
5518 st->print("/");
5519 }
5520 _range->field_at(i)->dump2(d,depth,st);
5521 }
5522 st->print(" ");
5523 st->print("( ");
5524 if( !depth || d[this] ) { // Check for recursive dump
5525 st->print("...)");
5526 return;
5527 }
5528 d.Insert((void*)this,(void*)this); // Stop recursion
5529 if (Parms < _domain_sig->cnt())
5530 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5531 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5532 st->print(", ");
5533 _domain_sig->field_at(i)->dump2(d,depth-1,st);
5534 }
5535 st->print(" )");
5536 }
5537 #endif
5538
5539 //------------------------------singleton--------------------------------------
5540 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5541 // constants (Ldi nodes). Singletons are integer, float or double constants
5542 // or a single symbol.
5543 bool TypeFunc::singleton(void) const {
5544 return false; // Never a singleton
5545 }
5546
5547 bool TypeFunc::empty(void) const {
5548 return false; // Never empty
5549 }
5550
5551
5552 BasicType TypeFunc::return_type() const{
5553 if (range()->cnt() == TypeFunc::Parms) {
|