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();
2651 #endif // __SOFTFP__
2652 local->set_operand(dest);
2653 #ifdef ASSERT
2654 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2655 #endif
2656 java_index += type2size[t];
2657 }
2658
2659 if (compilation()->env()->dtrace_method_probes()) {
2660 BasicTypeList signature;
2661 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2662 signature.append(T_METADATA); // Method*
2663 LIR_OprList* args = new LIR_OprList();
2664 args->append(getThreadPointer());
2665 LIR_Opr meth = new_register(T_METADATA);
2666 __ metadata2reg(method()->constant_encoding(), meth);
2667 args->append(meth);
2668 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2669 }
2670
2671 if (method()->is_synchronized()) {
2672 LIR_Opr obj;
2673 if (method()->is_static()) {
2674 obj = new_register(T_OBJECT);
2675 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2676 } else {
2677 Local* receiver = x->state()->local_at(0)->as_Local();
2678 assert(receiver != nullptr, "must already exist");
2679 obj = receiver->operand();
2680 }
2681 assert(obj->is_valid(), "must be valid");
2682
2683 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2684 LIR_Opr lock = syncLockOpr();
2685 __ load_stack_address_monitor(0, lock);
2686
2687 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2688 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2689
2690 // receiver is guaranteed non-null so don't need CodeEmitInfo
3256 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3257 }
3258 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3259 }
3260
3261 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3262 ciMethod *method, LIR_Opr step, int frequency,
3263 int bci, bool backedge, bool notify) {
3264 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3265 int level = _compilation->env()->comp_level();
3266 assert(level > CompLevel_simple, "Shouldn't be here");
3267
3268 int offset = -1;
3269 LIR_Opr counter_holder;
3270 if (level == CompLevel_limited_profile) {
3271 MethodCounters* counters_adr = method->ensure_method_counters();
3272 if (counters_adr == nullptr) {
3273 bailout("method counters allocation failed");
3274 return;
3275 }
3276 counter_holder = new_pointer_register();
3277 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3278 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3279 MethodCounters::invocation_counter_offset());
3280 } else if (level == CompLevel_full_profile) {
3281 counter_holder = new_register(T_METADATA);
3282 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3283 MethodData::invocation_counter_offset());
3284 ciMethodData* md = method->method_data_or_null();
3285 assert(md != nullptr, "Sanity");
3286 __ metadata2reg(md->constant_encoding(), counter_holder);
3287 } else {
3288 ShouldNotReachHere();
3289 }
3290 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3291 LIR_Opr result = new_register(T_INT);
3292 __ load(counter, result);
3293 __ add(result, step, result);
3294 __ store(result, counter);
3295 if (notify && (!backedge || UseOnStackReplacement)) {
3296 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3297 // 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();
2653 #endif // __SOFTFP__
2654 local->set_operand(dest);
2655 #ifdef ASSERT
2656 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, nullptr);
2657 #endif
2658 java_index += type2size[t];
2659 }
2660
2661 if (compilation()->env()->dtrace_method_probes()) {
2662 BasicTypeList signature;
2663 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2664 signature.append(T_METADATA); // Method*
2665 LIR_OprList* args = new LIR_OprList();
2666 args->append(getThreadPointer());
2667 LIR_Opr meth = new_register(T_METADATA);
2668 __ metadata2reg(method()->constant_encoding(), meth);
2669 args->append(meth);
2670 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, nullptr);
2671 }
2672
2673 MethodDetails method_details(method());
2674 RuntimeUpcallInfo* upcall = RuntimeUpcalls::get_first_upcall(RuntimeUpcallType::onMethodEntry, method_details);
2675 while (upcall != nullptr) {
2676 BasicTypeList signature;
2677 signature.append(LP64_ONLY(T_LONG) NOT_LP64(T_INT)); // thread
2678 LIR_OprList* args = new LIR_OprList();
2679 args->append(getThreadPointer());
2680 call_runtime(&signature, args, upcall->upcall_address(), voidType, nullptr);
2681 upcall = RuntimeUpcalls::get_next_upcall(RuntimeUpcallType::onMethodEntry, method_details, upcall);
2682 }
2683
2684 if (method()->is_synchronized()) {
2685 LIR_Opr obj;
2686 if (method()->is_static()) {
2687 obj = new_register(T_OBJECT);
2688 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj);
2689 } else {
2690 Local* receiver = x->state()->local_at(0)->as_Local();
2691 assert(receiver != nullptr, "must already exist");
2692 obj = receiver->operand();
2693 }
2694 assert(obj->is_valid(), "must be valid");
2695
2696 if (method()->is_synchronized() && GenerateSynchronizationCode) {
2697 LIR_Opr lock = syncLockOpr();
2698 __ load_stack_address_monitor(0, lock);
2699
2700 CodeEmitInfo* info = new CodeEmitInfo(scope()->start()->state()->copy(ValueStack::StateBefore, SynchronizationEntryBCI), nullptr, x->check_flag(Instruction::DeoptimizeOnException));
2701 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info);
2702
2703 // receiver is guaranteed non-null so don't need CodeEmitInfo
3269 freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
3270 }
3271 increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
3272 }
3273
3274 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info,
3275 ciMethod *method, LIR_Opr step, int frequency,
3276 int bci, bool backedge, bool notify) {
3277 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0");
3278 int level = _compilation->env()->comp_level();
3279 assert(level > CompLevel_simple, "Shouldn't be here");
3280
3281 int offset = -1;
3282 LIR_Opr counter_holder;
3283 if (level == CompLevel_limited_profile) {
3284 MethodCounters* counters_adr = method->ensure_method_counters();
3285 if (counters_adr == nullptr) {
3286 bailout("method counters allocation failed");
3287 return;
3288 }
3289 if (SCCache::is_on()) {
3290 counter_holder = new_register(T_METADATA);
3291 __ metadata2reg(counters_adr, counter_holder);
3292 } else {
3293 counter_holder = new_pointer_register();
3294 __ move(LIR_OprFact::intptrConst(counters_adr), counter_holder);
3295 }
3296 offset = in_bytes(backedge ? MethodCounters::backedge_counter_offset() :
3297 MethodCounters::invocation_counter_offset());
3298 } else if (level == CompLevel_full_profile) {
3299 counter_holder = new_register(T_METADATA);
3300 offset = in_bytes(backedge ? MethodData::backedge_counter_offset() :
3301 MethodData::invocation_counter_offset());
3302 ciMethodData* md = method->method_data_or_null();
3303 assert(md != nullptr, "Sanity");
3304 __ metadata2reg(md->constant_encoding(), counter_holder);
3305 } else {
3306 ShouldNotReachHere();
3307 }
3308 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT);
3309 LIR_Opr result = new_register(T_INT);
3310 __ load(counter, result);
3311 __ add(result, step, result);
3312 __ store(result, counter);
3313 if (notify && (!backedge || UseOnStackReplacement)) {
3314 LIR_Opr meth = LIR_OprFact::metadataConst(method->constant_encoding());
3315 // The bci for info can point to cmp for if's we want the if bci
|