1292 //----------- |
1292 //----------- |
1293 // Branch to failure if null |
1293 // Branch to failure if null |
1294 float ok_prob = PROB_MAX; // a priori estimate: nulls never happen |
1294 float ok_prob = PROB_MAX; // a priori estimate: nulls never happen |
1295 Deoptimization::DeoptReason reason; |
1295 Deoptimization::DeoptReason reason; |
1296 if (assert_null) { |
1296 if (assert_null) { |
1297 reason = Deoptimization::Reason_null_assert; |
1297 reason = Deoptimization::reason_null_assert(speculative); |
1298 } else if (type == T_OBJECT) { |
1298 } else if (type == T_OBJECT) { |
1299 reason = Deoptimization::reason_null_check(speculative); |
1299 reason = Deoptimization::reason_null_check(speculative); |
1300 } else { |
1300 } else { |
1301 reason = Deoptimization::Reason_div0_check; |
1301 reason = Deoptimization::Reason_div0_check; |
1302 } |
1302 } |
2131 * @param exact_kls type from profiling |
2131 * @param exact_kls type from profiling |
2132 * @param maybe_null did profiling see null? |
2132 * @param maybe_null did profiling see null? |
2133 * |
2133 * |
2134 * @return node with improved type |
2134 * @return node with improved type |
2135 */ |
2135 */ |
2136 Node* GraphKit::record_profile_for_speculation(Node* n, ciKlass* exact_kls, bool maybe_null) { |
2136 Node* GraphKit::record_profile_for_speculation(Node* n, ciKlass* exact_kls, ProfilePtrKind ptr_kind) { |
2137 const Type* current_type = _gvn.type(n); |
2137 const Type* current_type = _gvn.type(n); |
2138 assert(UseTypeSpeculation, "type speculation must be on"); |
2138 assert(UseTypeSpeculation, "type speculation must be on"); |
2139 |
2139 |
2140 const TypePtr* speculative = current_type->speculative(); |
2140 const TypePtr* speculative = current_type->speculative(); |
2141 |
2141 |
2143 if (current_type->would_improve_type(exact_kls, jvms()->depth())) { |
2143 if (current_type->would_improve_type(exact_kls, jvms()->depth())) { |
2144 const TypeKlassPtr* tklass = TypeKlassPtr::make(exact_kls); |
2144 const TypeKlassPtr* tklass = TypeKlassPtr::make(exact_kls); |
2145 const TypeOopPtr* xtype = tklass->as_instance_type(); |
2145 const TypeOopPtr* xtype = tklass->as_instance_type(); |
2146 assert(xtype->klass_is_exact(), "Should be exact"); |
2146 assert(xtype->klass_is_exact(), "Should be exact"); |
2147 // Any reason to believe n is not null (from this profiling or a previous one)? |
2147 // Any reason to believe n is not null (from this profiling or a previous one)? |
2148 const TypePtr* ptr = (maybe_null && current_type->speculative_maybe_null()) ? TypePtr::BOTTOM : TypePtr::NOTNULL; |
2148 assert(ptr_kind != ProfileAlwaysNull, "impossible here"); |
|
2149 const TypePtr* ptr = (ptr_kind == ProfileMaybeNull && current_type->speculative_maybe_null()) ? TypePtr::BOTTOM : TypePtr::NOTNULL; |
2149 // record the new speculative type's depth |
2150 // record the new speculative type's depth |
2150 speculative = xtype->cast_to_ptr_type(ptr->ptr())->is_ptr(); |
2151 speculative = xtype->cast_to_ptr_type(ptr->ptr())->is_ptr(); |
2151 speculative = speculative->with_inline_depth(jvms()->depth()); |
2152 speculative = speculative->with_inline_depth(jvms()->depth()); |
2152 } else if (current_type->would_improve_ptr(maybe_null)) { |
2153 } else if (current_type->would_improve_ptr(ptr_kind)) { |
2153 // Profiling report that null was never seen so we can change the |
2154 // Profiling report that null was never seen so we can change the |
2154 // speculative type to non null ptr. |
2155 // speculative type to non null ptr. |
2155 assert(!maybe_null, "nothing to improve"); |
2156 if (ptr_kind == ProfileAlwaysNull) { |
2156 if (speculative == NULL) { |
2157 speculative = TypePtr::NULL_PTR; |
2157 speculative = TypePtr::NOTNULL; |
|
2158 } else { |
2158 } else { |
|
2159 assert(ptr_kind == ProfileNeverNull, "nothing else is an improvement"); |
2159 const TypePtr* ptr = TypePtr::NOTNULL; |
2160 const TypePtr* ptr = TypePtr::NOTNULL; |
2160 speculative = speculative->cast_to_ptr_type(ptr->ptr())->is_ptr(); |
2161 if (speculative != NULL) { |
|
2162 speculative = speculative->cast_to_ptr_type(ptr->ptr())->is_ptr(); |
|
2163 } else { |
|
2164 speculative = ptr; |
|
2165 } |
2161 } |
2166 } |
2162 } |
2167 } |
2163 |
2168 |
2164 if (speculative != current_type->speculative()) { |
2169 if (speculative != current_type->speculative()) { |
2165 // Build a type with a speculative type (what we think we know |
2170 // Build a type with a speculative type (what we think we know |
2189 Node* GraphKit::record_profiled_receiver_for_speculation(Node* n) { |
2194 Node* GraphKit::record_profiled_receiver_for_speculation(Node* n) { |
2190 if (!UseTypeSpeculation) { |
2195 if (!UseTypeSpeculation) { |
2191 return n; |
2196 return n; |
2192 } |
2197 } |
2193 ciKlass* exact_kls = profile_has_unique_klass(); |
2198 ciKlass* exact_kls = profile_has_unique_klass(); |
2194 bool maybe_null = true; |
2199 ProfilePtrKind ptr_kind = ProfileMaybeNull; |
2195 if (java_bc() == Bytecodes::_checkcast || |
2200 if ((java_bc() == Bytecodes::_checkcast || |
2196 java_bc() == Bytecodes::_instanceof || |
2201 java_bc() == Bytecodes::_instanceof || |
2197 java_bc() == Bytecodes::_aastore) { |
2202 java_bc() == Bytecodes::_aastore) && |
|
2203 method()->method_data()->is_mature()) { |
2198 ciProfileData* data = method()->method_data()->bci_to_data(bci()); |
2204 ciProfileData* data = method()->method_data()->bci_to_data(bci()); |
2199 maybe_null = data == NULL ? true : data->as_BitData()->null_seen(); |
2205 if (data != NULL) { |
2200 } |
2206 if (!data->as_BitData()->null_seen()) { |
2201 return record_profile_for_speculation(n, exact_kls, maybe_null); |
2207 ptr_kind = ProfileNeverNull; |
|
2208 } else { |
|
2209 assert(data->is_ReceiverTypeData(), "bad profile data type"); |
|
2210 ciReceiverTypeData* call = (ciReceiverTypeData*)data->as_ReceiverTypeData(); |
|
2211 uint i = 0; |
|
2212 for (; i < call->row_limit(); i++) { |
|
2213 ciKlass* receiver = call->receiver(i); |
|
2214 if (receiver != NULL) { |
|
2215 break; |
|
2216 } |
|
2217 } |
|
2218 ptr_kind = (i == call->row_limit()) ? ProfileAlwaysNull : ProfileMaybeNull; |
|
2219 } |
|
2220 } |
|
2221 } |
|
2222 return record_profile_for_speculation(n, exact_kls, ptr_kind); |
2202 } |
2223 } |
2203 |
2224 |
2204 /** |
2225 /** |
2205 * Record profiling data from argument profiling at an invoke with the |
2226 * Record profiling data from argument profiling at an invoke with the |
2206 * type system so that it can propagate it (speculation) |
2227 * type system so that it can propagate it (speculation) |
2216 int nargs = tf->domain()->cnt() - TypeFunc::Parms; |
2237 int nargs = tf->domain()->cnt() - TypeFunc::Parms; |
2217 int skip = Bytecodes::has_receiver(bc) ? 1 : 0; |
2238 int skip = Bytecodes::has_receiver(bc) ? 1 : 0; |
2218 for (int j = skip, i = 0; j < nargs && i < TypeProfileArgsLimit; j++) { |
2239 for (int j = skip, i = 0; j < nargs && i < TypeProfileArgsLimit; j++) { |
2219 const Type *targ = tf->domain()->field_at(j + TypeFunc::Parms); |
2240 const Type *targ = tf->domain()->field_at(j + TypeFunc::Parms); |
2220 if (targ->basic_type() == T_OBJECT || targ->basic_type() == T_ARRAY) { |
2241 if (targ->basic_type() == T_OBJECT || targ->basic_type() == T_ARRAY) { |
2221 bool maybe_null = true; |
2242 ProfilePtrKind ptr_kind = ProfileMaybeNull; |
2222 ciKlass* better_type = NULL; |
2243 ciKlass* better_type = NULL; |
2223 if (method()->argument_profiled_type(bci(), i, better_type, maybe_null)) { |
2244 if (method()->argument_profiled_type(bci(), i, better_type, ptr_kind)) { |
2224 record_profile_for_speculation(argument(j), better_type, maybe_null); |
2245 record_profile_for_speculation(argument(j), better_type, ptr_kind); |
2225 } |
2246 } |
2226 i++; |
2247 i++; |
2227 } |
2248 } |
2228 } |
2249 } |
2229 } |
2250 } |
2236 if (!UseTypeSpeculation) { |
2257 if (!UseTypeSpeculation) { |
2237 return; |
2258 return; |
2238 } |
2259 } |
2239 for (int i = 0, j = 0; i < method()->arg_size() ; i++) { |
2260 for (int i = 0, j = 0; i < method()->arg_size() ; i++) { |
2240 if (_gvn.type(local(i))->isa_oopptr()) { |
2261 if (_gvn.type(local(i))->isa_oopptr()) { |
2241 bool maybe_null = true; |
2262 ProfilePtrKind ptr_kind = ProfileMaybeNull; |
2242 ciKlass* better_type = NULL; |
2263 ciKlass* better_type = NULL; |
2243 if (method()->parameter_profiled_type(j, better_type, maybe_null)) { |
2264 if (method()->parameter_profiled_type(j, better_type, ptr_kind)) { |
2244 record_profile_for_speculation(local(i), better_type, maybe_null); |
2265 record_profile_for_speculation(local(i), better_type, ptr_kind); |
2245 } |
2266 } |
2246 j++; |
2267 j++; |
2247 } |
2268 } |
2248 } |
2269 } |
2249 } |
2270 } |
2254 */ |
2275 */ |
2255 void GraphKit::record_profiled_return_for_speculation() { |
2276 void GraphKit::record_profiled_return_for_speculation() { |
2256 if (!UseTypeSpeculation) { |
2277 if (!UseTypeSpeculation) { |
2257 return; |
2278 return; |
2258 } |
2279 } |
2259 bool maybe_null = true; |
2280 ProfilePtrKind ptr_kind = ProfileMaybeNull; |
2260 ciKlass* better_type = NULL; |
2281 ciKlass* better_type = NULL; |
2261 if (method()->return_profiled_type(bci(), better_type, maybe_null)) { |
2282 if (method()->return_profiled_type(bci(), better_type, ptr_kind)) { |
2262 // If profiling reports a single type for the return value, |
2283 // If profiling reports a single type for the return value, |
2263 // feed it to the type system so it can propagate it as a |
2284 // feed it to the type system so it can propagate it as a |
2264 // speculative type |
2285 // speculative type |
2265 record_profile_for_speculation(stack(sp()-1), better_type, maybe_null); |
2286 record_profile_for_speculation(stack(sp()-1), better_type, ptr_kind); |
2266 } |
2287 } |
2267 } |
2288 } |
2268 |
2289 |
2269 void GraphKit::round_double_result(ciMethod* dest_method) { |
2290 void GraphKit::round_double_result(ciMethod* dest_method) { |
2270 // A non-strict method may return a double value which has an extended |
2291 // A non-strict method may return a double value which has an extended |
2936 int static_res = C->static_subtype_check(superk, subk); |
2957 int static_res = C->static_subtype_check(superk, subk); |
2937 known_statically = (static_res == Compile::SSC_always_true || static_res == Compile::SSC_always_false); |
2958 known_statically = (static_res == Compile::SSC_always_true || static_res == Compile::SSC_always_false); |
2938 } |
2959 } |
2939 } |
2960 } |
2940 |
2961 |
2941 if (known_statically && UseTypeSpeculation) { |
2962 if (!known_statically) { |
2942 // If we know the type check always succeeds then we don't use the |
|
2943 // profiling data at this bytecode. Don't lose it, feed it to the |
|
2944 // type system as a speculative type. |
|
2945 not_null_obj = record_profiled_receiver_for_speculation(not_null_obj); |
|
2946 } else { |
|
2947 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); |
2963 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); |
2948 // We may not have profiling here or it may not help us. If we |
2964 // We may not have profiling here or it may not help us. If we |
2949 // have a speculative type use it to perform an exact cast. |
2965 // have a speculative type use it to perform an exact cast. |
2950 ciKlass* spec_obj_type = obj_type->speculative_type(); |
2966 ciKlass* spec_obj_type = obj_type->speculative_type(); |
2951 if (spec_obj_type != NULL || (ProfileDynamicTypes && data != NULL)) { |
2967 if (spec_obj_type != NULL || (ProfileDynamicTypes && data != NULL)) { |
2975 phi ->init_req(_fail_path, intcon(0)); |
2991 phi ->init_req(_fail_path, intcon(0)); |
2976 |
2992 |
2977 // Return final merged results |
2993 // Return final merged results |
2978 set_control( _gvn.transform(region) ); |
2994 set_control( _gvn.transform(region) ); |
2979 record_for_igvn(region); |
2995 record_for_igvn(region); |
|
2996 |
|
2997 // If we know the type check always succeeds then we don't use the |
|
2998 // profiling data at this bytecode. Don't lose it, feed it to the |
|
2999 // type system as a speculative type. |
|
3000 if (safe_for_replace) { |
|
3001 Node* casted_obj = record_profiled_receiver_for_speculation(obj); |
|
3002 replace_in_map(obj, casted_obj); |
|
3003 } |
|
3004 |
2980 return _gvn.transform(phi); |
3005 return _gvn.transform(phi); |
2981 } |
3006 } |
2982 |
3007 |
2983 //-------------------------------gen_checkcast--------------------------------- |
3008 //-------------------------------gen_checkcast--------------------------------- |
2984 // Generate a checkcast idiom. Used by both the checkcast bytecode and the |
3009 // Generate a checkcast idiom. Used by both the checkcast bytecode and the |
3115 // replace_in_map( obj, res ); |
3140 // replace_in_map( obj, res ); |
3116 |
3141 |
3117 // Return final merged results |
3142 // Return final merged results |
3118 set_control( _gvn.transform(region) ); |
3143 set_control( _gvn.transform(region) ); |
3119 record_for_igvn(region); |
3144 record_for_igvn(region); |
3120 return res; |
3145 |
|
3146 return record_profiled_receiver_for_speculation(res); |
3121 } |
3147 } |
3122 |
3148 |
3123 //------------------------------next_monitor----------------------------------- |
3149 //------------------------------next_monitor----------------------------------- |
3124 // What number should be given to the next monitor? |
3150 // What number should be given to the next monitor? |
3125 int GraphKit::next_monitor() { |
3151 int GraphKit::next_monitor() { |