34 #include "opto/subnode.hpp"
35 #include "runtime/globals.hpp"
36 #include "runtime/objectMonitor.hpp"
37 #include "runtime/objectMonitorTable.hpp"
38 #include "runtime/stubRoutines.hpp"
39 #include "runtime/synchronizer.hpp"
40 #include "utilities/checkedCast.hpp"
41 #include "utilities/globalDefinitions.hpp"
42 #include "utilities/powerOfTwo.hpp"
43 #include "utilities/sizes.hpp"
44
45 #ifdef PRODUCT
46 #define BLOCK_COMMENT(str) /* nothing */
47 #define STOP(error) stop(error)
48 #else
49 #define BLOCK_COMMENT(str) block_comment(str)
50 #define STOP(error) block_comment(error); stop(error)
51 #endif
52
53 // C2 compiled method's prolog code.
54 void C2_MacroAssembler::verified_entry(int framesize, int stack_bang_size, bool fp_mode_24b, bool is_stub) {
55 assert(stack_bang_size >= framesize || stack_bang_size <= 0, "stack bang size incorrect");
56
57 assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
58 // Remove word for return addr
59 framesize -= wordSize;
60 stack_bang_size -= wordSize;
61
62 // Calls to C2R adapters often do not accept exceptional returns.
63 // We require that their callers must bang for them. But be careful, because
64 // some VM calls (such as call site linkage) can use several kilobytes of
65 // stack. But the stack safety zone should account for that.
66 // See bugs 4446381, 4468289, 4497237.
67 if (stack_bang_size > 0) {
68 generate_stack_overflow_check(stack_bang_size);
69
70 // We always push rbp, so that on return to interpreter rbp, will be
71 // restored correctly and we can correct the stack.
72 push(rbp);
73 // Save caller's stack pointer into RBP if the frame pointer is preserved.
74 if (PreserveFramePointer) {
75 mov(rbp, rsp);
76 }
77 // Remove word for ebp
78 framesize -= wordSize;
79
80 // Create frame
81 if (framesize) {
82 subptr(rsp, framesize);
83 }
84 } else {
85 subptr(rsp, framesize);
86
87 // Save RBP register now.
88 framesize -= wordSize;
89 movptr(Address(rsp, framesize), rbp);
90 // Save caller's stack pointer into RBP if the frame pointer is preserved.
91 if (PreserveFramePointer) {
92 movptr(rbp, rsp);
93 if (framesize > 0) {
94 addptr(rbp, framesize);
95 }
96 }
97 }
98
99 if (VerifyStackAtCalls) { // Majik cookie to verify stack depth
100 framesize -= wordSize;
101 movptr(Address(rsp, framesize), (int32_t)0xbadb100d);
102 }
103
104 #ifdef ASSERT
105 if (VerifyStackAtCalls) {
106 Label L;
107 push(rax);
108 mov(rax, rsp);
109 andptr(rax, StackAlignmentInBytes-1);
110 cmpptr(rax, StackAlignmentInBytes-wordSize);
111 pop(rax);
112 jcc(Assembler::equal, L);
113 STOP("Stack is not properly aligned!");
114 bind(L);
115 }
116 #endif
117
118 if (!is_stub) {
119 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
120 // We put the non-hot code of the nmethod entry barrier out-of-line in a stub.
121 Label dummy_slow_path;
122 Label dummy_continuation;
123 Label* slow_path = &dummy_slow_path;
124 Label* continuation = &dummy_continuation;
125 if (!Compile::current()->output()->in_scratch_emit_size()) {
126 // Use real labels from actual stub when not emitting code for the purpose of measuring its size
127 C2EntryBarrierStub* stub = new (Compile::current()->comp_arena()) C2EntryBarrierStub();
128 Compile::current()->output()->add_stub(stub);
129 slow_path = &stub->entry();
130 continuation = &stub->continuation();
131 }
132 bs->nmethod_entry_barrier(this, slow_path, continuation);
133 }
134 }
135
136 inline Assembler::AvxVectorLen C2_MacroAssembler::vector_length_encoding(int vlen_in_bytes) {
137 switch (vlen_in_bytes) {
138 case 4: // fall-through
139 case 8: // fall-through
140 case 16: return Assembler::AVX_128bit;
141 case 32: return Assembler::AVX_256bit;
142 case 64: return Assembler::AVX_512bit;
143
144 default: {
145 ShouldNotReachHere();
146 return Assembler::AVX_NoVec;
147 }
148 }
149 }
150
151 // fast_lock and fast_unlock used by C2
152
153 // Because the transitions from emitted code to the runtime
|
34 #include "opto/subnode.hpp"
35 #include "runtime/globals.hpp"
36 #include "runtime/objectMonitor.hpp"
37 #include "runtime/objectMonitorTable.hpp"
38 #include "runtime/stubRoutines.hpp"
39 #include "runtime/synchronizer.hpp"
40 #include "utilities/checkedCast.hpp"
41 #include "utilities/globalDefinitions.hpp"
42 #include "utilities/powerOfTwo.hpp"
43 #include "utilities/sizes.hpp"
44
45 #ifdef PRODUCT
46 #define BLOCK_COMMENT(str) /* nothing */
47 #define STOP(error) stop(error)
48 #else
49 #define BLOCK_COMMENT(str) block_comment(str)
50 #define STOP(error) block_comment(error); stop(error)
51 #endif
52
53 // C2 compiled method's prolog code.
54 // Beware! This sp_inc is NOT the same as the one mentioned in MacroAssembler::remove_frame but only the size
55 // of the extension space + the additional copy of the return address. That means, it doesn't contain the
56 // frame size (where the local and sp_inc are) and the saved RBP.
57 void C2_MacroAssembler::verified_entry(Compile* C, int sp_inc) {
58 if (C->clinit_barrier_on_entry()) {
59 assert(VM_Version::supports_fast_class_init_checks(), "sanity");
60 assert(!C->method()->holder()->is_not_initialized(), "initialization should have been started");
61
62 Label L_skip_barrier;
63 Register klass = rscratch1;
64
65 mov_metadata(klass, C->method()->holder()->constant_encoding());
66 clinit_barrier(klass, &L_skip_barrier /*L_fast_path*/);
67
68 jump(RuntimeAddress(SharedRuntime::get_handle_wrong_method_stub())); // slow path
69
70 bind(L_skip_barrier);
71 }
72
73 int framesize = C->output()->frame_size_in_bytes();
74 int bangsize = C->output()->bang_size_in_bytes();
75 bool fp_mode_24b = false;
76 int stack_bang_size = C->output()->need_stack_bang(bangsize) ? bangsize : 0;
77
78 assert(stack_bang_size >= framesize || stack_bang_size <= 0, "stack bang size incorrect");
79
80 assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
81 // Remove word for return addr
82 framesize -= wordSize;
83 stack_bang_size -= wordSize;
84
85 // Calls to C2R adapters often do not accept exceptional returns.
86 // We require that their callers must bang for them. But be careful, because
87 // some VM calls (such as call site linkage) can use several kilobytes of
88 // stack. But the stack safety zone should account for that.
89 // See bugs 4446381, 4468289, 4497237.
90 if (stack_bang_size > 0) {
91 generate_stack_overflow_check(stack_bang_size);
92
93 // We always push rbp, so that on return to interpreter rbp, will be
94 // restored correctly and we can correct the stack.
95 push(rbp);
96 #ifdef ASSERT
97 if (sp_inc > 0) {
98 movl(Address(rsp, 0), badRegWordVal);
99 movl(Address(rsp, VMRegImpl::stack_slot_size), badRegWordVal);
100 }
101 #endif
102 // Save caller's stack pointer into RBP if the frame pointer is preserved.
103 if (PreserveFramePointer) {
104 mov(rbp, rsp);
105 }
106 // Remove word for ebp
107 framesize -= wordSize;
108
109 // Create frame
110 if (framesize) {
111 subptr(rsp, framesize);
112 }
113 } else {
114 subptr(rsp, framesize);
115
116 // Save RBP register now.
117 framesize -= wordSize;
118 movptr(Address(rsp, framesize), rbp);
119 #ifdef ASSERT
120 if (sp_inc > 0) {
121 movl(Address(rsp, framesize), badRegWordVal);
122 movl(Address(rsp, framesize + VMRegImpl::stack_slot_size), badRegWordVal);
123 }
124 #endif
125 // Save caller's stack pointer into RBP if the frame pointer is preserved.
126 if (PreserveFramePointer) {
127 movptr(rbp, rsp);
128 if (framesize > 0) {
129 addptr(rbp, framesize);
130 }
131 }
132 }
133
134 if (C->needs_stack_repair()) {
135 // Save stack increment just below the saved rbp (also account for fixed framesize and rbp)
136 assert((sp_inc & (StackAlignmentInBytes-1)) == 0, "stack increment not aligned");
137 movptr(Address(rsp, framesize - wordSize), sp_inc + framesize);
138 }
139
140 if (VerifyStackAtCalls) { // Majik cookie to verify stack depth
141 framesize -= wordSize;
142 movptr(Address(rsp, framesize), (int32_t)0xbadb100d);
143 }
144
145 #ifdef ASSERT
146 if (VerifyStackAtCalls) {
147 Label L;
148 push(rax);
149 mov(rax, rsp);
150 andptr(rax, StackAlignmentInBytes-1);
151 cmpptr(rax, StackAlignmentInBytes-wordSize);
152 pop(rax);
153 jcc(Assembler::equal, L);
154 STOP("Stack is not properly aligned!");
155 bind(L);
156 }
157 #endif
158 }
159
160 void C2_MacroAssembler::entry_barrier() {
161 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
162 // We put the non-hot code of the nmethod entry barrier out-of-line in a stub.
163 Label dummy_slow_path;
164 Label dummy_continuation;
165 Label* slow_path = &dummy_slow_path;
166 Label* continuation = &dummy_continuation;
167 if (!Compile::current()->output()->in_scratch_emit_size()) {
168 // Use real labels from actual stub when not emitting code for the purpose of measuring its size
169 C2EntryBarrierStub* stub = new (Compile::current()->comp_arena()) C2EntryBarrierStub();
170 Compile::current()->output()->add_stub(stub);
171 slow_path = &stub->entry();
172 continuation = &stub->continuation();
173 }
174 bs->nmethod_entry_barrier(this, slow_path, continuation);
175 }
176
177 inline Assembler::AvxVectorLen C2_MacroAssembler::vector_length_encoding(int vlen_in_bytes) {
178 switch (vlen_in_bytes) {
179 case 4: // fall-through
180 case 8: // fall-through
181 case 16: return Assembler::AVX_128bit;
182 case 32: return Assembler::AVX_256bit;
183 case 64: return Assembler::AVX_512bit;
184
185 default: {
186 ShouldNotReachHere();
187 return Assembler::AVX_NoVec;
188 }
189 }
190 }
191
192 // fast_lock and fast_unlock used by C2
193
194 // Because the transitions from emitted code to the runtime
|