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();
2556 #endif // __SOFTFP__
2557 local->set_operand(dest);
2558 #ifdef ASSERT
2559 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2560 #endif
2561 java_index += type2size[t];
2562 }
2563
2564 if (compilation()->env()->dtrace_method_probes()) {
2565 BasicTypeList signature;
2566 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2567 signature.append(T_METADATA); // Method*
2568 LIR_OprList* args = new LIR_OprList();
2569 args->append(getThreadPointer());
2570 LIR_Opr meth = new_register(T_METADATA);
2571 __ metadata2reg(method()->constant_encoding(), meth);
2572 args->append(meth);
2573 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2574 }
2575
2576 if (method()->is_synchronized()) {
2577 LIR_Opr obj;
2578 if (method()->is_static()) {
2579 obj = new_register(T_OBJECT);
2580 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2581 } else {
2582 Local* receiver = x->state()->local_at(0)->as_Local();
2583 assert(receiver != nullptr, "must already exist");
2584 obj = receiver->operand();
2585 }
2586 assert(obj->is_valid(), "must be valid");
2587
2588 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2589 LIR_Opr lock = syncLockOpr();
2590 __ load_stack_address_monitor(0, lock);
2591
2592 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2593 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2594
2595 // receiver is guaranteed non-null so don't need CodeEmitInfo
3147 int freq_log = 0;
3148 int level = compilation()->env()->comp_level();
3149 if (level == CompLevel_limited_profile) {
3150 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
3151 } else if (level == CompLevel_full_profile) {
3152 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
3153 } else {
3154 ShouldNotReachHere();
3155 }
3156 // Increment the appropriate invocation/backedge counter and notify the runtime.
3157 double scale;
3158 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) {
3159 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3160 }
3161 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3162 }
3163
3164 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3165 ciMethod *method, LIR_Opr step, int frequency,
3166 int bci, bool backedge, bool notify) {
3167 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3168 int level = _compilation->env()->comp_level();
3169 assert(level > CompLevel_simple, "Shouldn't be here");
3170
3171 int offset = -1;
3172 LIR_Opr counter_holder;
3173 if (level == CompLevel_limited_profile) {
3174 MethodCounters* counters_adr = method->ensure_method_counters();
3175 if (counters_adr == nullptr) {
3176 bailout("method counters allocation failed");
3177 return;
3178 }
3179 counter_holder = new_pointer_register();
3180 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3181 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3182 MethodCounters::invocation_counter_offset());
3183 } else if (level == CompLevel_full_profile) {
3184 counter_holder = new_register(T_METADATA);
3185 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3186 MethodData::invocation_counter_offset());
3187 ciMethodData* md = method->method_data_or_null();
3188 assert(md != nullptr, "Sanity");
3189 __ metadata2reg(md->constant_encoding(), counter_holder);
3190 } else {
3191 ShouldNotReachHere();
3192 }
3193 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3194 LIR_Opr result = new_register(T_INT);
3195 __ load(counter, result);
3196 __ add(result, step, result);
3197 __ store(result, counter);
3198 if (notify && (!backedge || UseOnStackReplacement)) {
3199 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3200 // 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();
2558 #endif // __SOFTFP__
2559 local->set_operand(dest);
2560 #ifdef ASSERT
2561 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2562 #endif
2563 java_index += type2size[t];
2564 }
2565
2566 if (compilation()->env()->dtrace_method_probes()) {
2567 BasicTypeList signature;
2568 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2569 signature.append(T_METADATA); // Method*
2570 LIR_OprList* args = new LIR_OprList();
2571 args->append(getThreadPointer());
2572 LIR_Opr meth = new_register(T_METADATA);
2573 __ metadata2reg(method()->constant_encoding(), meth);
2574 args->append(meth);
2575 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2576 }
2577
2578 MethodDetails method_details(method());
2579 RuntimeUpcallInfo* upcall = RuntimeUpcalls::get_first_upcall(RuntimeUpcallType::onMethodEntry, method_details);
2580 while (upcall != nullptr) {
2581 BasicTypeList signature;
2582 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2583 LIR_OprList* args = new LIR_OprList();
2584 args->append(getThreadPointer());
2585 call_runtime(&signature, args, upcall->upcall_address(), voidType, nullptr);
2586 upcall = RuntimeUpcalls::get_next_upcall(RuntimeUpcallType::onMethodEntry, method_details, upcall);
2587 }
2588
2589 if (method()->is_synchronized()) {
2590 LIR_Opr obj;
2591 if (method()->is_static()) {
2592 obj = new_register(T_OBJECT);
2593 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2594 } else {
2595 Local* receiver = x->state()->local_at(0)->as_Local();
2596 assert(receiver != nullptr, "must already exist");
2597 obj = receiver->operand();
2598 }
2599 assert(obj->is_valid(), "must be valid");
2600
2601 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2602 LIR_Opr lock = syncLockOpr();
2603 __ load_stack_address_monitor(0, lock);
2604
2605 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2606 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2607
2608 // receiver is guaranteed non-null so don't need CodeEmitInfo
3160 int freq_log = 0;
3161 int level = compilation()->env()->comp_level();
3162 if (level == CompLevel_limited_profile) {
3163 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog);
3164 } else if (level == CompLevel_full_profile) {
3165 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog);
3166 } else {
3167 ShouldNotReachHere();
3168 }
3169 // Increment the appropriate invocation/backedge counter and notify the runtime.
3170 double scale;
3171 if (_method->has_option_value(CompileCommandEnum::CompileThresholdScaling, scale)) {
3172 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3173 }
3174 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3175 }
3176
3177 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3178 ciMethod *method, LIR_Opr step, int frequency,
3179 int bci, bool backedge, bool notify) {
3180 if (PreloadOnly) {
3181 // Nothing to do if we only use preload code.
3182 return;
3183 }
3184 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3185 int level = _compilation->env()->comp_level();
3186 assert(level > CompLevel_simple, "Shouldn't be here");
3187
3188 int offset = -1;
3189 LIR_Opr counter_holder;
3190 if (level == CompLevel_limited_profile) {
3191 MethodCounters* counters_adr = method->ensure_method_counters();
3192 if (counters_adr == nullptr) {
3193 bailout("method counters allocation failed");
3194 return;
3195 }
3196 if (SCCache::is_on()) {
3197 counter_holder = new_register(T_METADATA);
3198 __ metadata2reg(counters_adr, counter_holder);
3199 } else {
3200 counter_holder = new_pointer_register();
3201 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3202 }
3203 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3204 MethodCounters::invocation_counter_offset());
3205 } else if (level == CompLevel_full_profile) {
3206 counter_holder = new_register(T_METADATA);
3207 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3208 MethodData::invocation_counter_offset());
3209 ciMethodData* md = method->method_data_or_null();
3210 assert(md != nullptr, "Sanity");
3211 __ metadata2reg(md->constant_encoding(), counter_holder);
3212 } else {
3213 ShouldNotReachHere();
3214 }
3215 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3216 LIR_Opr result = new_register(T_INT);
3217 __ load(counter, result);
3218 __ add(result, step, result);
3219 __ store(result, counter);
3220 if (notify && (!backedge || UseOnStackReplacement)) {
3221 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3222 // The bci for info can point to cmp for if's we want the if bci
|