Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/library_call.cpp @ 900:9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
Summary: developed a reexecute logic for the interpreter to reexecute the bytecode when deopt happens
Reviewed-by: kvn, never, jrose, twisti
author | cfang |
---|---|
date | Fri, 31 Jul 2009 17:12:33 -0700 |
parents | 1cef5ec3ca56 |
children | fc2281ddce3c |
comparison
equal
deleted
inserted
replaced
899:55cb84cd1247 | 900:9987d9d5eb0e |
---|---|
3220 uncommon_trap(Deoptimization::Reason_intrinsic, | 3220 uncommon_trap(Deoptimization::Reason_intrinsic, |
3221 Deoptimization::Action_maybe_recompile); | 3221 Deoptimization::Action_maybe_recompile); |
3222 } | 3222 } |
3223 | 3223 |
3224 if (!stopped()) { | 3224 if (!stopped()) { |
3225 // How many elements will we copy from the original? | 3225 Node *newcopy; |
3226 // The answer is MinI(orig_length - start, length). | 3226 //set the original stack and the reexecute bit for the interpreter to reexecute |
3227 Node* orig_tail = _gvn.transform( new(C, 3) SubINode(orig_length, start) ); | 3227 //the bytecode that invokes Arrays.copyOf if deoptimization happens |
3228 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); | 3228 { PreserveReexecuteState preexecs(this); |
3229 | 3229 _sp += nargs; |
3230 const bool raw_mem_only = true; | 3230 jvms()->set_should_reexecute(true); |
3231 Node* newcopy = new_array(klass_node, length, nargs, raw_mem_only); | 3231 |
3232 | 3232 // How many elements will we copy from the original? |
3233 // Generate a direct call to the right arraycopy function(s). | 3233 // The answer is MinI(orig_length - start, length). |
3234 // We know the copy is disjoint but we might not know if the | 3234 Node* orig_tail = _gvn.transform( new(C, 3) SubINode(orig_length, start) ); |
3235 // oop stores need checking. | 3235 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); |
3236 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). | 3236 |
3237 // This will fail a store-check if x contains any non-nulls. | 3237 const bool raw_mem_only = true; |
3238 bool disjoint_bases = true; | 3238 newcopy = new_array(klass_node, length, 0, raw_mem_only); |
3239 bool length_never_negative = true; | 3239 |
3240 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, | 3240 // Generate a direct call to the right arraycopy function(s). |
3241 original, start, newcopy, intcon(0), moved, | 3241 // We know the copy is disjoint but we might not know if the |
3242 disjoint_bases, length_never_negative); | 3242 // oop stores need checking. |
3243 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). | |
3244 // This will fail a store-check if x contains any non-nulls. | |
3245 bool disjoint_bases = true; | |
3246 bool length_never_negative = true; | |
3247 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, | |
3248 original, start, newcopy, intcon(0), moved, | |
3249 disjoint_bases, length_never_negative); | |
3250 } //original reexecute and sp are set back here | |
3243 | 3251 |
3244 push(newcopy); | 3252 push(newcopy); |
3245 } | 3253 } |
3246 | 3254 |
3247 C->set_has_split_ifs(true); // Has chance for split-if optimization | 3255 C->set_has_split_ifs(true); // Has chance for split-if optimization |
4022 | 4030 |
4023 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; | 4031 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; |
4024 int raw_adr_idx = Compile::AliasIdxRaw; | 4032 int raw_adr_idx = Compile::AliasIdxRaw; |
4025 const bool raw_mem_only = true; | 4033 const bool raw_mem_only = true; |
4026 | 4034 |
4027 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); | 4035 //set the original stack and the reexecute bit for the interpreter to reexecute |
4028 if (array_ctl != NULL) { | 4036 //the bytecode that invokes Object.clone if deoptimization happens |
4029 // It's an array. | 4037 { PreserveReexecuteState preexecs(this); |
4030 PreserveJVMState pjvms(this); | 4038 _sp += nargs; |
4031 set_control(array_ctl); | 4039 jvms()->set_should_reexecute(true); |
4032 Node* obj_length = load_array_length(obj); | 4040 |
4033 Node* obj_size = NULL; | 4041 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); |
4034 Node* alloc_obj = new_array(obj_klass, obj_length, nargs, | 4042 if (array_ctl != NULL) { |
4035 raw_mem_only, &obj_size); | 4043 // It's an array. |
4036 | 4044 PreserveJVMState pjvms(this); |
4037 if (!use_ReduceInitialCardMarks()) { | 4045 set_control(array_ctl); |
4038 // If it is an oop array, it requires very special treatment, | 4046 Node* obj_length = load_array_length(obj); |
4039 // because card marking is required on each card of the array. | 4047 Node* obj_size = NULL; |
4040 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); | 4048 Node* alloc_obj = new_array(obj_klass, obj_length, 0, |
4041 if (is_obja != NULL) { | 4049 raw_mem_only, &obj_size); |
4042 PreserveJVMState pjvms2(this); | 4050 |
4043 set_control(is_obja); | 4051 if (!use_ReduceInitialCardMarks()) { |
4044 // Generate a direct call to the right arraycopy function(s). | 4052 // If it is an oop array, it requires very special treatment, |
4045 bool disjoint_bases = true; | 4053 // because card marking is required on each card of the array. |
4046 bool length_never_negative = true; | 4054 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); |
4047 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, | 4055 if (is_obja != NULL) { |
4048 obj, intcon(0), alloc_obj, intcon(0), | 4056 PreserveJVMState pjvms2(this); |
4049 obj_length, | 4057 set_control(is_obja); |
4050 disjoint_bases, length_never_negative); | 4058 // Generate a direct call to the right arraycopy function(s). |
4051 result_reg->init_req(_objArray_path, control()); | 4059 bool disjoint_bases = true; |
4052 result_val->init_req(_objArray_path, alloc_obj); | 4060 bool length_never_negative = true; |
4053 result_i_o ->set_req(_objArray_path, i_o()); | 4061 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, |
4054 result_mem ->set_req(_objArray_path, reset_memory()); | 4062 obj, intcon(0), alloc_obj, intcon(0), |
4063 obj_length, | |
4064 disjoint_bases, length_never_negative); | |
4065 result_reg->init_req(_objArray_path, control()); | |
4066 result_val->init_req(_objArray_path, alloc_obj); | |
4067 result_i_o ->set_req(_objArray_path, i_o()); | |
4068 result_mem ->set_req(_objArray_path, reset_memory()); | |
4069 } | |
4055 } | 4070 } |
4056 } | 4071 // We can dispense with card marks if we know the allocation |
4057 // We can dispense with card marks if we know the allocation | 4072 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks |
4058 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks | 4073 // causes the non-eden paths to simulate a fresh allocation, |
4059 // causes the non-eden paths to simulate a fresh allocation, | 4074 // insofar that no further card marks are required to initialize |
4060 // insofar that no further card marks are required to initialize | 4075 // the object. |
4061 // the object. | 4076 |
4062 | 4077 // Otherwise, there are no card marks to worry about. |
4063 // Otherwise, there are no card marks to worry about. | 4078 |
4064 | 4079 if (!stopped()) { |
4080 copy_to_clone(obj, alloc_obj, obj_size, true, false); | |
4081 | |
4082 // Present the results of the copy. | |
4083 result_reg->init_req(_array_path, control()); | |
4084 result_val->init_req(_array_path, alloc_obj); | |
4085 result_i_o ->set_req(_array_path, i_o()); | |
4086 result_mem ->set_req(_array_path, reset_memory()); | |
4087 } | |
4088 } | |
4089 | |
4090 // We only go to the instance fast case code if we pass a number of guards. | |
4091 // The paths which do not pass are accumulated in the slow_region. | |
4092 RegionNode* slow_region = new (C, 1) RegionNode(1); | |
4093 record_for_igvn(slow_region); | |
4065 if (!stopped()) { | 4094 if (!stopped()) { |
4066 copy_to_clone(obj, alloc_obj, obj_size, true, false); | 4095 // It's an instance (we did array above). Make the slow-path tests. |
4067 | 4096 // If this is a virtual call, we generate a funny guard. We grab |
4068 // Present the results of the copy. | 4097 // the vtable entry corresponding to clone() from the target object. |
4069 result_reg->init_req(_array_path, control()); | 4098 // If the target method which we are calling happens to be the |
4070 result_val->init_req(_array_path, alloc_obj); | 4099 // Object clone() method, we pass the guard. We do not need this |
4071 result_i_o ->set_req(_array_path, i_o()); | 4100 // guard for non-virtual calls; the caller is known to be the native |
4072 result_mem ->set_req(_array_path, reset_memory()); | 4101 // Object clone(). |
4073 } | 4102 if (is_virtual) { |
4074 } | 4103 generate_virtual_guard(obj_klass, slow_region); |
4075 | 4104 } |
4076 // We only go to the instance fast case code if we pass a number of guards. | 4105 |
4077 // The paths which do not pass are accumulated in the slow_region. | 4106 // The object must be cloneable and must not have a finalizer. |
4078 RegionNode* slow_region = new (C, 1) RegionNode(1); | 4107 // Both of these conditions may be checked in a single test. |
4079 record_for_igvn(slow_region); | 4108 // We could optimize the cloneable test further, but we don't care. |
4080 if (!stopped()) { | 4109 generate_access_flags_guard(obj_klass, |
4081 // It's an instance (we did array above). Make the slow-path tests. | 4110 // Test both conditions: |
4082 // If this is a virtual call, we generate a funny guard. We grab | 4111 JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER, |
4083 // the vtable entry corresponding to clone() from the target object. | 4112 // Must be cloneable but not finalizer: |
4084 // If the target method which we are calling happens to be the | 4113 JVM_ACC_IS_CLONEABLE, |
4085 // Object clone() method, we pass the guard. We do not need this | 4114 slow_region); |
4086 // guard for non-virtual calls; the caller is known to be the native | 4115 } |
4087 // Object clone(). | 4116 |
4088 if (is_virtual) { | 4117 if (!stopped()) { |
4089 generate_virtual_guard(obj_klass, slow_region); | 4118 // It's an instance, and it passed the slow-path tests. |
4090 } | 4119 PreserveJVMState pjvms(this); |
4091 | 4120 Node* obj_size = NULL; |
4092 // The object must be cloneable and must not have a finalizer. | 4121 Node* alloc_obj = new_instance(obj_klass, NULL, raw_mem_only, &obj_size); |
4093 // Both of these conditions may be checked in a single test. | 4122 |
4094 // We could optimize the cloneable test further, but we don't care. | 4123 copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks()); |
4095 generate_access_flags_guard(obj_klass, | 4124 |
4096 // Test both conditions: | 4125 // Present the results of the slow call. |
4097 JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER, | 4126 result_reg->init_req(_instance_path, control()); |
4098 // Must be cloneable but not finalizer: | 4127 result_val->init_req(_instance_path, alloc_obj); |
4099 JVM_ACC_IS_CLONEABLE, | 4128 result_i_o ->set_req(_instance_path, i_o()); |
4100 slow_region); | 4129 result_mem ->set_req(_instance_path, reset_memory()); |
4101 } | 4130 } |
4102 | 4131 |
4103 if (!stopped()) { | 4132 // Generate code for the slow case. We make a call to clone(). |
4104 // It's an instance, and it passed the slow-path tests. | 4133 set_control(_gvn.transform(slow_region)); |
4105 PreserveJVMState pjvms(this); | 4134 if (!stopped()) { |
4106 Node* obj_size = NULL; | 4135 PreserveJVMState pjvms(this); |
4107 Node* alloc_obj = new_instance(obj_klass, NULL, raw_mem_only, &obj_size); | 4136 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); |
4108 | 4137 Node* slow_result = set_results_for_java_call(slow_call); |
4109 copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks()); | 4138 // this->control() comes from set_results_for_java_call |
4110 | 4139 result_reg->init_req(_slow_path, control()); |
4111 // Present the results of the slow call. | 4140 result_val->init_req(_slow_path, slow_result); |
4112 result_reg->init_req(_instance_path, control()); | 4141 result_i_o ->set_req(_slow_path, i_o()); |
4113 result_val->init_req(_instance_path, alloc_obj); | 4142 result_mem ->set_req(_slow_path, reset_memory()); |
4114 result_i_o ->set_req(_instance_path, i_o()); | 4143 } |
4115 result_mem ->set_req(_instance_path, reset_memory()); | 4144 } //original reexecute and sp are set back here |
4116 } | |
4117 | |
4118 // Generate code for the slow case. We make a call to clone(). | |
4119 set_control(_gvn.transform(slow_region)); | |
4120 if (!stopped()) { | |
4121 PreserveJVMState pjvms(this); | |
4122 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); | |
4123 Node* slow_result = set_results_for_java_call(slow_call); | |
4124 // this->control() comes from set_results_for_java_call | |
4125 result_reg->init_req(_slow_path, control()); | |
4126 result_val->init_req(_slow_path, slow_result); | |
4127 result_i_o ->set_req(_slow_path, i_o()); | |
4128 result_mem ->set_req(_slow_path, reset_memory()); | |
4129 } | |
4130 | 4145 |
4131 // Return the combined state. | 4146 // Return the combined state. |
4132 set_control( _gvn.transform(result_reg) ); | 4147 set_control( _gvn.transform(result_reg) ); |
4133 set_i_o( _gvn.transform(result_i_o) ); | 4148 set_i_o( _gvn.transform(result_i_o) ); |
4134 set_all_memory( _gvn.transform(result_mem) ); | 4149 set_all_memory( _gvn.transform(result_mem) ); |