Skip to content

Commit e5b56ba

Browse files
committedJun 9, 2022
8288040: x86: Loom: Improve cont/monitor-count helper methods
Reviewed-by: coleenp, rpressler
1 parent 5a89cb0 commit e5b56ba

8 files changed

+121
-79
lines changed
 

‎src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp

+3-24
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,7 @@ int LIR_Assembler::emit_unwind_handler() {
460460
__ unlock_object(rdi, rsi, rax, *stub->entry());
461461
}
462462
__ bind(*stub->continuation());
463-
NOT_LP64(__ get_thread(thread);)
464-
__ dec_held_monitor_count(thread);
463+
__ dec_held_monitor_count();
465464
}
466465

467466
if (compilation()->env()->dtrace_method_probes()) {
@@ -3516,32 +3515,12 @@ void LIR_Assembler::emit_lock(LIR_OpLock* op) {
35163515
// will be skipped. Solution is
35173516
// 1. Increase only in fastpath
35183517
// 2. Runtime1::monitorenter increase count after locking
3519-
#ifndef _LP64
3520-
Register thread = rsi;
3521-
__ push(thread);
3522-
__ get_thread(thread);
3523-
#else
3524-
Register thread = r15_thread;
3525-
#endif
3526-
__ inc_held_monitor_count(thread);
3527-
#ifndef _LP64
3528-
__ pop(thread);
3529-
#endif
3518+
__ inc_held_monitor_count();
35303519
}
35313520
__ bind(*op->stub()->continuation());
35323521
if (op->code() == lir_unlock) {
35333522
// unlock in slowpath is JRT_Leaf stub, no deoptimization can happen
3534-
#ifndef _LP64
3535-
Register thread = rsi;
3536-
__ push(thread);
3537-
__ get_thread(thread);
3538-
#else
3539-
Register thread = r15_thread;
3540-
#endif
3541-
__ dec_held_monitor_count(thread);
3542-
#ifndef _LP64
3543-
__ pop(thread);
3544-
#endif
3523+
__ dec_held_monitor_count();
35453524
}
35463525
}
35473526

