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 ResourceMark rm;
1938 uint args = vk->value_arg_slots() + 1 /* return vk as well */;
1939
1940 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, args);
1941 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, args);
1942
1943 sig_bt[0] = T_METADATA;
1944 for (uint i = 0, j = 1; i < (uint)vk->nof_nonstatic_fields(); i++) {
1945 BasicType bt = vk->nonstatic_field_at(i)->layout_type();
1946 assert(i+j < args, "out of bounds access");
1947 sig_bt[i+j] = bt;
1948 if (bt == T_LONG || bt == T_DOUBLE) {
1949 j++;
1950 assert(i+j < args, "out of bounds access");
1951 sig_bt[i+j] = T_VOID;
1952 }
1953 }
1954
1955 if (SharedRuntime::java_return_convention(sig_bt, regs, args) <= 0) {
1956 return false;
1957 }
1958
1959 return true;
1960 }
1961
1962
1963 //------------------------------make-------------------------------------------
1964 // Make a TypeTuple from the range of a method signature
1965 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1966 ciType* return_type = sig->return_type();
1967 uint arg_cnt = 0;
1968 if (ret_vt_fields) {
1969 ret_vt_fields = return_type->is_valuetype() && vt_can_be_returned_as_fields((ciValueKlass*)return_type);
1970 }
1971 if (ret_vt_fields) {
1972 ciValueKlass* vk = (ciValueKlass*)return_type;
1973 arg_cnt = vk->value_arg_slots()+1;
1974 } else {
1975 arg_cnt = return_type->size();
1976 }
1977
1978 const Type **field_array = fields(arg_cnt);
1979 switch (return_type->basic_type()) {
1980 case T_LONG:
1981 field_array[TypeFunc::Parms] = TypeLong::LONG;
1982 field_array[TypeFunc::Parms+1] = Type::HALF;
1983 break;
1984 case T_DOUBLE:
1985 field_array[TypeFunc::Parms] = Type::DOUBLE;
1986 field_array[TypeFunc::Parms+1] = Type::HALF;
1987 break;
1988 case T_OBJECT:
1989 case T_ARRAY:
1990 case T_BOOLEAN:
1991 case T_CHAR:
1992 case T_FLOAT:
1993 case T_BYTE:
1994 case T_SHORT:
1995 case T_INT:
1996 field_array[TypeFunc::Parms] = get_const_type(return_type);
1997 break;
1998 case T_VALUETYPE:
1999 if (ret_vt_fields) {
2000 ciValueKlass* vk = (ciValueKlass*)return_type;
2001 uint pos = TypeFunc::Parms;
2002 field_array[pos] = TypeKlassPtr::make(vk);
2003 pos++;
2004 collect_value_fields(vk, field_array, pos);
2005 } else {
2006 field_array[TypeFunc::Parms] = get_const_type(return_type);
2007 }
2008 break;
2009 case T_VOID:
2010 break;
2011 default:
2012 ShouldNotReachHere();
2013 }
2014 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2015 }
2016
2017 // Make a TypeTuple from the domain of a method signature
2018 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) {
2019 uint arg_cnt = sig->size();
2020
2021 int vt_extra = 0;
2022 if (vt_fields_as_args) {
2023 for (int i = 0; i < sig->count(); i++) {
2024 ciType* type = sig->type_at(i);
2025 if (type->basic_type() == T_VALUETYPE) {
2026 assert(type->is_valuetype(), "inconsistent type");
2027 ciValueKlass* vk = (ciValueKlass*)type;
2028 vt_extra += vk->value_arg_slots()-1;
2029 }
2030 }
2031 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?");
2032 }
2033
2034 uint pos = TypeFunc::Parms;
2035 const Type **field_array;
2036 if (recv != NULL) {
4737 if (elemtype->isa_valuetype()) {
4738 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4739 if (offset >= (intptr_t)header) {
4740 ciKlass* arytype_klass = klass();
4741 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4742 int shift = vak->log2_element_size();
4743 intptr_t field_offset = ((offset - header) & ((1 << shift) - 1));
4744
4745 return with_field_offset(field_offset)->add_offset(offset - field_offset);
4746 }
4747 }
4748 }
4749 return add_offset(offset);
4750 }
4751
4752 //=============================================================================
4753
4754
4755 //=============================================================================
4756
4757 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL;
4758 //------------------------------make-------------------------------------------
4759 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) {
4760 return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons();
4761 }
4762
4763 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const {
4764 return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth);
4765 }
4766
4767 //------------------------------cast_to_ptr_type-------------------------------
4768 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const {
4769 if (ptr == _ptr) return this;
4770 return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth);
4771 }
4772
4773 //-----------------------------cast_to_instance_id----------------------------
4774 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const {
4775 if (instance_id == _instance_id) return this;
4776 return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth);
4777 }
4845 }
4846 case NotNull:
4847 case BotPTR:
4848 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4849 default: typerr(t);
4850 }
4851 }
4852
4853 case ValueTypePtr: {
4854 // Found an ValueTypePtr type vs self-ValueTypePtr type
4855 const TypeValueTypePtr* tp = t->is_valuetypeptr();
4856 Offset offset = meet_offset(tp->offset());
4857 PTR ptr = meet_ptr(tp->ptr());
4858 int instance_id = meet_instance_id(InstanceTop);
4859 const TypePtr* speculative = xmeet_speculative(tp);
4860 int depth = meet_inline_depth(tp->inline_depth());
4861 // Compute constant oop
4862 ciObject* o = NULL;
4863 ciObject* this_oop = const_oop();
4864 ciObject* tp_oop = tp->const_oop();
4865 const TypeValueType* vt = NULL;
4866 if (_vt != tp->_vt) {
4867 ciKlass* __value_klass = ciEnv::current()->___Value_klass();
4868 assert(klass() == __value_klass || tp->klass() == __value_klass, "impossible meet");
4869 if (above_centerline(ptr)) {
4870 vt = klass() == __value_klass ? tp->_vt : _vt;
4871 } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) {
4872 vt = tp->_vt;
4873 } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) {
4874 vt = _vt;
4875 } else {
4876 vt = klass() == __value_klass ? _vt : tp->_vt;
4877 }
4878 } else {
4879 vt = _vt;
4880 }
4881 if (ptr == Constant) {
4882 if (this_oop != NULL && tp_oop != NULL &&
4883 this_oop->equals(tp_oop) ) {
4884 o = this_oop;
4885 } else if (above_centerline(this ->_ptr)) {
4886 o = tp_oop;
4887 } else if (above_centerline(tp ->_ptr)) {
4888 o = this_oop;
4889 } else {
4890 ptr = NotNull;
4891 }
4892 }
4893 return make(vt, ptr, o, offset, instance_id, speculative, depth);
4894 }
4895 }
4896 }
4897
4898 // Dual: compute field-by-field dual
4899 const Type* TypeValueTypePtr::xdual() const {
4900 return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4901 }
4902
4903 //------------------------------eq---------------------------------------------
4904 // Structural equality check for Type representations
4905 bool TypeValueTypePtr::eq(const Type* t) const {
4906 const TypeValueTypePtr* p = t->is_valuetypeptr();
4907 return _vt->eq(p->value_type()) && TypeOopPtr::eq(p);
4908 }
4909
4910 //------------------------------hash-------------------------------------------
4911 // Type-specific hashing function.
4912 int TypeValueTypePtr::hash(void) const {
4913 return java_add(_vt->hash(), TypeOopPtr::hash());
5646 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5647 case TopPTR:
5648 case AnyNull:
5649 st->print(":%s", ptr_msg[_ptr]);
5650 if( _klass_is_exact ) st->print(":exact");
5651 break;
5652 }
5653
5654 _offset.dump2(st);
5655
5656 st->print(" *");
5657 }
5658 #endif
5659
5660
5661
5662 //=============================================================================
5663 // Convenience common pre-built types.
5664
5665 //------------------------------make-------------------------------------------
5666 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5667 const TypeTuple *range_sig, const TypeTuple *range_cc) {
5668 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5669 }
5670
5671 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5672 return make(domain, domain, range, range);
5673 }
5674
5675 //------------------------------make-------------------------------------------
5676 const TypeFunc *TypeFunc::make(ciMethod* method) {
5677 Compile* C = Compile::current();
5678 const TypeFunc* tf = C->last_tf(method); // check cache
5679 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5680 const TypeTuple *domain_sig, *domain_cc;
5681 // Value type arguments are not passed by reference, instead each
5682 // field of the value type is passed as an argument. We maintain 2
5683 // views of the argument list here: one based on the signature (with
5684 // a value type argument as a single slot), one based on the actual
5685 // calling convention (with a value type argument as a list of its
5686 // fields).
5687 if (method->is_static()) {
5688 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false);
5689 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs);
5690 } else {
5691 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false);
5692 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs);
5693 }
5694 const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false);
5695 const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);
5696 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5697 C->set_last_tf(method, tf); // fill cache
5698 return tf;
5699 }
5700
5701 //------------------------------meet-------------------------------------------
5702 // Compute the MEET of two types. It returns a new Type object.
5703 const Type *TypeFunc::xmeet( const Type *t ) const {
5704 // Perform a fast test for common case; meeting the same types together.
5705 if( this == t ) return this; // Meeting same type-rep?
5706
5707 // Current "this->_base" is Func
5708 switch (t->base()) { // switch on original type
5709
5710 case Bottom: // Ye Olde Default
5711 return t;
5712
5713 default: // All else is a mistake
5714 typerr(t);
5715
5716 case Top:
5717 break;
5718 }
5719 return this; // Return the double constant
5720 }
5721
5722 //------------------------------xdual------------------------------------------
5723 // Dual: compute field-by-field dual
5724 const Type *TypeFunc::xdual() const {
5725 return this;
5726 }
5727
5728 //------------------------------eq---------------------------------------------
5729 // Structural equality check for Type representations
5730 bool TypeFunc::eq( const Type *t ) const {
5731 const TypeFunc *a = (const TypeFunc*)t;
5732 return _domain_sig == a->_domain_sig &&
5733 _domain_cc == a->_domain_cc &&
5734 _range_sig == a->_range_sig &&
5735 _range_cc == a->_range_cc;
5736 }
5737
5738 //------------------------------hash-------------------------------------------
5739 // Type-specific hashing function.
5740 int TypeFunc::hash(void) const {
5741 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5742 }
5743
5744 //------------------------------dump2------------------------------------------
5745 // Dump Function Type
5746 #ifndef PRODUCT
5747 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5748 if( _range_sig->cnt() <= Parms )
5749 st->print("void");
5750 else {
5751 uint i;
5752 for (i = Parms; i < _range_sig->cnt()-1; i++) {
5753 _range_sig->field_at(i)->dump2(d,depth,st);
5754 st->print("/");
5755 }
5756 _range_sig->field_at(i)->dump2(d,depth,st);
5757 }
5758 st->print(" ");
5759 st->print("( ");
5760 if( !depth || d[this] ) { // Check for recursive dump
5761 st->print("...)");
5762 return;
5763 }
5764 d.Insert((void*)this,(void*)this); // Stop recursion
5765 if (Parms < _domain_sig->cnt())
5766 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5767 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5768 st->print(", ");
5769 _domain_sig->field_at(i)->dump2(d,depth-1,st);
5770 }
5771 st->print(" )");
5772 }
5773 #endif
5774
5775 //------------------------------singleton--------------------------------------
5776 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5777 // constants (Ldi nodes). Singletons are integer, float or double constants
5778 // or a single symbol.
5779 bool TypeFunc::singleton(void) const {
5780 return false; // Never a singleton
5781 }
5782
5783 bool TypeFunc::empty(void) const {
5784 return false; // Never empty
5785 }
5786
5787
5788 BasicType TypeFunc::return_type() const{
5789 if (range_sig()->cnt() == TypeFunc::Parms) {
5790 return T_VOID;
5791 }
5792 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5793 }
|