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