1.1 --- a/src/share/vm/opto/graphKit.cpp Tue Mar 25 12:54:21 2014 -0700 1.2 +++ b/src/share/vm/opto/graphKit.cpp Tue Mar 25 17:07:36 2014 -0700 1.3 @@ -612,9 +612,10 @@ 1.4 // Usual case: Bail to interpreter. 1.5 // Reserve the right to recompile if we haven't seen anything yet. 1.6 1.7 + assert(!Deoptimization::reason_is_speculate(reason), "unsupported"); 1.8 Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile; 1.9 if (treat_throw_as_hot 1.10 - && (method()->method_data()->trap_recompiled_at(bci()) 1.11 + && (method()->method_data()->trap_recompiled_at(bci(), NULL) 1.12 || C->too_many_traps(reason))) { 1.13 // We cannot afford to take more traps here. Suffer in the interpreter. 1.14 if (C->log() != NULL) 1.15 @@ -1124,6 +1125,17 @@ 1.16 } 1.17 return _gvn.transform( new (C) ConvI2LNode(offset)); 1.18 } 1.19 + 1.20 +Node* GraphKit::ConvI2UL(Node* offset) { 1.21 + juint offset_con = (juint) find_int_con(offset, Type::OffsetBot); 1.22 + if (offset_con != (juint) Type::OffsetBot) { 1.23 + return longcon((julong) offset_con); 1.24 + } 1.25 + Node* conv = _gvn.transform( new (C) ConvI2LNode(offset)); 1.26 + Node* mask = _gvn.transform( ConLNode::make(C, (julong) max_juint) ); 1.27 + return _gvn.transform( new (C) AndLNode(conv, mask) ); 1.28 +} 1.29 + 1.30 Node* GraphKit::ConvL2I(Node* offset) { 1.31 // short-circuit a common case 1.32 jlong offset_con = find_long_con(offset, (jlong)Type::OffsetBot); 1.33 @@ -2112,30 +2124,33 @@ 1.34 * @return node with improved type 1.35 */ 1.36 Node* GraphKit::record_profile_for_speculation(Node* n, ciKlass* exact_kls) { 1.37 - const TypeOopPtr* current_type = _gvn.type(n)->isa_oopptr(); 1.38 + const Type* current_type = _gvn.type(n); 1.39 assert(UseTypeSpeculation, "type speculation must be on"); 1.40 - if (exact_kls != NULL && 1.41 - // nothing to improve if type is already exact 1.42 - (current_type == NULL || 1.43 - (!current_type->klass_is_exact() && 1.44 - (current_type->speculative() == NULL || 1.45 - !current_type->speculative()->klass_is_exact())))) { 1.46 + 1.47 + const TypeOopPtr* speculative = current_type->speculative(); 1.48 + 1.49 + if (current_type->would_improve_type(exact_kls, jvms()->depth())) { 1.50 const TypeKlassPtr* tklass = TypeKlassPtr::make(exact_kls); 1.51 const TypeOopPtr* xtype = tklass->as_instance_type(); 1.52 assert(xtype->klass_is_exact(), "Should be exact"); 1.53 - 1.54 + // record the new speculative type's depth 1.55 + speculative = xtype->with_inline_depth(jvms()->depth()); 1.56 + } 1.57 + 1.58 + if (speculative != current_type->speculative()) { 1.59 // Build a type with a speculative type (what we think we know 1.60 // about the type but will need a guard when we use it) 1.61 - const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::OffsetBot, TypeOopPtr::InstanceBot, xtype); 1.62 - // We're changing the type, we need a new cast node to carry the 1.63 - // new type. The new type depends on the control: what profiling 1.64 - // tells us is only valid from here as far as we can tell. 1.65 - Node* cast = new(C) CastPPNode(n, spec_type); 1.66 - cast->init_req(0, control()); 1.67 + const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::OffsetBot, TypeOopPtr::InstanceBot, speculative); 1.68 + // We're changing the type, we need a new CheckCast node to carry 1.69 + // the new type. The new type depends on the control: what 1.70 + // profiling tells us is only valid from here as far as we can 1.71 + // tell. 1.72 + Node* cast = new(C) CheckCastPPNode(control(), n, current_type->remove_speculative()->join_speculative(spec_type)); 1.73 cast = _gvn.transform(cast); 1.74 replace_in_map(n, cast); 1.75 n = cast; 1.76 } 1.77 + 1.78 return n; 1.79 } 1.80 1.81 @@ -2145,7 +2160,7 @@ 1.82 * 1.83 * @param n receiver node 1.84 * 1.85 - * @return node with improved type 1.86 + * @return node with improved type 1.87 */ 1.88 Node* GraphKit::record_profiled_receiver_for_speculation(Node* n) { 1.89 if (!UseTypeSpeculation) { 1.90 @@ -2739,12 +2754,14 @@ 1.91 // Subsequent type checks will always fold up. 1.92 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj, 1.93 ciKlass* require_klass, 1.94 - ciKlass* spec_klass, 1.95 + ciKlass* spec_klass, 1.96 bool safe_for_replace) { 1.97 if (!UseTypeProfile || !TypeProfileCasts) return NULL; 1.98 1.99 + Deoptimization::DeoptReason reason = spec_klass == NULL ? Deoptimization::Reason_class_check : Deoptimization::Reason_speculate_class_check; 1.100 + 1.101 // Make sure we haven't already deoptimized from this tactic. 1.102 - if (too_many_traps(Deoptimization::Reason_class_check)) 1.103 + if (too_many_traps(reason)) 1.104 return NULL; 1.105 1.106 // (No, this isn't a call, but it's enough like a virtual call 1.107 @@ -2766,7 +2783,7 @@ 1.108 &exact_obj); 1.109 { PreserveJVMState pjvms(this); 1.110 set_control(slow_ctl); 1.111 - uncommon_trap(Deoptimization::Reason_class_check, 1.112 + uncommon_trap(reason, 1.113 Deoptimization::Action_maybe_recompile); 1.114 } 1.115 if (safe_for_replace) { 1.116 @@ -2793,8 +2810,10 @@ 1.117 bool not_null) { 1.118 // type == NULL if profiling tells us this object is always null 1.119 if (type != NULL) { 1.120 - if (!too_many_traps(Deoptimization::Reason_null_check) && 1.121 - !too_many_traps(Deoptimization::Reason_class_check)) { 1.122 + Deoptimization::DeoptReason class_reason = Deoptimization::Reason_speculate_class_check; 1.123 + Deoptimization::DeoptReason null_reason = Deoptimization::Reason_null_check; 1.124 + if (!too_many_traps(null_reason) && 1.125 + !too_many_traps(class_reason)) { 1.126 Node* not_null_obj = NULL; 1.127 // not_null is true if we know the object is not null and 1.128 // there's no need for a null check 1.129 @@ -2813,7 +2832,7 @@ 1.130 { 1.131 PreserveJVMState pjvms(this); 1.132 set_control(slow_ctl); 1.133 - uncommon_trap(Deoptimization::Reason_class_check, 1.134 + uncommon_trap(class_reason, 1.135 Deoptimization::Action_maybe_recompile); 1.136 } 1.137 replace_in_map(not_null_obj, exact_obj); 1.138 @@ -2882,7 +2901,7 @@ 1.139 } 1.140 1.141 if (known_statically && UseTypeSpeculation) { 1.142 - // If we know the type check always succeed then we don't use the 1.143 + // If we know the type check always succeeds then we don't use the 1.144 // profiling data at this bytecode. Don't lose it, feed it to the 1.145 // type system as a speculative type. 1.146 not_null_obj = record_profiled_receiver_for_speculation(not_null_obj); 1.147 @@ -2999,22 +3018,28 @@ 1.148 } 1.149 1.150 Node* cast_obj = NULL; 1.151 - const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 1.152 - // We may not have profiling here or it may not help us. If we have 1.153 - // a speculative type use it to perform an exact cast. 1.154 - ciKlass* spec_obj_type = obj_type->speculative_type(); 1.155 - if (spec_obj_type != NULL || 1.156 - (data != NULL && 1.157 - // Counter has never been decremented (due to cast failure). 1.158 - // ...This is a reasonable thing to expect. It is true of 1.159 - // all casts inserted by javac to implement generic types. 1.160 - data->as_CounterData()->count() >= 0)) { 1.161 - cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace); 1.162 - if (cast_obj != NULL) { 1.163 - if (failure_control != NULL) // failure is now impossible 1.164 - (*failure_control) = top(); 1.165 - // adjust the type of the phi to the exact klass: 1.166 - phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR)); 1.167 + if (tk->klass_is_exact()) { 1.168 + // The following optimization tries to statically cast the speculative type of the object 1.169 + // (for example obtained during profiling) to the type of the superklass and then do a 1.170 + // dynamic check that the type of the object is what we expect. To work correctly 1.171 + // for checkcast and aastore the type of superklass should be exact. 1.172 + const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); 1.173 + // We may not have profiling here or it may not help us. If we have 1.174 + // a speculative type use it to perform an exact cast. 1.175 + ciKlass* spec_obj_type = obj_type->speculative_type(); 1.176 + if (spec_obj_type != NULL || 1.177 + (data != NULL && 1.178 + // Counter has never been decremented (due to cast failure). 1.179 + // ...This is a reasonable thing to expect. It is true of 1.180 + // all casts inserted by javac to implement generic types. 1.181 + data->as_CounterData()->count() >= 0)) { 1.182 + cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace); 1.183 + if (cast_obj != NULL) { 1.184 + if (failure_control != NULL) // failure is now impossible 1.185 + (*failure_control) = top(); 1.186 + // adjust the type of the phi to the exact klass: 1.187 + phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR)); 1.188 + } 1.189 } 1.190 } 1.191 1.192 @@ -3137,10 +3162,14 @@ 1.193 Node* mem = reset_memory(); 1.194 1.195 FastLockNode * flock = _gvn.transform(new (C) FastLockNode(0, obj, box) )->as_FastLock(); 1.196 - if (PrintPreciseBiasedLockingStatistics) { 1.197 + if (UseBiasedLocking && PrintPreciseBiasedLockingStatistics) { 1.198 // Create the counters for this fast lock. 1.199 flock->create_lock_counter(sync_jvms()); // sync_jvms used to get current bci 1.200 } 1.201 + 1.202 + // Create the rtm counters for this fast lock if needed. 1.203 + flock->create_rtm_lock_counter(sync_jvms()); // sync_jvms used to get current bci 1.204 + 1.205 // Add monitor to debug info for the slow path. If we block inside the 1.206 // slow path and de-opt, we need the monitor hanging around 1.207 map()->push_monitor( flock );