‎src/hotspot/cpu/x86/interp_masm_x86.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,7 @@ void InterpreterMacroAssembler::remove_activation(
10641064

10651065
bind(unlock);
10661066
unlock_object(robj);
1067-
NOT_LP64(get_thread(rthread);)
1068-
dec_held_monitor_count(rthread);
1067+
dec_held_monitor_count();
10691068

10701069
pop(state);
10711070

@@ -1111,8 +1110,7 @@ void InterpreterMacroAssembler::remove_activation(
11111110
push(state);
11121111
mov(robj, rmon); // nop if robj and rmon are the same
11131112
unlock_object(robj);
1114-
NOT_LP64(get_thread(rthread);)
1115-
dec_held_monitor_count(rthread);
1113+
dec_held_monitor_count();
11161114
pop(state);
11171115

11181116
if (install_monitor_exception) {
@@ -1173,7 +1171,7 @@ void InterpreterMacroAssembler::remove_activation(
11731171
leave(); // remove frame anchor
11741172
pop(ret_addr); // get return address
11751173
mov(rsp, rbx); // set sp to sender sp
1176-
pop_cont_fastpath(rthread);
1174+
pop_cont_fastpath();
11771175
}
11781176

11791177
void InterpreterMacroAssembler::get_method_counters(Register method,

‎src/hotspot/cpu/x86/macroAssembler_x86.cpp

+98-12
Original file line numberDiff line numberDiff line change
@@ -2833,36 +2833,122 @@ void MacroAssembler::push_IU_state() {
28332833
pusha();
28342834
}
28352835

2836-
void MacroAssembler::push_cont_fastpath(Register java_thread) {
2836+
void MacroAssembler::push_cont_fastpath() {
28372837
if (!Continuations::enabled()) return;
2838+
2839+
#ifndef _LP64
2840+
Register rthread = rax;
2841+
Register rrealsp = rbx;
2842+
push(rthread);
2843+
push(rrealsp);
2844+
2845+
get_thread(rthread);
2846+
2847+
// The code below wants the original RSP.
2848+
// Move it back after the pushes above.
2849+
movptr(rrealsp, rsp);
2850+
addptr(rrealsp, 2*wordSize);
2851+
#else
2852+
Register rthread = r15_thread;
2853+
Register rrealsp = rsp;
2854+
#endif
2855+
28382856
Label done;
2839-
cmpptr(rsp, Address(java_thread, JavaThread::cont_fastpath_offset()));
2857+
cmpptr(rrealsp, Address(rthread, JavaThread::cont_fastpath_offset()));
28402858
jccb(Assembler::belowEqual, done);
2841-
movptr(Address(java_thread, JavaThread::cont_fastpath_offset()), rsp);
2859+
movptr(Address(rthread, JavaThread::cont_fastpath_offset()), rrealsp);
28422860
bind(done);
2861+
2862+
#ifndef _LP64
2863+
pop(rrealsp);
2864+
pop(rthread);
2865+
#endif
28432866
}
28442867

2845-
void MacroAssembler::pop_cont_fastpath(Register java_thread) {
2868+
void MacroAssembler::pop_cont_fastpath() {
28462869
if (!Continuations::enabled()) return;
2870+
2871+
#ifndef _LP64
2872+
Register rthread = rax;
2873+
Register rrealsp = rbx;
2874+
push(rthread);
2875+
push(rrealsp);
2876+
2877+
get_thread(rthread);
2878+
2879+
// The code below wants the original RSP.
2880+
// Move it back after the pushes above.
2881+
movptr(rrealsp, rsp);
2882+
addptr(rrealsp, 2*wordSize);
2883+
#else
2884+
Register rthread = r15_thread;
2885+
Register rrealsp = rsp;
2886+
#endif
2887+
28472888
Label done;
2848-
cmpptr(rsp, Address(java_thread, JavaThread::cont_fastpath_offset()));
2889+
cmpptr(rrealsp, Address(rthread, JavaThread::cont_fastpath_offset()));
28492890
jccb(Assembler::below, done);
2850-
movptr(Address(java_thread, JavaThread::cont_fastpath_offset()), 0);
2891+
movptr(Address(rthread, JavaThread::cont_fastpath_offset()), 0);
28512892
bind(done);
2893+
2894+
#ifndef _LP64
2895+
pop(rrealsp);
2896+
pop(rthread);
2897+
#endif
28522898
}
28532899

2854-
void MacroAssembler::inc_held_monitor_count(Register java_thread) {
2900+
void MacroAssembler::inc_held_monitor_count() {
28552901
if (!Continuations::enabled()) return;
2856-
incrementl(Address(java_thread, JavaThread::held_monitor_count_offset()));
2902+
2903+
#ifndef _LP64
2904+
Register thread = rax;
2905+
push(thread);
2906+
get_thread(thread);
2907+
#else
2908+
Register thread = r15_thread;
2909+
#endif
2910+
2911+
incrementl(Address(thread, JavaThread::held_monitor_count_offset()));
2912+
2913+
#ifndef _LP64
2914+
pop(thread);
2915+
#endif
28572916
}
28582917

2859-
void MacroAssembler::dec_held_monitor_count(Register java_thread) {
2918+
void MacroAssembler::dec_held_monitor_count() {
28602919
if (!Continuations::enabled()) return;
2861-
decrementl(Address(java_thread, JavaThread::held_monitor_count_offset()));
2920+
2921+
#ifndef _LP64
2922+
Register thread = rax;
2923+
push(thread);
2924+
get_thread(thread);
2925+
#else
2926+
Register thread = r15_thread;
2927+
#endif
2928+
2929+
decrementl(Address(thread, JavaThread::held_monitor_count_offset()));
2930+
2931+
#ifndef _LP64
2932+
pop(thread);
2933+
#endif
28622934
}
28632935

2864-
void MacroAssembler::reset_held_monitor_count(Register java_thread) {
2865-
movl(Address(java_thread, JavaThread::held_monitor_count_offset()), (int32_t)0);
2936+
void MacroAssembler::reset_held_monitor_count() {
2937+
if (!Continuations::enabled()) return;
2938+
2939+
#ifndef _LP64
2940+
Register thread = rax;
2941+
push(thread);
2942+
get_thread(thread);
2943+
#else
2944+
Register thread = r15_thread;
2945+
#endif
2946+
2947+
movl(Address(thread, JavaThread::held_monitor_count_offset()), (int32_t)0);
2948+
2949+
#ifndef _LP64
2950+
pop(thread);
2951+
#endif
28662952
}
28672953

28682954
#ifdef ASSERT

‎src/hotspot/cpu/x86/macroAssembler_x86.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ class MacroAssembler: public Assembler {
524524
void push_CPU_state();
525525
void pop_CPU_state();
526526

527-
void push_cont_fastpath(Register java_thread);
528-
void pop_cont_fastpath(Register java_thread);
529-
void inc_held_monitor_count(Register java_thread);
530-
void dec_held_monitor_count(Register java_thread);
531-
void reset_held_monitor_count(Register java_thread);
527+
void push_cont_fastpath();
528+
void pop_cont_fastpath();
529+
void inc_held_monitor_count();
530+
void dec_held_monitor_count();
531+
void reset_held_monitor_count();
532532
DEBUG_ONLY(void stop_if_in_cont(Register cont_reg, const char* name);)
533533

534534
// Round up to a power of two

‎src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ void SharedRuntime::gen_i2c_adapter(MacroAssembler *masm,
941941
}
942942
}
943943

944-
__ push_cont_fastpath(r15_thread); // Set JavaThread::_cont_fastpath to the sp of the oldest interpreted frame we know about
944+
__ push_cont_fastpath(); // Set JavaThread::_cont_fastpath to the sp of the oldest interpreted frame we know about
945945

946946
// 6243940 We might end up in handle_wrong_method if
947947
// the callee is deoptimized as we race thru here. If that

‎src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class StubGenerator: public StubCodeGenerator {
393393
}
394394
#endif
395395

396-
__ pop_cont_fastpath(r15_thread);
396+
__ pop_cont_fastpath();
397397

398398
// restore regs belonging to calling function
399399
#ifdef _WIN64
@@ -8338,7 +8338,7 @@ void fill_continuation_entry(MacroAssembler* masm, Register reg_cont_obj, Regist
83388338
__ movl(Address(rsp, ContinuationEntry::parent_held_monitor_count_offset()), rax);
83398339

83408340
__ movptr(Address(r15_thread, JavaThread::cont_fastpath_offset()), 0);
8341-
__ reset_held_monitor_count(r15_thread);
8341+
__ reset_held_monitor_count();
83428342
}
83438343

83448344
//---------------------------- continuation_enter_cleanup ---------------------------

‎src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp

+5-21
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,10 @@ address TemplateInterpreterGenerator::generate_safept_entry_for(
367367
address runtime_entry) {
368368
address entry = __ pc();
369369

370-
const Register rthread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
371-
372370
__ push(state);
373-
NOT_LP64(__ get_thread(rthread);)
374-
__ push_cont_fastpath(rthread);
371+
__ push_cont_fastpath();
375372
__ call_VM(noreg, runtime_entry);
376-
NOT_LP64(__ get_thread(rthread);)
377-
__ pop_cont_fastpath(rthread);
373+
__ pop_cont_fastpath();
378374

379375
__ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
380376
return entry;
@@ -609,9 +605,7 @@ void TemplateInterpreterGenerator::lock_method() {
609605
__ movptr(lockreg, rsp); // object address
610606
__ lock_object(lockreg);
611607

612-
Register rthread = NOT_LP64(rax) LP64_ONLY(r15_thread);
613-
NOT_LP64(__ get_thread(rthread);)
614-
__ inc_held_monitor_count(rthread);
608+
__ inc_held_monitor_count();
615609
}
616610

617611
// Generate a fixed interpreter frame. This is identical setup for
@@ -666,24 +660,15 @@ void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
666660
address TemplateInterpreterGenerator::generate_Continuation_doYield_entry(void) {
667661
if (!Continuations::enabled()) return nullptr;
668662

669-
#ifdef _LP64
670663
address entry = __ pc();
671664
assert(StubRoutines::cont_doYield() != NULL, "stub not yet generated");
672665

673-
// __ movl(c_rarg1, Address(rsp, wordSize)); // scopes
674-
const Register thread1 = NOT_LP64(rdi) LP64_ONLY(r15_thread);
675-
NOT_LP64(__ get_thread(thread1));
676-
__ push_cont_fastpath(thread1);
666+
__ push_cont_fastpath();
677667

678668
__ jump(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::cont_doYield())));
679669
// return value is in rax
680670

681671
return entry;
682-
#else
683-
// Not implemented. Allow startup of legacy Java code that does not touch
684-
// Continuation.doYield yet. Throw AbstractMethodError on access.
685-
return generate_abstract_entry();
686-
#endif
687672
}
688673

689674
// Method entry for java.lang.ref.Reference.get.
@@ -1279,8 +1264,7 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
12791264

12801265
__ bind(unlock);
12811266
__ unlock_object(regmon);
1282-
NOT_LP64(__ get_thread(thread);)
1283-
__ dec_held_monitor_count(thread);
1267+
__ dec_held_monitor_count();
12841268
}
12851269
__ bind(L);
12861270
}

‎src/hotspot/cpu/x86/templateTable_x86.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -2592,11 +2592,10 @@ void TemplateTable::_return(TosState state) {
25922592
#endif
25932593
__ jcc(Assembler::zero, no_safepoint);
25942594
__ push(state);
2595-
__ push_cont_fastpath(NOT_LP64(thread) LP64_ONLY(r15_thread));
2595+
__ push_cont_fastpath();
25962596
__ call_VM(noreg, CAST_FROM_FN_PTR(address,
25972597
InterpreterRuntime::at_safepoint));
2598-
NOT_LP64(__ get_thread(thread);)
2599-
__ pop_cont_fastpath(NOT_LP64(thread) LP64_ONLY(r15_thread));
2598+
__ pop_cont_fastpath();
26002599
__ pop(state);
26012600
__ bind(no_safepoint);
26022601
}
@@ -4365,9 +4364,7 @@ void TemplateTable::monitorenter() {
43654364
__ lock_object(rmon);
43664365

43674366
// The object is stored so counter should be increased even if stackoverflow is generated
4368-
Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rbx);
4369-
NOT_LP64(__ get_thread(rthread);)
4370-
__ inc_held_monitor_count(rthread);
4367+
__ inc_held_monitor_count();
43714368

43724369
// check to make sure this monitor doesn't cause stack overflow after locking
43734370
__ save_bcp(); // in case of exception
@@ -4428,9 +4425,7 @@ void TemplateTable::monitorexit() {
44284425
__ push_ptr(rax); // make sure object is on stack (contract with oopMaps)
44294426
__ unlock_object(rtop);
44304427

4431-
Register rthread = LP64_ONLY(r15_thread) NOT_LP64(rax);
4432-
NOT_LP64(__ get_thread(rthread);)
4433-
__ dec_held_monitor_count(rthread);
4428+
__ dec_held_monitor_count();
44344429

44354430
__ pop_ptr(rax); // discard object
44364431
}

0 commit comments

Comments
 (0)
Please sign in to comment.