Skip to content

Commit eb02184

Browse files
author
Daniel D. Daugherty
committed
8134630: make code and comments consistent for stack lock optimization
Reviewed-by: dholmes, coleenp
1 parent f751738 commit eb02184

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,33 @@ void InterpreterMacroAssembler::lock_object(Register lock_reg)
775775
cmpxchg_obj_header(swap_reg, lock_reg, obj_reg, rscratch1, done, /*fallthrough*/NULL);
776776
}
777777

778-
// Test if the oopMark is an obvious stack pointer, i.e.,
778+
// Fast check for recursive lock.
779+
//
780+
// Can apply the optimization only if this is a stack lock
781+
// allocated in this thread. For efficiency, we can focus on
782+
// recently allocated stack locks (instead of reading the stack
783+
// base and checking whether 'mark' points inside the current
784+
// thread stack):
779785
// 1) (mark & 7) == 0, and
780-
// 2) rsp <= mark < mark + os::pagesize()
786+
// 2) sp <= mark < mark + os::pagesize()
787+
//
788+
// Warning: sp + os::pagesize can overflow the stack base. We must
789+
// neither apply the optimization for an inflated lock allocated
790+
// just above the thread stack (this is why condition 1 matters)
791+
// nor apply the optimization if the stack lock is inside the stack
792+
// of another thread. The latter is avoided even in case of overflow
793+
// because we have guard pages at the end of all stacks. Hence, if
794+
// we go over the stack base and hit the stack of another thread,
795+
// this should not be in a writeable area that could contain a
796+
// stack lock allocated by that thread. As a consequence, a stack
797+
// lock less than page size away from sp is guaranteed to be
798+
// owned by the current thread.
781799
//
782800
// These 3 tests can be done by evaluating the following
783-
// expression: ((mark - rsp) & (7 - os::vm_page_size())),
801+
// expression: ((mark - sp) & (7 - os::vm_page_size())),
784802
// assuming both stack pointer and pagesize have their
785803
// least significant 3 bits clear.
786-
// NOTE: the oopMark is in swap_reg %r0 as the result of cmpxchg
804+
// NOTE: the mark is in swap_reg %r0 as the result of cmpxchg
787805
// NOTE2: aarch64 does not like to subtract sp from rn so take a
788806
// copy
789807
mov(rscratch1, sp);

src/hotspot/cpu/x86/interp_masm_x86.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,15 +1252,33 @@ void InterpreterMacroAssembler::lock_object(Register lock_reg) {
12521252

12531253
const int zero_bits = LP64_ONLY(7) NOT_LP64(3);
12541254

1255-
// Test if the oopMark is an obvious stack pointer, i.e.,
1255+
// Fast check for recursive lock.
1256+
//
1257+
// Can apply the optimization only if this is a stack lock
1258+
// allocated in this thread. For efficiency, we can focus on
1259+
// recently allocated stack locks (instead of reading the stack
1260+
// base and checking whether 'mark' points inside the current
1261+
// thread stack):
12561262
// 1) (mark & zero_bits) == 0, and
12571263
// 2) rsp <= mark < mark + os::pagesize()
12581264
//
1265+
// Warning: rsp + os::pagesize can overflow the stack base. We must
1266+
// neither apply the optimization for an inflated lock allocated
1267+
// just above the thread stack (this is why condition 1 matters)
1268+
// nor apply the optimization if the stack lock is inside the stack
1269+
// of another thread. The latter is avoided even in case of overflow
1270+
// because we have guard pages at the end of all stacks. Hence, if
1271+
// we go over the stack base and hit the stack of another thread,
1272+
// this should not be in a writeable area that could contain a
1273+
// stack lock allocated by that thread. As a consequence, a stack
1274+
// lock less than page size away from rsp is guaranteed to be
1275+
// owned by the current thread.
1276+
//
12591277
// These 3 tests can be done by evaluating the following
12601278
// expression: ((mark - rsp) & (zero_bits - os::vm_page_size())),
12611279
// assuming both stack pointer and pagesize have their
12621280
// least significant bits clear.
1263-
// NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
1281+
// NOTE: the mark is in swap_reg %rax as the result of cmpxchg
12641282
subptr(swap_reg, rsp);
12651283
andptr(swap_reg, zero_bits - os::vm_page_size());
12661284

0 commit comments

Comments
 (0)