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) {
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 // Save caller's stack pointer into RBP if the frame pointer is preserved.
95 if (PreserveFramePointer) {
100
101 // Create frame
102 if (framesize) {
103 subptr(rsp, framesize);
104 }
105 } else {
106 subptr(rsp, framesize);
107
108 // Save RBP register now.
109 framesize -= wordSize;
110 movptr(Address(rsp, framesize), rbp);
111 // Save caller's stack pointer into RBP if the frame pointer is preserved.
112 if (PreserveFramePointer) {
113 movptr(rbp, rsp);
114 if (framesize > 0) {
115 addptr(rbp, framesize);
116 }
117 }
118 }
119
120 if (C->needs_stack_repair()) {
121 // Save stack increment just below the saved rbp (also account for fixed framesize and rbp)
122 assert((sp_inc & (StackAlignmentInBytes-1)) == 0, "stack increment not aligned");
123 movptr(Address(rsp, framesize - wordSize), sp_inc + framesize + wordSize);
124 }
125
126 if (VerifyStackAtCalls) { // Majik cookie to verify stack depth
127 framesize -= wordSize;
128 movptr(Address(rsp, framesize), (int32_t)0xbadb100d);
129 }
130
131 #ifdef ASSERT
132 if (VerifyStackAtCalls) {
133 Label L;
134 push(rax);
135 mov(rax, rsp);
136 andptr(rax, StackAlignmentInBytes-1);
137 cmpptr(rax, StackAlignmentInBytes-wordSize);
138 pop(rax);
139 jcc(Assembler::equal, L);
140 STOP("Stack is not properly aligned!");
141 bind(L);
142 }
143 #endif
144 }
145
146 void C2_MacroAssembler::entry_barrier() {
147 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
148 // We put the non-hot code of the nmethod entry barrier out-of-line in a stub.
149 Label dummy_slow_path;
150 Label dummy_continuation;
151 Label* slow_path = &dummy_slow_path;
152 Label* continuation = &dummy_continuation;
153 if (!Compile::current()->output()->in_scratch_emit_size()) {
154 // Use real labels from actual stub when not emitting code for the purpose of measuring its size
155 C2EntryBarrierStub* stub = new (Compile::current()->comp_arena()) C2EntryBarrierStub();
156 Compile::current()->output()->add_stub(stub);
157 slow_path = &stub->entry();
158 continuation = &stub->continuation();
159 }
160 bs->nmethod_entry_barrier(this, slow_path, continuation);
161 }
162
163 inline Assembler::AvxVectorLen C2_MacroAssembler::vector_length_encoding(int vlen_in_bytes) {
164 switch (vlen_in_bytes) {
165 case 4: // fall-through
166 case 8: // fall-through
167 case 16: return Assembler::AVX_128bit;
168 case 32: return Assembler::AVX_256bit;
169 case 64: return Assembler::AVX_512bit;
170
171 default: {
172 ShouldNotReachHere();
173 return Assembler::AVX_NoVec;
174 }
175 }
176 }
177
178 // fast_lock and fast_unlock used by C2
179
180 // Because the transitions from emitted code to the runtime
|