16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_Compilation.hpp"
26 #include "c1/c1_Defs.hpp"
27 #include "c1/c1_FrameMap.hpp"
28 #include "c1/c1_Instruction.hpp"
29 #include "c1/c1_LIRAssembler.hpp"
30 #include "c1/c1_LIRGenerator.hpp"
31 #include "c1/c1_ValueStack.hpp"
32 #include "ci/ciArrayKlass.hpp"
33 #include "ci/ciInstance.hpp"
34 #include "ci/ciObjArray.hpp"
35 #include "ci/ciUtilities.hpp"
36 #include "compiler/compilerDefinitions.inline.hpp"
37 #include "compiler/compilerOracle.hpp"
38 #include "gc/shared/barrierSet.hpp"
39 #include "gc/shared/c1/barrierSetC1.hpp"
40 #include "oops/klass.inline.hpp"
41 #include "oops/methodCounters.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "runtime/stubRoutines.hpp"
44 #include "runtime/vm_version.hpp"
45 #include "utilities/bitMap.inline.hpp"
46 #include "utilities/macros.hpp"
47 #include "utilities/powerOfTwo.hpp"
48
49 #ifdef ASSERT
50 #define __ gen()->lir(__FILE__, __LINE__)->
51 #else
52 #define __ gen()->lir()->
53 #endif
54
55 #ifndef PATCHED_ADDR
56 #define PATCHED_ADDR (max_jint)
57 #endif
58
59 void PhiResolverState::reset() {
60 _virtual_operands.clear();
61 _other_operands.clear();
2596 #endif // __SOFTFP__
2597 local->set_operand(dest);
2598 #ifdef ASSERT
2599 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2600 #endif
2601 java_index += type2size[t];
2602 }
2603
2604 if (compilation()->env()->dtrace_method_probes()) {
2605 BasicTypeList signature;
2606 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2607 signature.append(T_METADATA); // Method*
2608 LIR_OprList* args = new LIR_OprList();
2609 args->append(getThreadPointer());
2610 LIR_Opr meth = new_register(T_METADATA);
2611 __ metadata2reg(method()->constant_encoding(), meth);
2612 args->append(meth);
2613 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2614 }
2615
2616 if (method()->is_synchronized()) {
2617 LIR_Opr obj;
2618 if (method()->is_static()) {
2619 obj = new_register(T_OBJECT);
2620 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2621 } else {
2622 Local* receiver = x->state()->local_at(0)->as_Local();
2623 assert(receiver != nullptr, "must already exist");
2624 obj = receiver->operand();
2625 }
2626 assert(obj->is_valid(), "must be valid");
2627
2628 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2629 LIR_Opr lock = syncLockOpr();
2630 __ load_stack_address_monitor(0, lock);
2631
2632 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2633 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2634
2635 // receiver is guaranteed non-null so don't need CodeEmitInfo
3187 int freq_log = 0;
3188 int level = compilation()->env()->comp_level();
3189 if (level == CompLevel_limited_profile) {
3190 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
3191 } else if (level == CompLevel_full_profile) {
3192 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
3193 } else {
3194 ShouldNotReachHere();
3195 }
3196 // Increment the appropriate invocation/backedge counter and notify the runtime.
3197 double scale;
3198 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) {
3199 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3200 }
3201 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3202 }
3203
3204 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3205 ciMethod *method, LIR_Opr step, int frequency,
3206 int bci, bool backedge, bool notify) {
3207 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3208 int level = _compilation->env()->comp_level();
3209 assert(level > CompLevel_simple, "Shouldn't be here");
3210
3211 int offset = -1;
3212 LIR_Opr counter_holder;
3213 if (level == CompLevel_limited_profile) {
3214 MethodCounters* counters_adr = method->ensure_method_counters();
3215 if (counters_adr == nullptr) {
3216 bailout("method counters allocation failed");
3217 return;
3218 }
3219 counter_holder = new_pointer_register();
3220 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3221 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3222 MethodCounters::invocation_counter_offset());
3223 } else if (level == CompLevel_full_profile) {
3224 counter_holder = new_register(T_METADATA);
3225 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3226 MethodData::invocation_counter_offset());
3227 ciMethodData* md = method->method_data_or_null();
3228 assert(md != nullptr, "Sanity");
3229 __ metadata2reg(md->constant_encoding(), counter_holder);
3230 } else {
3231 ShouldNotReachHere();
3232 }
3233 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3234 LIR_Opr result = new_register(T_INT);
3235 __ load(counter, result);
3236 __ add(result, step, result);
3237 __ store(result, counter);
3238 if (notify && (!backedge || UseOnStackReplacement)) {
3239 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3240 // The bci for info can point to cmp for if's we want the if bci
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_Compilation.hpp"
26 #include "c1/c1_Defs.hpp"
27 #include "c1/c1_FrameMap.hpp"
28 #include "c1/c1_Instruction.hpp"
29 #include "c1/c1_LIRAssembler.hpp"
30 #include "c1/c1_LIRGenerator.hpp"
31 #include "c1/c1_ValueStack.hpp"
32 #include "ci/ciArrayKlass.hpp"
33 #include "ci/ciInstance.hpp"
34 #include "ci/ciObjArray.hpp"
35 #include "ci/ciUtilities.hpp"
36 #include "code/SCCache.hpp"
37 #include "compiler/compilerDefinitions.inline.hpp"
38 #include "compiler/compilerOracle.hpp"
39 #include "gc/shared/barrierSet.hpp"
40 #include "gc/shared/c1/barrierSetC1.hpp"
41 #include "oops/klass.inline.hpp"
42 #include "oops/methodCounters.hpp"
43 #include "runtime/runtimeUpcalls.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/stubRoutines.hpp"
46 #include "runtime/vm_version.hpp"
47 #include "utilities/bitMap.inline.hpp"
48 #include "utilities/macros.hpp"
49 #include "utilities/powerOfTwo.hpp"
50
51 #ifdef ASSERT
52 #define __ gen()->lir(__FILE__, __LINE__)->
53 #else
54 #define __ gen()->lir()->
55 #endif
56
57 #ifndef PATCHED_ADDR
58 #define PATCHED_ADDR (max_jint)
59 #endif
60
61 void PhiResolverState::reset() {
62 _virtual_operands.clear();
63 _other_operands.clear();
2598 #endif // __SOFTFP__
2599 local->set_operand(dest);
2600 #ifdef ASSERT
2601 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2602 #endif
2603 java_index += type2size[t];
2604 }
2605
2606 if (compilation()->env()->dtrace_method_probes()) {
2607 BasicTypeList signature;
2608 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2609 signature.append(T_METADATA); // Method*
2610 LIR_OprList* args = new LIR_OprList();
2611 args->append(getThreadPointer());
2612 LIR_Opr meth = new_register(T_METADATA);
2613 __ metadata2reg(method()->constant_encoding(), meth);
2614 args->append(meth);
2615 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2616 }
2617
2618 MethodDetails method_details(method());
2619 RuntimeUpcallInfo* upcall = RuntimeUpcalls::get_first_upcall(RuntimeUpcallType::onMethodEntry, method_details);
2620 while (upcall != nullptr) {
2621 BasicTypeList signature;
2622 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2623 LIR_OprList* args = new LIR_OprList();
2624 args->append(getThreadPointer());
2625 call_runtime(&signature, args, upcall->upcall_address(), voidType, nullptr);
2626 upcall = RuntimeUpcalls::get_next_upcall(RuntimeUpcallType::onMethodEntry, method_details, upcall);
2627 }
2628
2629 if (method()->is_synchronized()) {
2630 LIR_Opr obj;
2631 if (method()->is_static()) {
2632 obj = new_register(T_OBJECT);
2633 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2634 } else {
2635 Local* receiver = x->state()->local_at(0)->as_Local();
2636 assert(receiver != nullptr, "must already exist");
2637 obj = receiver->operand();
2638 }
2639 assert(obj->is_valid(), "must be valid");
2640
2641 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2642 LIR_Opr lock = syncLockOpr();
2643 __ load_stack_address_monitor(0, lock);
2644
2645 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2646 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2647
2648 // receiver is guaranteed non-null so don't need CodeEmitInfo
3200 int freq_log = 0;
3201 int level = compilation()->env()->comp_level();
3202 if (level == CompLevel_limited_profile) {
3203 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
3204 } else if (level == CompLevel_full_profile) {
3205 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
3206 } else {
3207 ShouldNotReachHere();
3208 }
3209 // Increment the appropriate invocation/backedge counter and notify the runtime.
3210 double scale;
3211 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) {
3212 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3213 }
3214 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3215 }
3216
3217 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3218 ciMethod *method, LIR_Opr step, int frequency,
3219 int bci, bool backedge, bool notify) {
3220 if (PreloadOnly) {
3221 // Nothing to do if we only use preload code.
3222 return;
3223 }
3224 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3225 int level = _compilation->env()->comp_level();
3226 assert(level > CompLevel_simple, "Shouldn't be here");
3227
3228 int offset = -1;
3229 LIR_Opr counter_holder;
3230 if (level == CompLevel_limited_profile) {
3231 MethodCounters* counters_adr = method->ensure_method_counters();
3232 if (counters_adr == nullptr) {
3233 bailout("method counters allocation failed");
3234 return;
3235 }
3236 if (SCCache::is_on()) {
3237 counter_holder = new_register(T_METADATA);
3238 __ metadata2reg(counters_adr, counter_holder);
3239 } else {
3240 counter_holder = new_pointer_register();
3241 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3242 }
3243 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3244 MethodCounters::invocation_counter_offset());
3245 } else if (level == CompLevel_full_profile) {
3246 counter_holder = new_register(T_METADATA);
3247 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3248 MethodData::invocation_counter_offset());
3249 ciMethodData* md = method->method_data_or_null();
3250 assert(md != nullptr, "Sanity");
3251 __ metadata2reg(md->constant_encoding(), counter_holder);
3252 } else {
3253 ShouldNotReachHere();
3254 }
3255 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3256 LIR_Opr result = new_register(T_INT);
3257 __ load(counter, result);
3258 __ add(result, step, result);
3259 __ store(result, counter);
3260 if (notify && (!backedge || UseOnStackReplacement)) {
3261 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3262 // The bci for info can point to cmp for if's we want the if bci
|