99 |
99 |
100 @Override |
100 @Override |
101 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
101 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
102 directCall(crb, masm, callTarget, null, true, state); |
102 directCall(crb, masm, callTarget, null, true, state); |
103 } |
103 } |
|
104 |
|
105 public int emitCall(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
|
106 return directCall(crb, masm, callTarget, null, true, state); |
|
107 } |
104 } |
108 } |
105 |
109 |
106 @Opcode("CALL_INDIRECT") |
110 @Opcode("CALL_INDIRECT") |
107 public static class IndirectCallOp extends MethodCallOp { |
111 public static class IndirectCallOp extends MethodCallOp { |
108 public static final LIRInstructionClass<IndirectCallOp> TYPE = LIRInstructionClass.create(IndirectCallOp.class); |
112 public static final LIRInstructionClass<IndirectCallOp> TYPE = LIRInstructionClass.create(IndirectCallOp.class); |
181 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
185 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
182 directCall(crb, masm, callTarget, ((RegisterValue) callTemp).getRegister(), false, state); |
186 directCall(crb, masm, callTarget, ((RegisterValue) callTemp).getRegister(), false, state); |
183 } |
187 } |
184 } |
188 } |
185 |
189 |
186 public static void directCall(CompilationResultBuilder crb, AMD64MacroAssembler masm, InvokeTarget callTarget, Register scratch, boolean align, LIRFrameState info) { |
190 public static int directCall(CompilationResultBuilder crb, AMD64MacroAssembler masm, InvokeTarget callTarget, Register scratch, boolean align, LIRFrameState info) { |
187 if (align) { |
191 if (align) { |
188 emitAlignmentForDirectCall(crb, masm); |
192 emitAlignmentForDirectCall(crb, masm); |
189 } |
193 } |
190 int before = masm.position(); |
194 int before = masm.position(); |
|
195 int callPCOffset; |
191 if (scratch != null) { |
196 if (scratch != null) { |
192 // offset might not fit a 32-bit immediate, generate an |
197 // offset might not fit a 32-bit immediate, generate an |
193 // indirect call with a 64-bit immediate |
198 // indirect call with a 64-bit immediate |
194 masm.movq(scratch, 0L); |
199 masm.movq(scratch, 0L); |
|
200 callPCOffset = masm.position(); |
195 masm.call(scratch); |
201 masm.call(scratch); |
196 } else { |
202 } else { |
|
203 callPCOffset = masm.position(); |
197 masm.call(); |
204 masm.call(); |
198 } |
205 } |
199 int after = masm.position(); |
206 int after = masm.position(); |
200 crb.recordDirectCall(before, after, callTarget, info); |
207 crb.recordDirectCall(before, after, callTarget, info); |
201 crb.recordExceptionHandlers(after, info); |
208 crb.recordExceptionHandlers(after, info); |
202 masm.ensureUniquePC(); |
209 masm.ensureUniquePC(); |
|
210 return callPCOffset; |
203 } |
211 } |
204 |
212 |
205 protected static void emitAlignmentForDirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
213 protected static void emitAlignmentForDirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm) { |
206 // make sure that the displacement word of the call ends up word aligned |
214 // make sure that the displacement word of the call ends up word aligned |
207 int offset = masm.position(); |
215 int offset = masm.position(); |
226 int after = masm.position(); |
234 int after = masm.position(); |
227 crb.recordDirectCall(before, after, target, null); |
235 crb.recordDirectCall(before, after, target, null); |
228 masm.ensureUniquePC(); |
236 masm.ensureUniquePC(); |
229 } |
237 } |
230 |
238 |
231 public static void indirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register dst, InvokeTarget callTarget, LIRFrameState info) { |
239 public static int indirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register dst, InvokeTarget callTarget, LIRFrameState info) { |
232 int before = masm.position(); |
240 int before = masm.position(); |
233 masm.call(dst); |
241 masm.call(dst); |
234 int after = masm.position(); |
242 int after = masm.position(); |
235 crb.recordIndirectCall(before, after, callTarget, info); |
243 crb.recordIndirectCall(before, after, callTarget, info); |
236 crb.recordExceptionHandlers(after, info); |
244 crb.recordExceptionHandlers(after, info); |
237 masm.ensureUniquePC(); |
245 masm.ensureUniquePC(); |
|
246 return before; |
238 } |
247 } |
239 } |
248 } |