comparison src/share/vm/opto/compile.cpp @ 276:aa8f54688692

Merge
author trims
date Sun, 10 Aug 2008 21:31:42 -0700
parents b0fe4deeb9fb
children c3e045194476
comparison
equal deleted inserted replaced
240:585535ec8a14 276:aa8f54688692
581 581
582 if (failing()) return; 582 if (failing()) return;
583 NOT_PRODUCT( verify_graph_edges(); ) 583 NOT_PRODUCT( verify_graph_edges(); )
584 584
585 // Perform escape analysis 585 // Perform escape analysis
586 if (_do_escape_analysis) 586 if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
587 _congraph = new ConnectionGraph(this); 587 TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, true);
588 if (_congraph != NULL) { 588 // Add ConP#NULL and ConN#NULL nodes before ConnectionGraph construction.
589 NOT_PRODUCT( TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, TimeCompiler); ) 589 PhaseGVN* igvn = initial_gvn();
590 _congraph->compute_escape(); 590 Node* oop_null = igvn->zerocon(T_OBJECT);
591 if (failing()) return; 591 Node* noop_null = igvn->zerocon(T_NARROWOOP);
592
593 _congraph = new(comp_arena()) ConnectionGraph(this);
594 bool has_non_escaping_obj = _congraph->compute_escape();
592 595
593 #ifndef PRODUCT 596 #ifndef PRODUCT
594 if (PrintEscapeAnalysis) { 597 if (PrintEscapeAnalysis) {
595 _congraph->dump(); 598 _congraph->dump();
596 } 599 }
597 #endif 600 #endif
601 // Cleanup.
602 if (oop_null->outcnt() == 0)
603 igvn->hash_delete(oop_null);
604 if (noop_null->outcnt() == 0)
605 igvn->hash_delete(noop_null);
606
607 if (!has_non_escaping_obj) {
608 _congraph = NULL;
609 }
610
611 if (failing()) return;
598 } 612 }
599 // Now optimize 613 // Now optimize
600 Optimize(); 614 Optimize();
601 if (failing()) return; 615 if (failing()) return;
602 NOT_PRODUCT( verify_graph_edges(); ) 616 NOT_PRODUCT( verify_graph_edges(); )
993 //------------------------------flatten_alias_type----------------------------- 1007 //------------------------------flatten_alias_type-----------------------------
994 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { 1008 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
995 int offset = tj->offset(); 1009 int offset = tj->offset();
996 TypePtr::PTR ptr = tj->ptr(); 1010 TypePtr::PTR ptr = tj->ptr();
997 1011
1012 // Known instance (scalarizable allocation) alias only with itself.
1013 bool is_known_inst = tj->isa_oopptr() != NULL &&
1014 tj->is_oopptr()->is_known_instance();
1015
998 // Process weird unsafe references. 1016 // Process weird unsafe references.
999 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) { 1017 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1000 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops"); 1018 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops");
1019 assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1001 tj = TypeOopPtr::BOTTOM; 1020 tj = TypeOopPtr::BOTTOM;
1002 ptr = tj->ptr(); 1021 ptr = tj->ptr();
1003 offset = tj->offset(); 1022 offset = tj->offset();
1004 } 1023 }
1005 1024
1006 // Array pointers need some flattening 1025 // Array pointers need some flattening
1007 const TypeAryPtr *ta = tj->isa_aryptr(); 1026 const TypeAryPtr *ta = tj->isa_aryptr();
1008 if( ta && _AliasLevel >= 2 ) { 1027 if( ta && is_known_inst ) {
1028 if ( offset != Type::OffsetBot &&
1029 offset > arrayOopDesc::length_offset_in_bytes() ) {
1030 offset = Type::OffsetBot; // Flatten constant access into array body only
1031 tj = ta = TypeAryPtr::make(ptr, ta->ary(), ta->klass(), true, offset, ta->instance_id());
1032 }
1033 } else if( ta && _AliasLevel >= 2 ) {
1009 // For arrays indexed by constant indices, we flatten the alias 1034 // For arrays indexed by constant indices, we flatten the alias
1010 // space to include all of the array body. Only the header, klass 1035 // space to include all of the array body. Only the header, klass
1011 // and array length can be accessed un-aliased. 1036 // and array length can be accessed un-aliased.
1012 if( offset != Type::OffsetBot ) { 1037 if( offset != Type::OffsetBot ) {
1013 if( ta->const_oop() ) { // methodDataOop or methodOop 1038 if( ta->const_oop() ) { // methodDataOop or methodOop
1014 offset = Type::OffsetBot; // Flatten constant access into array body 1039 offset = Type::OffsetBot; // Flatten constant access into array body
1015 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id()); 1040 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
1016 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) { 1041 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1017 // range is OK as-is. 1042 // range is OK as-is.
1018 tj = ta = TypeAryPtr::RANGE; 1043 tj = ta = TypeAryPtr::RANGE;
1019 } else if( offset == oopDesc::klass_offset_in_bytes() ) { 1044 } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1020 tj = TypeInstPtr::KLASS; // all klass loads look alike 1045 tj = TypeInstPtr::KLASS; // all klass loads look alike
1024 tj = TypeInstPtr::MARK; 1049 tj = TypeInstPtr::MARK;
1025 ta = TypeAryPtr::RANGE; // generic ignored junk 1050 ta = TypeAryPtr::RANGE; // generic ignored junk
1026 ptr = TypePtr::BotPTR; 1051 ptr = TypePtr::BotPTR;
1027 } else { // Random constant offset into array body 1052 } else { // Random constant offset into array body
1028 offset = Type::OffsetBot; // Flatten constant access into array body 1053 offset = Type::OffsetBot; // Flatten constant access into array body
1029 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id()); 1054 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,offset);
1030 } 1055 }
1031 } 1056 }
1032 // Arrays of fixed size alias with arrays of unknown size. 1057 // Arrays of fixed size alias with arrays of unknown size.
1033 if (ta->size() != TypeInt::POS) { 1058 if (ta->size() != TypeInt::POS) {
1034 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS); 1059 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1035 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset, ta->instance_id()); 1060 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset);
1036 } 1061 }
1037 // Arrays of known objects become arrays of unknown objects. 1062 // Arrays of known objects become arrays of unknown objects.
1038 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) { 1063 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1039 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size()); 1064 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1040 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset, ta->instance_id()); 1065 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);
1041 } 1066 }
1042 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) { 1067 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1043 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size()); 1068 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1044 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset, ta->instance_id()); 1069 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);
1045 } 1070 }
1046 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so 1071 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1047 // cannot be distinguished by bytecode alone. 1072 // cannot be distinguished by bytecode alone.
1048 if (ta->elem() == TypeInt::BOOL) { 1073 if (ta->elem() == TypeInt::BOOL) {
1049 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size()); 1074 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1050 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE); 1075 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1051 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset, ta->instance_id()); 1076 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
1052 } 1077 }
1053 // During the 2nd round of IterGVN, NotNull castings are removed. 1078 // During the 2nd round of IterGVN, NotNull castings are removed.
1054 // Make sure the Bottom and NotNull variants alias the same. 1079 // Make sure the Bottom and NotNull variants alias the same.
1055 // Also, make sure exact and non-exact variants alias the same. 1080 // Also, make sure exact and non-exact variants alias the same.
1056 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) { 1081 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) {
1066 const TypeInstPtr *to = tj->isa_instptr(); 1091 const TypeInstPtr *to = tj->isa_instptr();
1067 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) { 1092 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1068 if( ptr == TypePtr::Constant ) { 1093 if( ptr == TypePtr::Constant ) {
1069 // No constant oop pointers (such as Strings); they alias with 1094 // No constant oop pointers (such as Strings); they alias with
1070 // unknown strings. 1095 // unknown strings.
1096 assert(!is_known_inst, "not scalarizable allocation");
1071 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset); 1097 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1072 } else if( to->is_known_instance_field() ) { 1098 } else if( is_known_inst ) {
1073 tj = to; // Keep NotNull and klass_is_exact for instance type 1099 tj = to; // Keep NotNull and klass_is_exact for instance type
1074 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) { 1100 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1075 // During the 2nd round of IterGVN, NotNull castings are removed. 1101 // During the 2nd round of IterGVN, NotNull castings are removed.
1076 // Make sure the Bottom and NotNull variants alias the same. 1102 // Make sure the Bottom and NotNull variants alias the same.
1077 // Also, make sure exact and non-exact variants alias the same. 1103 // Also, make sure exact and non-exact variants alias the same.
1078 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset, to->instance_id()); 1104 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1079 } 1105 }
1080 // Canonicalize the holder of this field 1106 // Canonicalize the holder of this field
1081 ciInstanceKlass *k = to->klass()->as_instance_klass(); 1107 ciInstanceKlass *k = to->klass()->as_instance_klass();
1082 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) { 1108 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1083 // First handle header references such as a LoadKlassNode, even if the 1109 // First handle header references such as a LoadKlassNode, even if the
1084 // object's klass is unloaded at compile time (4965979). 1110 // object's klass is unloaded at compile time (4965979).
1085 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset, to->instance_id()); 1111 if (!is_known_inst) { // Do it only for non-instance types
1112 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset);
1113 }
1086 } else if (offset < 0 || offset >= k->size_helper() * wordSize) { 1114 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
1087 to = NULL; 1115 to = NULL;
1088 tj = TypeOopPtr::BOTTOM; 1116 tj = TypeOopPtr::BOTTOM;
1089 offset = tj->offset(); 1117 offset = tj->offset();
1090 } else { 1118 } else {
1091 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset); 1119 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1092 if (!k->equals(canonical_holder) || tj->offset() != offset) { 1120 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1093 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset, to->instance_id()); 1121 if( is_known_inst ) {
1122 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id());
1123 } else {
1124 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset);
1125 }
1094 } 1126 }
1095 } 1127 }
1096 } 1128 }
1097 1129
1098 // Klass pointers to object array klasses need some flattening 1130 // Klass pointers to object array klasses need some flattening
1274 #ifdef ASSERT 1306 #ifdef ASSERT
1275 assert(flat == flatten_alias_type(flat), "idempotent"); 1307 assert(flat == flatten_alias_type(flat), "idempotent");
1276 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr"); 1308 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr");
1277 if (flat->isa_oopptr() && !flat->isa_klassptr()) { 1309 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1278 const TypeOopPtr* foop = flat->is_oopptr(); 1310 const TypeOopPtr* foop = flat->is_oopptr();
1279 const TypePtr* xoop = foop->cast_to_exactness(!foop->klass_is_exact())->is_ptr(); 1311 // Scalarizable allocations have exact klass always.
1312 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
1313 const TypePtr* xoop = foop->cast_to_exactness(exact)->is_ptr();
1280 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type"); 1314 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type");
1281 } 1315 }
1282 assert(flat == flatten_alias_type(flat), "exact bit doesn't matter"); 1316 assert(flat == flatten_alias_type(flat), "exact bit doesn't matter");
1283 #endif 1317 #endif
1284 1318