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 "precompiled.hpp"
26 #include "c1/c1_Compilation.hpp"
27 #include "c1/c1_Defs.hpp"
28 #include "c1/c1_FrameMap.hpp"
29 #include "c1/c1_Instruction.hpp"
30 #include "c1/c1_LIRAssembler.hpp"
31 #include "c1/c1_LIRGenerator.hpp"
32 #include "c1/c1_ValueStack.hpp"
33 #include "ci/ciArrayKlass.hpp"
34 #include "ci/ciInstance.hpp"
35 #include "ci/ciObjArray.hpp"
36 #include "ci/ciUtilities.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/sharedRuntime.hpp"
44 #include "runtime/stubRoutines.hpp"
45 #include "runtime/vm_version.hpp"
46 #include "utilities/bitMap.inline.hpp"
47 #include "utilities/macros.hpp"
48 #include "utilities/powerOfTwo.hpp"
49
50 #ifdef ASSERT
51 #define __ gen()->lir(__FILE__, __LINE__)->
52 #else
53 #define __ gen()->lir()->
54 #endif
55
56 #ifndef PATCHED_ADDR
57 #define PATCHED_ADDR (max_jint)
58 #endif
59
60 void PhiResolverState::reset() {
61 _virtual_operands.clear();
62 _other_operands.clear();
2658 #endif // __SOFTFP__
2659 local->set_operand(dest);
2660 #ifdef ASSERT
2661 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2662 #endif
2663 java_index += type2size[t];
2664 }
2665
2666 if (compilation()->env()->dtrace_method_probes()) {
2667 BasicTypeList signature;
2668 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2669 signature.append(T_METADATA); // Method*
2670 LIR_OprList* args = new LIR_OprList();
2671 args->append(getThreadPointer());
2672 LIR_Opr meth = new_register(T_METADATA);
2673 __ metadata2reg(method()->constant_encoding(), meth);
2674 args->append(meth);
2675 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2676 }
2677
2678 if (method()->is_synchronized()) {
2679 LIR_Opr obj;
2680 if (method()->is_static()) {
2681 obj = new_register(T_OBJECT);
2682 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2683 } else {
2684 Local* receiver = x->state()->local_at(0)->as_Local();
2685 assert(receiver != nullptr, "must already exist");
2686 obj = receiver->operand();
2687 }
2688 assert(obj->is_valid(), "must be valid");
2689
2690 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2691 LIR_Opr lock = syncLockOpr();
2692 __ load_stack_address_monitor(0, lock);
2693
2694 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2695 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2696
2697 // receiver is guaranteed non-null so don't need CodeEmitInfo
3263 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3264 }
3265 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3266 }
3267
3268 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3269 ciMethod *method, LIR_Opr step, int frequency,
3270 int bci, bool backedge, bool notify) {
3271 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3272 int level = _compilation->env()->comp_level();
3273 assert(level > CompLevel_simple, "Shouldn't be here");
3274
3275 int offset = -1;
3276 LIR_Opr counter_holder;
3277 if (level == CompLevel_limited_profile) {
3278 MethodCounters* counters_adr = method->ensure_method_counters();
3279 if (counters_adr == nullptr) {
3280 bailout("method counters allocation failed");
3281 return;
3282 }
3283 counter_holder = new_pointer_register();
3284 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3285 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3286 MethodCounters::invocation_counter_offset());
3287 } else if (level == CompLevel_full_profile) {
3288 counter_holder = new_register(T_METADATA);
3289 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3290 MethodData::invocation_counter_offset());
3291 ciMethodData* md = method->method_data_or_null();
3292 assert(md != nullptr, "Sanity");
3293 __ metadata2reg(md->constant_encoding(), counter_holder);
3294 } else {
3295 ShouldNotReachHere();
3296 }
3297 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3298 LIR_Opr result = new_register(T_INT);
3299 __ load(counter, result);
3300 __ add(result, step, result);
3301 __ store(result, counter);
3302 if (notify && (!backedge || UseOnStackReplacement)) {
3303 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3304 // The bci for info can point to cmp for if's we want the if bci
|
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 "precompiled.hpp"
26 #include "c1/c1_Compilation.hpp"
27 #include "c1/c1_Defs.hpp"
28 #include "c1/c1_FrameMap.hpp"
29 #include "c1/c1_Instruction.hpp"
30 #include "c1/c1_LIRAssembler.hpp"
31 #include "c1/c1_LIRGenerator.hpp"
32 #include "c1/c1_ValueStack.hpp"
33 #include "ci/ciArrayKlass.hpp"
34 #include "ci/ciInstance.hpp"
35 #include "ci/ciObjArray.hpp"
36 #include "ci/ciUtilities.hpp"
37 #include "code/SCCache.hpp"
38 #include "compiler/compilerDefinitions.inline.hpp"
39 #include "compiler/compilerOracle.hpp"
40 #include "gc/shared/barrierSet.hpp"
41 #include "gc/shared/c1/barrierSetC1.hpp"
42 #include "oops/klass.inline.hpp"
43 #include "oops/methodCounters.hpp"
44 #include "runtime/runtimeUpcalls.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "runtime/vm_version.hpp"
48 #include "utilities/bitMap.inline.hpp"
49 #include "utilities/macros.hpp"
50 #include "utilities/powerOfTwo.hpp"
51
52 #ifdef ASSERT
53 #define __ gen()->lir(__FILE__, __LINE__)->
54 #else
55 #define __ gen()->lir()->
56 #endif
57
58 #ifndef PATCHED_ADDR
59 #define PATCHED_ADDR (max_jint)
60 #endif
61
62 void PhiResolverState::reset() {
63 _virtual_operands.clear();
64 _other_operands.clear();
2660 #endif // __SOFTFP__
2661 local->set_operand(dest);
2662 #ifdef ASSERT
2663 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2664 #endif
2665 java_index += type2size[t];
2666 }
2667
2668 if (compilation()->env()->dtrace_method_probes()) {
2669 BasicTypeList signature;
2670 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2671 signature.append(T_METADATA); // Method*
2672 LIR_OprList* args = new LIR_OprList();
2673 args->append(getThreadPointer());
2674 LIR_Opr meth = new_register(T_METADATA);
2675 __ metadata2reg(method()->constant_encoding(), meth);
2676 args->append(meth);
2677 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2678 }
2679
2680 MethodDetails method_details(method());
2681 RuntimeUpcallInfo* upcall = RuntimeUpcalls::get_first_upcall(RuntimeUpcallType::onMethodEntry, method_details);
2682 while (upcall != nullptr) {
2683 BasicTypeList signature;
2684 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2685 LIR_OprList* args = new LIR_OprList();
2686 args->append(getThreadPointer());
2687 call_runtime(&signature, args, upcall->upcall_address(), voidType, nullptr);
2688 upcall = RuntimeUpcalls::get_next_upcall(RuntimeUpcallType::onMethodEntry, method_details, upcall);
2689 }
2690
2691 if (method()->is_synchronized()) {
2692 LIR_Opr obj;
2693 if (method()->is_static()) {
2694 obj = new_register(T_OBJECT);
2695 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2696 } else {
2697 Local* receiver = x->state()->local_at(0)->as_Local();
2698 assert(receiver != nullptr, "must already exist");
2699 obj = receiver->operand();
2700 }
2701 assert(obj->is_valid(), "must be valid");
2702
2703 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2704 LIR_Opr lock = syncLockOpr();
2705 __ load_stack_address_monitor(0, lock);
2706
2707 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2708 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2709
2710 // receiver is guaranteed non-null so don't need CodeEmitInfo
3276 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3277 }
3278 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3279 }
3280
3281 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3282 ciMethod *method, LIR_Opr step, int frequency,
3283 int bci, bool backedge, bool notify) {
3284 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3285 int level = _compilation->env()->comp_level();
3286 assert(level > CompLevel_simple, "Shouldn't be here");
3287
3288 int offset = -1;
3289 LIR_Opr counter_holder;
3290 if (level == CompLevel_limited_profile) {
3291 MethodCounters* counters_adr = method->ensure_method_counters();
3292 if (counters_adr == nullptr) {
3293 bailout("method counters allocation failed");
3294 return;
3295 }
3296 if (SCCache::is_on()) {
3297 counter_holder = new_register(T_METADATA);
3298 __ metadata2reg(counters_adr, counter_holder);
3299 } else {
3300 counter_holder = new_pointer_register();
3301 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3302 }
3303 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3304 MethodCounters::invocation_counter_offset());
3305 } else if (level == CompLevel_full_profile) {
3306 counter_holder = new_register(T_METADATA);
3307 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3308 MethodData::invocation_counter_offset());
3309 ciMethodData* md = method->method_data_or_null();
3310 assert(md != nullptr, "Sanity");
3311 __ metadata2reg(md->constant_encoding(), counter_holder);
3312 } else {
3313 ShouldNotReachHere();
3314 }
3315 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3316 LIR_Opr result = new_register(T_INT);
3317 __ load(counter, result);
3318 __ add(result, step, result);
3319 __ store(result, counter);
3320 if (notify && (!backedge || UseOnStackReplacement)) {
3321 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3322 // The bci for info can point to cmp for if's we want the if bci
|