574 fsc[0] = TypeInt::CC;
575 fsc[1] = Type::MEMORY;
576 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
577
578 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
579 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
580 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
581 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
582 false, 0, Offset(oopDesc::mark_offset_in_bytes()));
583 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
584 false, 0, Offset(oopDesc::klass_offset_in_bytes()));
585 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
586
587 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
588
589 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
590 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
591
592 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
593
594 mreg2type[Op_Node] = Type::BOTTOM;
595 mreg2type[Op_Set ] = 0;
596 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
597 mreg2type[Op_RegI] = TypeInt::INT;
598 mreg2type[Op_RegP] = TypePtr::BOTTOM;
599 mreg2type[Op_RegF] = Type::FLOAT;
600 mreg2type[Op_RegD] = Type::DOUBLE;
601 mreg2type[Op_RegL] = TypeLong::LONG;
602 mreg2type[Op_RegFlags] = TypeInt::CC;
603
604 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
605
606 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom);
607
608 #ifdef _LP64
609 if (UseCompressedOops) {
610 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
611 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
612 } else
613 #endif
1897
1898 bool TypeLong::empty(void) const {
1899 return _lo > _hi;
1900 }
1901
1902 //=============================================================================
1903 // Convenience common pre-built types.
1904 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1905 const TypeTuple *TypeTuple::IFFALSE;
1906 const TypeTuple *TypeTuple::IFTRUE;
1907 const TypeTuple *TypeTuple::IFNEITHER;
1908 const TypeTuple *TypeTuple::LOOPBODY;
1909 const TypeTuple *TypeTuple::MEMBAR;
1910 const TypeTuple *TypeTuple::STORECONDITIONAL;
1911 const TypeTuple *TypeTuple::START_I2C;
1912 const TypeTuple *TypeTuple::INT_PAIR;
1913 const TypeTuple *TypeTuple::LONG_PAIR;
1914 const TypeTuple *TypeTuple::INT_CC_PAIR;
1915 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1916
1917
1918 //------------------------------make-------------------------------------------
1919 // Make a TypeTuple from the range of a method signature
1920 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1921 ciType* return_type = sig->return_type();
1922 uint arg_cnt = return_type->size();
1923 const Type **field_array = fields(arg_cnt);
1924 switch (return_type->basic_type()) {
1925 case T_LONG:
1926 field_array[TypeFunc::Parms] = TypeLong::LONG;
1927 field_array[TypeFunc::Parms+1] = Type::HALF;
1928 break;
1929 case T_DOUBLE:
1930 field_array[TypeFunc::Parms] = Type::DOUBLE;
1931 field_array[TypeFunc::Parms+1] = Type::HALF;
1932 break;
1933 case T_OBJECT:
1934 case T_VALUETYPE:
1935 case T_ARRAY:
1936 case T_BOOLEAN:
1937 case T_CHAR:
1938 case T_FLOAT:
1939 case T_BYTE:
1940 case T_SHORT:
1941 case T_INT:
1942 field_array[TypeFunc::Parms] = get_const_type(return_type);
1943 break;
1944 case T_VOID:
1945 break;
1946 default:
1947 ShouldNotReachHere();
1948 }
1949 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1950 }
1951
1952 static void collect_value_fields(ciValueKlass* vk, const Type**& field_array, uint& pos) {
1953 for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1954 ciField* f = vk->nonstatic_field_at(j);
1955 BasicType bt = f->type()->basic_type();
1956 assert(bt < T_VALUETYPE && bt >= T_BOOLEAN, "not yet supported");
1957 field_array[pos++] = Type::get_const_type(f->type());
1958 if (bt == T_LONG || bt == T_DOUBLE) {
1959 field_array[pos++] = Type::HALF;
1960 }
1961 }
1962 }
1963
1964 // Make a TypeTuple from the domain of a method signature
1965 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
1966 uint arg_cnt = sig->size();
1967
1968 int vt_extra = 0;
1969 if (vt_fields_as_args) {
1970 for (int i = 0; i < sig->count(); i++) {
1971 ciType* type = sig->type_at(i);
1972 if (type->basic_type() == T_VALUETYPE) {
1973 assert(type->is_valuetype(), "inconsistent type");
1974 ciValueKlass* vk = (ciValueKlass*)type;
1975 vt_extra += vk->value_arg_slots()-1;
1976 }
1977 }
1978 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
1979 }
1980
1981 uint pos = TypeFunc::Parms;
1982 const Type **field_array;
1983 if (recv != NULL) {
4684 if (elemtype->isa_valuetype()) {
4685 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4686 if (offset >= (intptr_t)header) {
4687 ciKlass* arytype_klass = klass();
4688 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4689 int shift = vak->log2_element_size();
4690 intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4691
4692 return with_field_offset(field_offset)->add_offset(offset - field_offset);
4693 }
4694 }
4695 }
4696 return add_offset(offset);
4697 }
4698
4699 //=============================================================================
4700
4701
4702 //=============================================================================
4703
4704 //------------------------------make-------------------------------------------
4705 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4706 return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4707 }
4708
4709 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4710 return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4711 }
4712
4713 //------------------------------cast_to_ptr_type-------------------------------
4714 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4715 if (ptr == _ptr) return this;
4716 return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4717 }
4718
4719 //-----------------------------cast_to_instance_id----------------------------
4720 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4721 if (instance_id == _instance_id) return this;
4722 return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4723 }
4791 }
4792 case NotNull:
4793 case BotPTR:
4794 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4795 default: typerr(t);
4796 }
4797 }
4798
4799 case ValueTypePtr: {
4800 // Found an ValueTypePtr type vs self-ValueTypePtr type
4801 const TypeValueTypePtr* tp = t->is_valuetypeptr();
4802 Offset offset = meet_offset(tp->offset());
4803 PTR ptr = meet_ptr(tp->ptr());
4804 int instance_id = meet_instance_id(InstanceTop);
4805 const TypePtr* speculative = xmeet_speculative(tp);
4806 int depth = meet_inline_depth(tp->inline_depth());
4807 // Compute constant oop
4808 ciObject* o = NULL;
4809 ciObject* this_oop = const_oop();
4810 ciObject* tp_oop = tp->const_oop();
4811 if (ptr == Constant) {
4812 if (this_oop != NULL && tp_oop != NULL &&
4813 this_oop->equals(tp_oop) ) {
4814 o = this_oop;
4815 } else if (above_centerline(this ->_ptr)) {
4816 o = tp_oop;
4817 } else if (above_centerline(tp ->_ptr)) {
4818 o = this_oop;
4819 } else {
4820 ptr = NotNull;
4821 }
4822 }
4823 return make(_vt, ptr, o, offset, instance_id, speculative, depth);
4824 }
4825 }
4826 }
4827
4828 // Dual: compute field-by-field dual
4829 const Type* TypeValueTypePtr::xdual() const {
4830 return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4831 }
4832
4833 //------------------------------eq---------------------------------------------
4834 // Structural equality check for Type representations
4835 bool TypeValueTypePtr::eq(const Type* t) const {
4836 const TypeValueTypePtr* p = t->is_valuetypeptr();
4837 return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4838 }
4839
4840 //------------------------------hash-------------------------------------------
4841 // Type-specific hashing function.
4842 int TypeValueTypePtr::hash(void) const {
4843 return java_add(_vt->hash(), TypeOopPtr::hash());
5576 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5577 case TopPTR:
5578 case AnyNull:
5579 st->print(":%s", ptr_msg[_ptr]);
5580 if( _klass_is_exact ) st->print(":exact");
5581 break;
5582 }
5583
5584 _offset.dump2(st);
5585
5586 st->print(" *");
5587 }
5588 #endif
5589
5590
5591
5592 //=============================================================================
5593 // Convenience common pre-built types.
5594
5595 //------------------------------make-------------------------------------------
5596 const TypeFunc *TypeFunc::make( const TypeTuple *domain_sig, const TypeTuple* domain_cc, const TypeTuple *range ) {
5597 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range))->hashcons();
5598 }
5599
5600 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5601 return make(domain, domain, range);
5602 }
5603
5604 //------------------------------make-------------------------------------------
5605 const TypeFunc *TypeFunc::make(ciMethod* method) {
5606 Compile* C = Compile::current();
5607 const TypeFunc* tf = C->last_tf(method); // check cache
5608 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5609 const TypeTuple *domain_sig, *domain_cc;
5610 // Value type arguments are not passed by reference, instead each
5611 // field of the value type is passed as an argument. We maintain 2
5612 // views of the argument list here: one based on the signature (with
5613 // a value type argument as a single slot), one based on the actual
5614 // calling convention (with a value type argument as a list of its
5615 // fields).
5616 if (method->is_static()) {
5617 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5618 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5619 } else {
5620 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5621 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5622 }
5623 const TypeTuple *range = TypeTuple::make_range(method->signature());
5624 tf = TypeFunc::make(domain_sig, domain_cc, range);
5625 C->set_last_tf(method, tf); // fill cache
5626 return tf;
5627 }
5628
5629 //------------------------------meet-------------------------------------------
5630 // Compute the MEET of two types. It returns a new Type object.
5631 const Type *TypeFunc::xmeet( const Type *t ) const {
5632 // Perform a fast test for common case; meeting the same types together.
5633 if( this == t ) return this; // Meeting same type-rep?
5634
5635 // Current "this->_base" is Func
5636 switch (t->base()) { // switch on original type
5637
5638 case Bottom: // Ye Olde Default
5639 return t;
5640
5641 default: // All else is a mistake
5642 typerr(t);
5643
5644 case Top:
5645 break;
5646 }
5647 return this; // Return the double constant
5648 }
5649
5650 //------------------------------xdual------------------------------------------
5651 // Dual: compute field-by-field dual
5652 const Type *TypeFunc::xdual() const {
5653 return this;
5654 }
5655
5656 //------------------------------eq---------------------------------------------
5657 // Structural equality check for Type representations
5658 bool TypeFunc::eq( const Type *t ) const {
5659 const TypeFunc *a = (const TypeFunc*)t;
5660 return _domain_sig == a->_domain_sig &&
5661 _domain_cc == a->_domain_cc &&
5662 _range == a->_range;
5663 }
5664
5665 //------------------------------hash-------------------------------------------
5666 // Type-specific hashing function.
5667 int TypeFunc::hash(void) const {
5668 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range;
5669 }
5670
5671 //------------------------------dump2------------------------------------------
5672 // Dump Function Type
5673 #ifndef PRODUCT
5674 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5675 if( _range->cnt() <= Parms )
5676 st->print("void");
5677 else {
5678 uint i;
5679 for (i = Parms; i < _range->cnt()-1; i++) {
5680 _range->field_at(i)->dump2(d,depth,st);
5681 st->print("/");
5682 }
5683 _range->field_at(i)->dump2(d,depth,st);
5684 }
5685 st->print(" ");
5686 st->print("( ");
5687 if( !depth || d[this] ) { // Check for recursive dump
5688 st->print("...)");
5689 return;
5690 }
5691 d.Insert((void*)this,(void*)this); // Stop recursion
5692 if (Parms < _domain_sig->cnt())
5693 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5694 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5695 st->print(", ");
5696 _domain_sig->field_at(i)->dump2(d,depth-1,st);
5697 }
5698 st->print(" )");
5699 }
5700 #endif
5701
5702 //------------------------------singleton--------------------------------------
5703 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5704 // constants (Ldi nodes). Singletons are integer, float or double constants
5705 // or a single symbol.
5706 bool TypeFunc::singleton(void) const {
5707 return false; // Never a singleton
5708 }
5709
5710 bool TypeFunc::empty(void) const {
5711 return false; // Never empty
5712 }
5713
5714
5715 BasicType TypeFunc::return_type() const{
5716 if (range()->cnt() == TypeFunc::Parms) {
5717 return T_VOID;
5718 }
5719 return range()->field_at(TypeFunc::Parms)->basic_type();
5720 }
|
574 fsc[0] = TypeInt::CC;
575 fsc[1] = Type::MEMORY;
576 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
577
578 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
579 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
580 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
581 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
582 false, 0, Offset(oopDesc::mark_offset_in_bytes()));
583 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
584 false, 0, Offset(oopDesc::klass_offset_in_bytes()));
585 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
586
587 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
588
589 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
590 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
591
592 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
593
594 TypeValueTypePtr::NOTNULL = EnableValhalla ? TypeValueTypePtr::make(TypePtr::NotNull, current->env()->___Value_klass()->as_value_klass()) : NULL;
595
596 mreg2type[Op_Node] = Type::BOTTOM;
597 mreg2type[Op_Set ] = 0;
598 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
599 mreg2type[Op_RegI] = TypeInt::INT;
600 mreg2type[Op_RegP] = TypePtr::BOTTOM;
601 mreg2type[Op_RegF] = Type::FLOAT;
602 mreg2type[Op_RegD] = Type::DOUBLE;
603 mreg2type[Op_RegL] = TypeLong::LONG;
604 mreg2type[Op_RegFlags] = TypeInt::CC;
605
606 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
607
608 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom);
609
610 #ifdef _LP64
611 if (UseCompressedOops) {
612 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
613 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
614 } else
615 #endif
1899
1900 bool TypeLong::empty(void) const {
1901 return _lo > _hi;
1902 }
1903
1904 //=============================================================================
1905 // Convenience common pre-built types.
1906 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1907 const TypeTuple *TypeTuple::IFFALSE;
1908 const TypeTuple *TypeTuple::IFTRUE;
1909 const TypeTuple *TypeTuple::IFNEITHER;
1910 const TypeTuple *TypeTuple::LOOPBODY;
1911 const TypeTuple *TypeTuple::MEMBAR;
1912 const TypeTuple *TypeTuple::STORECONDITIONAL;
1913 const TypeTuple *TypeTuple::START_I2C;
1914 const TypeTuple *TypeTuple::INT_PAIR;
1915 const TypeTuple *TypeTuple::LONG_PAIR;
1916 const TypeTuple *TypeTuple::INT_CC_PAIR;
1917 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1918
1919 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos) {
1920 for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1921 ciField* f = vk->nonstatic_field_at(j);
1922 BasicType bt = f->type()->basic_type();
1923 assert(bt < T_VALUETYPE && bt >= T_BOOLEAN, "not yet supported");
1924 field_array[pos++] = Type::get_const_type(f->type());
1925 if (bt == T_LONG || bt == T_DOUBLE) {
1926 field_array[pos++] = Type::HALF;
1927 }
1928 }
1929 }
1930
1931 // Can a value type instance of this type be returned as multiple
1932 // returned values?
1933 static bool vt_can_be_returned_as_fields(ciValueKlass* vk) {
1934 if (vk == ciEnv::current()->___Value_klass()) {
1935 return false;
1936 }
1937
1938 ResourceMark rm;
1939 uint args = vk->value_arg_slots() + 1 /* return vk as well */;
1940
1941 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, args);
1942 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, args);
1943
1944 sig_bt[0] = T_METADATA;
1945 for (uint i = 0, j = 1; i < (uint)vk->nof_nonstatic_fields(); i++) {
1946 BasicType bt = vk->nonstatic_field_at(i)->layout_type();
1947 assert(i+j < args, "out of bounds access");
1948 sig_bt[i+j] = bt;
1949 if (bt == T_LONG || bt == T_DOUBLE) {
1950 j++;
1951 assert(i+j < args, "out of bounds access");
1952 sig_bt[i+j] = T_VOID;
1953 }
1954 }
1955
1956 if (SharedRuntime::java_return_convention(sig_bt, regs, args) <= 0) {
1957 return false;
1958 }
1959
1960 return true;
1961 }
1962
1963
1964 //------------------------------make-------------------------------------------
1965 // Make a TypeTuple from the range of a method signature
1966 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1967 ciType* return_type = sig->return_type();
1968 uint arg_cnt = 0;
1969 if (ret_vt_fields) {
1970 ret_vt_fields = return_type->is_valuetype() && vt_can_be_returned_as_fields((ciValueKlass*)return_type);
1971 }
1972 if (ret_vt_fields) {
1973 ciValueKlass* vk = (ciValueKlass*)return_type;
1974 arg_cnt = vk->value_arg_slots()+1;
1975 } else {
1976 arg_cnt = return_type->size();
1977 }
1978
1979 const Type **field_array = fields(arg_cnt);
1980 switch (return_type->basic_type()) {
1981 case T_LONG:
1982 field_array[TypeFunc::Parms] = TypeLong::LONG;
1983 field_array[TypeFunc::Parms+1] = Type::HALF;
1984 break;
1985 case T_DOUBLE:
1986 field_array[TypeFunc::Parms] = Type::DOUBLE;
1987 field_array[TypeFunc::Parms+1] = Type::HALF;
1988 break;
1989 case T_OBJECT:
1990 case T_ARRAY:
1991 case T_BOOLEAN:
1992 case T_CHAR:
1993 case T_FLOAT:
1994 case T_BYTE:
1995 case T_SHORT:
1996 case T_INT:
1997 field_array[TypeFunc::Parms] = get_const_type(return_type);
1998 break;
1999 case T_VALUETYPE:
2000 if (ret_vt_fields) {
2001 ciValueKlass* vk = (ciValueKlass*)return_type;
2002 uint pos = TypeFunc::Parms;
2003 field_array[pos] = TypeKlassPtr::make(vk);
2004 pos++;
2005 collect_value_fields(vk, field_array, pos);
2006 } else {
2007 field_array[TypeFunc::Parms] = get_const_type(return_type);
2008 }
2009 break;
2010 case T_VOID:
2011 break;
2012 default:
2013 ShouldNotReachHere();
2014 }
2015 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2016 }
2017
2018 // Make a TypeTuple from the domain of a method signature
2019 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2020 uint arg_cnt = sig->size();
2021
2022 int vt_extra = 0;
2023 if (vt_fields_as_args) {
2024 for (int i = 0; i < sig->count(); i++) {
2025 ciType* type = sig->type_at(i);
2026 if (type->basic_type() == T_VALUETYPE) {
2027 assert(type->is_valuetype(), "inconsistent type");
2028 ciValueKlass* vk = (ciValueKlass*)type;
2029 vt_extra += vk->value_arg_slots()-1;
2030 }
2031 }
2032 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2033 }
2034
2035 uint pos = TypeFunc::Parms;
2036 const Type **field_array;
2037 if (recv != NULL) {
4738 if (elemtype->isa_valuetype()) {
4739 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4740 if (offset >= (intptr_t)header) {
4741 ciKlass* arytype_klass = klass();
4742 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4743 int shift = vak->log2_element_size();
4744 intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4745
4746 return with_field_offset(field_offset)->add_offset(offset - field_offset);
4747 }
4748 }
4749 }
4750 return add_offset(offset);
4751 }
4752
4753 //=============================================================================
4754
4755
4756 //=============================================================================
4757
4758 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4759 //------------------------------make-------------------------------------------
4760 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4761 return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4762 }
4763
4764 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4765 return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4766 }
4767
4768 //------------------------------cast_to_ptr_type-------------------------------
4769 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4770 if (ptr == _ptr) return this;
4771 return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4772 }
4773
4774 //-----------------------------cast_to_instance_id----------------------------
4775 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4776 if (instance_id == _instance_id) return this;
4777 return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4778 }
4846 }
4847 case NotNull:
4848 case BotPTR:
4849 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4850 default: typerr(t);
4851 }
4852 }
4853
4854 case ValueTypePtr: {
4855 // Found an ValueTypePtr type vs self-ValueTypePtr type
4856 const TypeValueTypePtr* tp = t->is_valuetypeptr();
4857 Offset offset = meet_offset(tp->offset());
4858 PTR ptr = meet_ptr(tp->ptr());
4859 int instance_id = meet_instance_id(InstanceTop);
4860 const TypePtr* speculative = xmeet_speculative(tp);
4861 int depth = meet_inline_depth(tp->inline_depth());
4862 // Compute constant oop
4863 ciObject* o = NULL;
4864 ciObject* this_oop = const_oop();
4865 ciObject* tp_oop = tp->const_oop();
4866 const TypeValueType* vt = NULL;
4867 if (_vt != tp->_vt) {
4868 ciKlass* __value_klass = ciEnv::current()->___Value_klass();
4869 assert(klass() == __value_klass || tp->klass() == __value_klass, "impossible meet");
4870 if (above_centerline(ptr)) {
4871 vt = klass() == __value_klass ? tp->_vt : _vt;
4872 } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4873 vt = tp->_vt;
4874 } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4875 vt = _vt;
4876 } else {
4877 vt = klass() == __value_klass ? _vt : tp->_vt;
4878 }
4879 } else {
4880 vt = _vt;
4881 }
4882 if (ptr == Constant) {
4883 if (this_oop != NULL && tp_oop != NULL &&
4884 this_oop->equals(tp_oop) ) {
4885 o = this_oop;
4886 } else if (above_centerline(this ->_ptr)) {
4887 o = tp_oop;
4888 } else if (above_centerline(tp ->_ptr)) {
4889 o = this_oop;
4890 } else {
4891 ptr = NotNull;
4892 }
4893 }
4894 return make(vt, ptr, o, offset, instance_id, speculative, depth);
4895 }
4896 }
4897 }
4898
4899 // Dual: compute field-by-field dual
4900 const Type* TypeValueTypePtr::xdual() const {
4901 return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4902 }
4903
4904 //------------------------------eq---------------------------------------------
4905 // Structural equality check for Type representations
4906 bool TypeValueTypePtr::eq(const Type* t) const {
4907 const TypeValueTypePtr* p = t->is_valuetypeptr();
4908 return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4909 }
4910
4911 //------------------------------hash-------------------------------------------
4912 // Type-specific hashing function.
4913 int TypeValueTypePtr::hash(void) const {
4914 return java_add(_vt->hash(), TypeOopPtr::hash());
5647 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5648 case TopPTR:
5649 case AnyNull:
5650 st->print(":%s", ptr_msg[_ptr]);
5651 if( _klass_is_exact ) st->print(":exact");
5652 break;
5653 }
5654
5655 _offset.dump2(st);
5656
5657 st->print(" *");
5658 }
5659 #endif
5660
5661
5662
5663 //=============================================================================
5664 // Convenience common pre-built types.
5665
5666 //------------------------------make-------------------------------------------
5667 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5668 const TypeTuple *range_sig, const TypeTuple *range_cc) {
5669 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5670 }
5671
5672 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5673 return make(domain, domain, range, range);
5674 }
5675
5676 //------------------------------make-------------------------------------------
5677 const TypeFunc *TypeFunc::make(ciMethod* method) {
5678 Compile* C = Compile::current();
5679 const TypeFunc* tf = C->last_tf(method); // check cache
5680 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5681 const TypeTuple *domain_sig, *domain_cc;
5682 // Value type arguments are not passed by reference, instead each
5683 // field of the value type is passed as an argument. We maintain 2
5684 // views of the argument list here: one based on the signature (with
5685 // a value type argument as a single slot), one based on the actual
5686 // calling convention (with a value type argument as a list of its
5687 // fields).
5688 if (method->is_static()) {
5689 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5690 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5691 } else {
5692 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5693 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5694 }
5695 const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false);
5696 const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);
5697 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5698 C->set_last_tf(method, tf); // fill cache
5699 return tf;
5700 }
5701
5702 //------------------------------meet-------------------------------------------
5703 // Compute the MEET of two types. It returns a new Type object.
5704 const Type *TypeFunc::xmeet( const Type *t ) const {
5705 // Perform a fast test for common case; meeting the same types together.
5706 if( this == t ) return this; // Meeting same type-rep?
5707
5708 // Current "this->_base" is Func
5709 switch (t->base()) { // switch on original type
5710
5711 case Bottom: // Ye Olde Default
5712 return t;
5713
5714 default: // All else is a mistake
5715 typerr(t);
5716
5717 case Top:
5718 break;
5719 }
5720 return this; // Return the double constant
5721 }
5722
5723 //------------------------------xdual------------------------------------------
5724 // Dual: compute field-by-field dual
5725 const Type *TypeFunc::xdual() const {
5726 return this;
5727 }
5728
5729 //------------------------------eq---------------------------------------------
5730 // Structural equality check for Type representations
5731 bool TypeFunc::eq( const Type *t ) const {
5732 const TypeFunc *a = (const TypeFunc*)t;
5733 return _domain_sig == a->_domain_sig &&
5734 _domain_cc == a->_domain_cc &&
5735 _range_sig == a->_range_sig &&
5736 _range_cc == a->_range_cc;
5737 }
5738
5739 //------------------------------hash-------------------------------------------
5740 // Type-specific hashing function.
5741 int TypeFunc::hash(void) const {
5742 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5743 }
5744
5745 //------------------------------dump2------------------------------------------
5746 // Dump Function Type
5747 #ifndef PRODUCT
5748 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5749 if( _range_sig->cnt() <= Parms )
5750 st->print("void");
5751 else {
5752 uint i;
5753 for (i = Parms; i < _range_sig->cnt()-1; i++) {
5754 _range_sig->field_at(i)->dump2(d,depth,st);
5755 st->print("/");
5756 }
5757 _range_sig->field_at(i)->dump2(d,depth,st);
5758 }
5759 st->print(" ");
5760 st->print("( ");
5761 if( !depth || d[this] ) { // Check for recursive dump
5762 st->print("...)");
5763 return;
5764 }
5765 d.Insert((void*)this,(void*)this); // Stop recursion
5766 if (Parms < _domain_sig->cnt())
5767 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5768 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5769 st->print(", ");
5770 _domain_sig->field_at(i)->dump2(d,depth-1,st);
5771 }
5772 st->print(" )");
5773 }
5774 #endif
5775
5776 //------------------------------singleton--------------------------------------
5777 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5778 // constants (Ldi nodes). Singletons are integer, float or double constants
5779 // or a single symbol.
5780 bool TypeFunc::singleton(void) const {
5781 return false; // Never a singleton
5782 }
5783
5784 bool TypeFunc::empty(void) const {
5785 return false; // Never empty
5786 }
5787
5788
5789 BasicType TypeFunc::return_type() const{
5790 if (range_sig()->cnt() == TypeFunc::Parms) {
5791 return T_VOID;
5792 }
5793 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5794 }
|