42
42
#include " utilities/globalDefinitions.hpp"
43
43
44
44
int C1_MacroAssembler::lock_object (Register hdr, Register obj, Register disp_hdr, Register tmp, Label& slow_case) {
45
- const int aligned_mask = BytesPerWord -1 ;
46
- const int hdr_offset = oopDesc::mark_offset_in_bytes ();
47
45
assert (hdr == rax, " hdr must be rax, for the cmpxchg instruction" );
48
46
assert_different_registers (hdr, obj, disp_hdr, tmp);
49
47
int null_check_offset = -1 ;
@@ -55,93 +53,20 @@ int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr
55
53
56
54
null_check_offset = offset ();
57
55
58
- if (LockingMode == LM_LIGHTWEIGHT) {
59
- lightweight_lock (disp_hdr, obj, hdr, tmp, slow_case);
60
- } else if (LockingMode == LM_LEGACY) {
61
- Label done;
62
-
63
- if (DiagnoseSyncOnValueBasedClasses != 0 ) {
64
- load_klass (hdr, obj, rscratch1);
65
- testb (Address (hdr, Klass::misc_flags_offset ()), KlassFlags::_misc_is_value_based_class);
66
- jcc (Assembler::notZero, slow_case);
67
- }
68
-
69
- // Load object header
70
- movptr (hdr, Address (obj, hdr_offset));
71
- // and mark it as unlocked
72
- orptr (hdr, markWord::unlocked_value);
73
- // save unlocked object header into the displaced header location on the stack
74
- movptr (Address (disp_hdr, 0 ), hdr);
75
- // test if object header is still the same (i.e. unlocked), and if so, store the
76
- // displaced header address in the object header - if it is not the same, get the
77
- // object header instead
78
- MacroAssembler::lock (); // must be immediately before cmpxchg!
79
- cmpxchgptr (disp_hdr, Address (obj, hdr_offset));
80
- // if the object header was the same, we're done
81
- jcc (Assembler::equal, done);
82
- // if the object header was not the same, it is now in the hdr register
83
- // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
84
- //
85
- // 1) (hdr & aligned_mask) == 0
86
- // 2) rsp <= hdr
87
- // 3) hdr <= rsp + page_size
88
- //
89
- // these 3 tests can be done by evaluating the following expression:
90
- //
91
- // (hdr - rsp) & (aligned_mask - page_size)
92
- //
93
- // assuming both the stack pointer and page_size have their least
94
- // significant 2 bits cleared and page_size is a power of 2
95
- subptr (hdr, rsp);
96
- andptr (hdr, aligned_mask - (int )os::vm_page_size ());
97
- // for recursive locking, the result is zero => save it in the displaced header
98
- // location (null in the displaced hdr location indicates recursive locking)
99
- movptr (Address (disp_hdr, 0 ), hdr);
100
- // otherwise we don't care about the result and handle locking via runtime call
101
- jcc (Assembler::notZero, slow_case);
102
- // done
103
- bind (done);
104
- inc_held_monitor_count ();
105
- }
56
+ lightweight_lock (disp_hdr, obj, hdr, tmp, slow_case);
106
57
107
58
return null_check_offset;
108
59
}
109
60
110
61
void C1_MacroAssembler::unlock_object (Register hdr, Register obj, Register disp_hdr, Label& slow_case) {
111
- const int aligned_mask = BytesPerWord -1 ;
112
- const int hdr_offset = oopDesc::mark_offset_in_bytes ();
113
62
assert (disp_hdr == rax, " disp_hdr must be rax, for the cmpxchg instruction" );
114
63
assert (hdr != obj && hdr != disp_hdr && obj != disp_hdr, " registers must be different" );
115
- Label done;
116
-
117
- if (LockingMode != LM_LIGHTWEIGHT) {
118
- // load displaced header
119
- movptr (hdr, Address (disp_hdr, 0 ));
120
- // if the loaded hdr is null we had recursive locking
121
- testptr (hdr, hdr);
122
- // if we had recursive locking, we are done
123
- jcc (Assembler::zero, done);
124
- }
125
64
126
65
// load object
127
66
movptr (obj, Address (disp_hdr, BasicObjectLock::obj_offset ()));
128
67
verify_oop (obj);
129
68
130
- if (LockingMode == LM_LIGHTWEIGHT) {
131
- lightweight_unlock (obj, disp_hdr, hdr, slow_case);
132
- } else if (LockingMode == LM_LEGACY) {
133
- // test if object header is pointing to the displaced header, and if so, restore
134
- // the displaced header in the object - if the object header is not pointing to
135
- // the displaced header, get the object header instead
136
- MacroAssembler::lock (); // must be immediately before cmpxchg!
137
- cmpxchgptr (hdr, Address (obj, hdr_offset));
138
- // if the object header was not pointing to the displaced header,
139
- // we do unlocking via runtime call
140
- jcc (Assembler::notEqual, slow_case);
141
- // done
142
- bind (done);
143
- dec_held_monitor_count ();
144
- }
69
+ lightweight_unlock (obj, disp_hdr, hdr, slow_case);
145
70
}
146
71
147
72
0 commit comments