Mercurial > hg > truffle
comparison src/share/vm/opto/graphKit.cpp @ 17810:62c54fcc0a35
Merge
author | kvn |
---|---|
date | Tue, 25 Mar 2014 17:07:36 -0700 |
parents | 752ba2e5f6d0 606acabe7b5c |
children | 00c8a1255912 |
comparison
equal
deleted
inserted
replaced
17809:a433eb716ce1 | 17810:62c54fcc0a35 |
---|---|
610 // create the stack trace. | 610 // create the stack trace. |
611 | 611 |
612 // Usual case: Bail to interpreter. | 612 // Usual case: Bail to interpreter. |
613 // Reserve the right to recompile if we haven't seen anything yet. | 613 // Reserve the right to recompile if we haven't seen anything yet. |
614 | 614 |
615 assert(!Deoptimization::reason_is_speculate(reason), "unsupported"); | |
615 Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile; | 616 Deoptimization::DeoptAction action = Deoptimization::Action_maybe_recompile; |
616 if (treat_throw_as_hot | 617 if (treat_throw_as_hot |
617 && (method()->method_data()->trap_recompiled_at(bci()) | 618 && (method()->method_data()->trap_recompiled_at(bci(), NULL) |
618 || C->too_many_traps(reason))) { | 619 || C->too_many_traps(reason))) { |
619 // We cannot afford to take more traps here. Suffer in the interpreter. | 620 // We cannot afford to take more traps here. Suffer in the interpreter. |
620 if (C->log() != NULL) | 621 if (C->log() != NULL) |
621 C->log()->elem("hot_throw preallocated='0' reason='%s' mcount='%d'", | 622 C->log()->elem("hot_throw preallocated='0' reason='%s' mcount='%d'", |
622 Deoptimization::trap_reason_name(reason), | 623 Deoptimization::trap_reason_name(reason), |
1122 if (offset_con != Type::OffsetBot) { | 1123 if (offset_con != Type::OffsetBot) { |
1123 return longcon((jlong) offset_con); | 1124 return longcon((jlong) offset_con); |
1124 } | 1125 } |
1125 return _gvn.transform( new (C) ConvI2LNode(offset)); | 1126 return _gvn.transform( new (C) ConvI2LNode(offset)); |
1126 } | 1127 } |
1128 | |
1129 Node* GraphKit::ConvI2UL(Node* offset) { | |
1130 juint offset_con = (juint) find_int_con(offset, Type::OffsetBot); | |
1131 if (offset_con != (juint) Type::OffsetBot) { | |
1132 return longcon((julong) offset_con); | |
1133 } | |
1134 Node* conv = _gvn.transform( new (C) ConvI2LNode(offset)); | |
1135 Node* mask = _gvn.transform( ConLNode::make(C, (julong) max_juint) ); | |
1136 return _gvn.transform( new (C) AndLNode(conv, mask) ); | |
1137 } | |
1138 | |
1127 Node* GraphKit::ConvL2I(Node* offset) { | 1139 Node* GraphKit::ConvL2I(Node* offset) { |
1128 // short-circuit a common case | 1140 // short-circuit a common case |
1129 jlong offset_con = find_long_con(offset, (jlong)Type::OffsetBot); | 1141 jlong offset_con = find_long_con(offset, (jlong)Type::OffsetBot); |
1130 if (offset_con != (jlong)Type::OffsetBot) { | 1142 if (offset_con != (jlong)Type::OffsetBot) { |
1131 return intcon((int) offset_con); | 1143 return intcon((int) offset_con); |
2110 * @param exact_kls type from profiling | 2122 * @param exact_kls type from profiling |
2111 * | 2123 * |
2112 * @return node with improved type | 2124 * @return node with improved type |
2113 */ | 2125 */ |
2114 Node* GraphKit::record_profile_for_speculation(Node* n, ciKlass* exact_kls) { | 2126 Node* GraphKit::record_profile_for_speculation(Node* n, ciKlass* exact_kls) { |
2115 const TypeOopPtr* current_type = _gvn.type(n)->isa_oopptr(); | 2127 const Type* current_type = _gvn.type(n); |
2116 assert(UseTypeSpeculation, "type speculation must be on"); | 2128 assert(UseTypeSpeculation, "type speculation must be on"); |
2117 if (exact_kls != NULL && | 2129 |
2118 // nothing to improve if type is already exact | 2130 const TypeOopPtr* speculative = current_type->speculative(); |
2119 (current_type == NULL || | 2131 |
2120 (!current_type->klass_is_exact() && | 2132 if (current_type->would_improve_type(exact_kls, jvms()->depth())) { |
2121 (current_type->speculative() == NULL || | |
2122 !current_type->speculative()->klass_is_exact())))) { | |
2123 const TypeKlassPtr* tklass = TypeKlassPtr::make(exact_kls); | 2133 const TypeKlassPtr* tklass = TypeKlassPtr::make(exact_kls); |
2124 const TypeOopPtr* xtype = tklass->as_instance_type(); | 2134 const TypeOopPtr* xtype = tklass->as_instance_type(); |
2125 assert(xtype->klass_is_exact(), "Should be exact"); | 2135 assert(xtype->klass_is_exact(), "Should be exact"); |
2126 | 2136 // record the new speculative type's depth |
2137 speculative = xtype->with_inline_depth(jvms()->depth()); | |
2138 } | |
2139 | |
2140 if (speculative != current_type->speculative()) { | |
2127 // Build a type with a speculative type (what we think we know | 2141 // Build a type with a speculative type (what we think we know |
2128 // about the type but will need a guard when we use it) | 2142 // about the type but will need a guard when we use it) |
2129 const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::OffsetBot, TypeOopPtr::InstanceBot, xtype); | 2143 const TypeOopPtr* spec_type = TypeOopPtr::make(TypePtr::BotPTR, Type::OffsetBot, TypeOopPtr::InstanceBot, speculative); |
2130 // We're changing the type, we need a new cast node to carry the | 2144 // We're changing the type, we need a new CheckCast node to carry |
2131 // new type. The new type depends on the control: what profiling | 2145 // the new type. The new type depends on the control: what |
2132 // tells us is only valid from here as far as we can tell. | 2146 // profiling tells us is only valid from here as far as we can |
2133 Node* cast = new(C) CastPPNode(n, spec_type); | 2147 // tell. |
2134 cast->init_req(0, control()); | 2148 Node* cast = new(C) CheckCastPPNode(control(), n, current_type->remove_speculative()->join_speculative(spec_type)); |
2135 cast = _gvn.transform(cast); | 2149 cast = _gvn.transform(cast); |
2136 replace_in_map(n, cast); | 2150 replace_in_map(n, cast); |
2137 n = cast; | 2151 n = cast; |
2138 } | 2152 } |
2153 | |
2139 return n; | 2154 return n; |
2140 } | 2155 } |
2141 | 2156 |
2142 /** | 2157 /** |
2143 * Record profiling data from receiver profiling at an invoke with the | 2158 * Record profiling data from receiver profiling at an invoke with the |
2144 * type system so that it can propagate it (speculation) | 2159 * type system so that it can propagate it (speculation) |
2145 * | 2160 * |
2146 * @param n receiver node | 2161 * @param n receiver node |
2147 * | 2162 * |
2148 * @return node with improved type | 2163 * @return node with improved type |
2149 */ | 2164 */ |
2150 Node* GraphKit::record_profiled_receiver_for_speculation(Node* n) { | 2165 Node* GraphKit::record_profiled_receiver_for_speculation(Node* n) { |
2151 if (!UseTypeSpeculation) { | 2166 if (!UseTypeSpeculation) { |
2152 return n; | 2167 return n; |
2153 } | 2168 } |
2737 //------------------------maybe_cast_profiled_receiver------------------------- | 2752 //------------------------maybe_cast_profiled_receiver------------------------- |
2738 // If the profile has seen exactly one type, narrow to exactly that type. | 2753 // If the profile has seen exactly one type, narrow to exactly that type. |
2739 // Subsequent type checks will always fold up. | 2754 // Subsequent type checks will always fold up. |
2740 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj, | 2755 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj, |
2741 ciKlass* require_klass, | 2756 ciKlass* require_klass, |
2742 ciKlass* spec_klass, | 2757 ciKlass* spec_klass, |
2743 bool safe_for_replace) { | 2758 bool safe_for_replace) { |
2744 if (!UseTypeProfile || !TypeProfileCasts) return NULL; | 2759 if (!UseTypeProfile || !TypeProfileCasts) return NULL; |
2745 | 2760 |
2761 Deoptimization::DeoptReason reason = spec_klass == NULL ? Deoptimization::Reason_class_check : Deoptimization::Reason_speculate_class_check; | |
2762 | |
2746 // Make sure we haven't already deoptimized from this tactic. | 2763 // Make sure we haven't already deoptimized from this tactic. |
2747 if (too_many_traps(Deoptimization::Reason_class_check)) | 2764 if (too_many_traps(reason)) |
2748 return NULL; | 2765 return NULL; |
2749 | 2766 |
2750 // (No, this isn't a call, but it's enough like a virtual call | 2767 // (No, this isn't a call, but it's enough like a virtual call |
2751 // to use the same ciMethod accessor to get the profile info...) | 2768 // to use the same ciMethod accessor to get the profile info...) |
2752 // If we have a speculative type use it instead of profiling (which | 2769 // If we have a speculative type use it instead of profiling (which |
2764 Node* exact_obj = not_null_obj; // will get updated in place... | 2781 Node* exact_obj = not_null_obj; // will get updated in place... |
2765 Node* slow_ctl = type_check_receiver(exact_obj, exact_kls, 1.0, | 2782 Node* slow_ctl = type_check_receiver(exact_obj, exact_kls, 1.0, |
2766 &exact_obj); | 2783 &exact_obj); |
2767 { PreserveJVMState pjvms(this); | 2784 { PreserveJVMState pjvms(this); |
2768 set_control(slow_ctl); | 2785 set_control(slow_ctl); |
2769 uncommon_trap(Deoptimization::Reason_class_check, | 2786 uncommon_trap(reason, |
2770 Deoptimization::Action_maybe_recompile); | 2787 Deoptimization::Action_maybe_recompile); |
2771 } | 2788 } |
2772 if (safe_for_replace) { | 2789 if (safe_for_replace) { |
2773 replace_in_map(not_null_obj, exact_obj); | 2790 replace_in_map(not_null_obj, exact_obj); |
2774 } | 2791 } |
2791 Node* GraphKit::maybe_cast_profiled_obj(Node* obj, | 2808 Node* GraphKit::maybe_cast_profiled_obj(Node* obj, |
2792 ciKlass* type, | 2809 ciKlass* type, |
2793 bool not_null) { | 2810 bool not_null) { |
2794 // type == NULL if profiling tells us this object is always null | 2811 // type == NULL if profiling tells us this object is always null |
2795 if (type != NULL) { | 2812 if (type != NULL) { |
2796 if (!too_many_traps(Deoptimization::Reason_null_check) && | 2813 Deoptimization::DeoptReason class_reason = Deoptimization::Reason_speculate_class_check; |
2797 !too_many_traps(Deoptimization::Reason_class_check)) { | 2814 Deoptimization::DeoptReason null_reason = Deoptimization::Reason_null_check; |
2815 if (!too_many_traps(null_reason) && | |
2816 !too_many_traps(class_reason)) { | |
2798 Node* not_null_obj = NULL; | 2817 Node* not_null_obj = NULL; |
2799 // not_null is true if we know the object is not null and | 2818 // not_null is true if we know the object is not null and |
2800 // there's no need for a null check | 2819 // there's no need for a null check |
2801 if (!not_null) { | 2820 if (!not_null) { |
2802 Node* null_ctl = top(); | 2821 Node* null_ctl = top(); |
2811 Node* slow_ctl = type_check_receiver(exact_obj, exact_kls, 1.0, | 2830 Node* slow_ctl = type_check_receiver(exact_obj, exact_kls, 1.0, |
2812 &exact_obj); | 2831 &exact_obj); |
2813 { | 2832 { |
2814 PreserveJVMState pjvms(this); | 2833 PreserveJVMState pjvms(this); |
2815 set_control(slow_ctl); | 2834 set_control(slow_ctl); |
2816 uncommon_trap(Deoptimization::Reason_class_check, | 2835 uncommon_trap(class_reason, |
2817 Deoptimization::Action_maybe_recompile); | 2836 Deoptimization::Action_maybe_recompile); |
2818 } | 2837 } |
2819 replace_in_map(not_null_obj, exact_obj); | 2838 replace_in_map(not_null_obj, exact_obj); |
2820 obj = exact_obj; | 2839 obj = exact_obj; |
2821 } | 2840 } |
2880 known_statically = (static_res == SSC_always_true || static_res == SSC_always_false); | 2899 known_statically = (static_res == SSC_always_true || static_res == SSC_always_false); |
2881 } | 2900 } |
2882 } | 2901 } |
2883 | 2902 |
2884 if (known_statically && UseTypeSpeculation) { | 2903 if (known_statically && UseTypeSpeculation) { |
2885 // If we know the type check always succeed then we don't use the | 2904 // If we know the type check always succeeds then we don't use the |
2886 // profiling data at this bytecode. Don't lose it, feed it to the | 2905 // profiling data at this bytecode. Don't lose it, feed it to the |
2887 // type system as a speculative type. | 2906 // type system as a speculative type. |
2888 not_null_obj = record_profiled_receiver_for_speculation(not_null_obj); | 2907 not_null_obj = record_profiled_receiver_for_speculation(not_null_obj); |
2889 } else { | 2908 } else { |
2890 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); | 2909 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); |
2997 region->del_req(_null_path); | 3016 region->del_req(_null_path); |
2998 phi ->del_req(_null_path); | 3017 phi ->del_req(_null_path); |
2999 } | 3018 } |
3000 | 3019 |
3001 Node* cast_obj = NULL; | 3020 Node* cast_obj = NULL; |
3002 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); | 3021 if (tk->klass_is_exact()) { |
3003 // We may not have profiling here or it may not help us. If we have | 3022 // The following optimization tries to statically cast the speculative type of the object |
3004 // a speculative type use it to perform an exact cast. | 3023 // (for example obtained during profiling) to the type of the superklass and then do a |
3005 ciKlass* spec_obj_type = obj_type->speculative_type(); | 3024 // dynamic check that the type of the object is what we expect. To work correctly |
3006 if (spec_obj_type != NULL || | 3025 // for checkcast and aastore the type of superklass should be exact. |
3007 (data != NULL && | 3026 const TypeOopPtr* obj_type = _gvn.type(obj)->is_oopptr(); |
3008 // Counter has never been decremented (due to cast failure). | 3027 // We may not have profiling here or it may not help us. If we have |
3009 // ...This is a reasonable thing to expect. It is true of | 3028 // a speculative type use it to perform an exact cast. |
3010 // all casts inserted by javac to implement generic types. | 3029 ciKlass* spec_obj_type = obj_type->speculative_type(); |
3011 data->as_CounterData()->count() >= 0)) { | 3030 if (spec_obj_type != NULL || |
3012 cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace); | 3031 (data != NULL && |
3013 if (cast_obj != NULL) { | 3032 // Counter has never been decremented (due to cast failure). |
3014 if (failure_control != NULL) // failure is now impossible | 3033 // ...This is a reasonable thing to expect. It is true of |
3015 (*failure_control) = top(); | 3034 // all casts inserted by javac to implement generic types. |
3016 // adjust the type of the phi to the exact klass: | 3035 data->as_CounterData()->count() >= 0)) { |
3017 phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR)); | 3036 cast_obj = maybe_cast_profiled_receiver(not_null_obj, tk->klass(), spec_obj_type, safe_for_replace); |
3037 if (cast_obj != NULL) { | |
3038 if (failure_control != NULL) // failure is now impossible | |
3039 (*failure_control) = top(); | |
3040 // adjust the type of the phi to the exact klass: | |
3041 phi->raise_bottom_type(_gvn.type(cast_obj)->meet_speculative(TypePtr::NULL_PTR)); | |
3042 } | |
3018 } | 3043 } |
3019 } | 3044 } |
3020 | 3045 |
3021 if (cast_obj == NULL) { | 3046 if (cast_obj == NULL) { |
3022 // Load the object's klass | 3047 // Load the object's klass |
3135 // Box the stack location | 3160 // Box the stack location |
3136 Node* box = _gvn.transform(new (C) BoxLockNode(next_monitor())); | 3161 Node* box = _gvn.transform(new (C) BoxLockNode(next_monitor())); |
3137 Node* mem = reset_memory(); | 3162 Node* mem = reset_memory(); |
3138 | 3163 |
3139 FastLockNode * flock = _gvn.transform(new (C) FastLockNode(0, obj, box) )->as_FastLock(); | 3164 FastLockNode * flock = _gvn.transform(new (C) FastLockNode(0, obj, box) )->as_FastLock(); |
3140 if (PrintPreciseBiasedLockingStatistics) { | 3165 if (UseBiasedLocking && PrintPreciseBiasedLockingStatistics) { |
3141 // Create the counters for this fast lock. | 3166 // Create the counters for this fast lock. |
3142 flock->create_lock_counter(sync_jvms()); // sync_jvms used to get current bci | 3167 flock->create_lock_counter(sync_jvms()); // sync_jvms used to get current bci |
3143 } | 3168 } |
3169 | |
3170 // Create the rtm counters for this fast lock if needed. | |
3171 flock->create_rtm_lock_counter(sync_jvms()); // sync_jvms used to get current bci | |
3172 | |
3144 // Add monitor to debug info for the slow path. If we block inside the | 3173 // Add monitor to debug info for the slow path. If we block inside the |
3145 // slow path and de-opt, we need the monitor hanging around | 3174 // slow path and de-opt, we need the monitor hanging around |
3146 map()->push_monitor( flock ); | 3175 map()->push_monitor( flock ); |
3147 | 3176 |
3148 const TypeFunc *tf = LockNode::lock_type(); | 3177 const TypeFunc *tf = LockNode::lock_type(); |