blob: 1c9aed83c32cd21ef11c1d1fab96f4e479a97f64 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <algorithm>
18#include <vector>
19
20#include "base/logging.h"
21#include "base/macros.h"
22#include "calling_convention.h"
23#include "class_linker.h"
24#include "compiled_method.h"
25#include "dex_file-inl.h"
26#include "driver/compiler_driver.h"
Ian Rogers166db042013-07-26 12:05:57 -070027#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070028#include "jni_internal.h"
Ian Rogers166db042013-07-26 12:05:57 -070029#include "utils/assembler.h"
30#include "utils/managed_register.h"
31#include "utils/arm/managed_register_arm.h"
32#include "utils/mips/managed_register_mips.h"
33#include "utils/x86/managed_register_x86.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070034#include "thread.h"
35#include "UniquePtr.h"
36
37#define __ jni_asm->
38
39namespace art {
40
41static void CopyParameter(Assembler* jni_asm,
42 ManagedRuntimeCallingConvention* mr_conv,
43 JniCallingConvention* jni_conv,
44 size_t frame_size, size_t out_arg_size);
45static void SetNativeParameter(Assembler* jni_asm,
46 JniCallingConvention* jni_conv,
47 ManagedRegister in_reg);
48
49// Generate the JNI bridge for the given method, general contract:
50// - Arguments are in the managed runtime format, either on stack or in
51// registers, a reference to the method object is supplied as part of this
52// convention.
53//
54CompiledMethod* ArtJniCompileMethodInternal(CompilerDriver& compiler,
55 uint32_t access_flags, uint32_t method_idx,
56 const DexFile& dex_file) {
57 const bool is_native = (access_flags & kAccNative) != 0;
58 CHECK(is_native);
59 const bool is_static = (access_flags & kAccStatic) != 0;
60 const bool is_synchronized = (access_flags & kAccSynchronized) != 0;
61 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
62 InstructionSet instruction_set = compiler.GetInstructionSet();
63 if (instruction_set == kThumb2) {
64 instruction_set = kArm;
65 }
66 // Calling conventions used to iterate over parameters to method
67 UniquePtr<JniCallingConvention> main_jni_conv(
68 JniCallingConvention::Create(is_static, is_synchronized, shorty, instruction_set));
69 bool reference_return = main_jni_conv->IsReturnAReference();
70
71 UniquePtr<ManagedRuntimeCallingConvention> mr_conv(
72 ManagedRuntimeCallingConvention::Create(is_static, is_synchronized, shorty, instruction_set));
73
74 // Calling conventions to call into JNI method "end" possibly passing a returned reference, the
75 // method and the current thread.
76 size_t jni_end_arg_count = 0;
77 if (reference_return) { jni_end_arg_count++; }
78 if (is_synchronized) { jni_end_arg_count++; }
79 const char* jni_end_shorty = jni_end_arg_count == 0 ? "I"
80 : (jni_end_arg_count == 1 ? "II" : "III");
81 UniquePtr<JniCallingConvention> end_jni_conv(
82 JniCallingConvention::Create(is_static, is_synchronized, jni_end_shorty, instruction_set));
83
Brian Carlstrom7940e442013-07-12 13:46:57 -070084 // Assembler that holds generated instructions
85 UniquePtr<Assembler> jni_asm(Assembler::Create(instruction_set));
Brian Carlstrom7940e442013-07-12 13:46:57 -070086
87 // Offsets into data structures
88 // TODO: if cross compiling these offsets are for the host not the target
89 const Offset functions(OFFSETOF_MEMBER(JNIEnvExt, functions));
90 const Offset monitor_enter(OFFSETOF_MEMBER(JNINativeInterface, MonitorEnter));
91 const Offset monitor_exit(OFFSETOF_MEMBER(JNINativeInterface, MonitorExit));
92
93 // 1. Build the frame saving all callee saves
94 const size_t frame_size(main_jni_conv->FrameSize());
95 const std::vector<ManagedRegister>& callee_save_regs = main_jni_conv->CalleeSaveRegisters();
96 __ BuildFrame(frame_size, mr_conv->MethodRegister(), callee_save_regs, mr_conv->EntrySpills());
97
98 // 2. Set up the StackIndirectReferenceTable
99 mr_conv->ResetIterator(FrameOffset(frame_size));
100 main_jni_conv->ResetIterator(FrameOffset(0));
101 __ StoreImmediateToFrame(main_jni_conv->SirtNumRefsOffset(),
102 main_jni_conv->ReferenceCount(),
103 mr_conv->InterproceduralScratchRegister());
104 __ CopyRawPtrFromThread(main_jni_conv->SirtLinkOffset(),
105 Thread::TopSirtOffset(),
106 mr_conv->InterproceduralScratchRegister());
107 __ StoreStackOffsetToThread(Thread::TopSirtOffset(),
108 main_jni_conv->SirtOffset(),
109 mr_conv->InterproceduralScratchRegister());
110
111 // 3. Place incoming reference arguments into SIRT
112 main_jni_conv->Next(); // Skip JNIEnv*
113 // 3.5. Create Class argument for static methods out of passed method
114 if (is_static) {
115 FrameOffset sirt_offset = main_jni_conv->CurrentParamSirtEntryOffset();
116 // Check sirt offset is within frame
117 CHECK_LT(sirt_offset.Uint32Value(), frame_size);
118 __ LoadRef(main_jni_conv->InterproceduralScratchRegister(),
Brian Carlstromea46f952013-07-30 01:26:50 -0700119 mr_conv->MethodRegister(), mirror::ArtMethod::DeclaringClassOffset());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 __ VerifyObject(main_jni_conv->InterproceduralScratchRegister(), false);
121 __ StoreRef(sirt_offset, main_jni_conv->InterproceduralScratchRegister());
122 main_jni_conv->Next(); // in SIRT so move to next argument
123 }
124 while (mr_conv->HasNext()) {
125 CHECK(main_jni_conv->HasNext());
126 bool ref_param = main_jni_conv->IsCurrentParamAReference();
127 CHECK(!ref_param || mr_conv->IsCurrentParamAReference());
128 // References need placing in SIRT and the entry value passing
129 if (ref_param) {
130 // Compute SIRT entry, note null is placed in the SIRT but its boxed value
131 // must be NULL
132 FrameOffset sirt_offset = main_jni_conv->CurrentParamSirtEntryOffset();
133 // Check SIRT offset is within frame and doesn't run into the saved segment state
134 CHECK_LT(sirt_offset.Uint32Value(), frame_size);
135 CHECK_NE(sirt_offset.Uint32Value(),
136 main_jni_conv->SavedLocalReferenceCookieOffset().Uint32Value());
137 bool input_in_reg = mr_conv->IsCurrentParamInRegister();
138 bool input_on_stack = mr_conv->IsCurrentParamOnStack();
139 CHECK(input_in_reg || input_on_stack);
140
141 if (input_in_reg) {
142 ManagedRegister in_reg = mr_conv->CurrentParamRegister();
143 __ VerifyObject(in_reg, mr_conv->IsCurrentArgPossiblyNull());
144 __ StoreRef(sirt_offset, in_reg);
145 } else if (input_on_stack) {
146 FrameOffset in_off = mr_conv->CurrentParamStackOffset();
147 __ VerifyObject(in_off, mr_conv->IsCurrentArgPossiblyNull());
148 __ CopyRef(sirt_offset, in_off,
149 mr_conv->InterproceduralScratchRegister());
150 }
151 }
152 mr_conv->Next();
153 main_jni_conv->Next();
154 }
155
156 // 4. Write out the end of the quick frames.
157 __ StoreStackPointerToThread(Thread::TopOfManagedStackOffset());
158 __ StoreImmediateToThread(Thread::TopOfManagedStackPcOffset(), 0,
159 mr_conv->InterproceduralScratchRegister());
160
161 // 5. Move frame down to allow space for out going args.
162 const size_t main_out_arg_size = main_jni_conv->OutArgSize();
163 const size_t end_out_arg_size = end_jni_conv->OutArgSize();
164 const size_t max_out_arg_size = std::max(main_out_arg_size, end_out_arg_size);
165 __ IncreaseFrameSize(max_out_arg_size);
166
167
168 // 6. Call into appropriate JniMethodStart passing Thread* so that transition out of Runnable
169 // can occur. The result is the saved JNI local state that is restored by the exit call. We
170 // abuse the JNI calling convention here, that is guaranteed to support passing 2 pointer
171 // arguments.
Ian Rogers848871b2013-08-05 10:56:33 -0700172 ThreadOffset jni_start = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(pJniMethodStartSynchronized)
173 : QUICK_ENTRYPOINT_OFFSET(pJniMethodStart);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size));
175 FrameOffset locked_object_sirt_offset(0);
176 if (is_synchronized) {
177 // Pass object for locking.
178 main_jni_conv->Next(); // Skip JNIEnv.
179 locked_object_sirt_offset = main_jni_conv->CurrentParamSirtEntryOffset();
180 main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size));
181 if (main_jni_conv->IsCurrentParamOnStack()) {
182 FrameOffset out_off = main_jni_conv->CurrentParamStackOffset();
183 __ CreateSirtEntry(out_off, locked_object_sirt_offset,
184 mr_conv->InterproceduralScratchRegister(),
185 false);
186 } else {
187 ManagedRegister out_reg = main_jni_conv->CurrentParamRegister();
188 __ CreateSirtEntry(out_reg, locked_object_sirt_offset,
189 ManagedRegister::NoRegister(), false);
190 }
191 main_jni_conv->Next();
192 }
193 if (main_jni_conv->IsCurrentParamInRegister()) {
194 __ GetCurrentThread(main_jni_conv->CurrentParamRegister());
195 __ Call(main_jni_conv->CurrentParamRegister(), Offset(jni_start),
196 main_jni_conv->InterproceduralScratchRegister());
197 } else {
198 __ GetCurrentThread(main_jni_conv->CurrentParamStackOffset(),
199 main_jni_conv->InterproceduralScratchRegister());
200 __ Call(ThreadOffset(jni_start), main_jni_conv->InterproceduralScratchRegister());
201 }
202 if (is_synchronized) { // Check for exceptions from monitor enter.
203 __ ExceptionPoll(main_jni_conv->InterproceduralScratchRegister(), main_out_arg_size);
204 }
205 FrameOffset saved_cookie_offset = main_jni_conv->SavedLocalReferenceCookieOffset();
206 __ Store(saved_cookie_offset, main_jni_conv->IntReturnRegister(), 4);
207
208 // 7. Iterate over arguments placing values from managed calling convention in
209 // to the convention required for a native call (shuffling). For references
210 // place an index/pointer to the reference after checking whether it is
211 // NULL (which must be encoded as NULL).
212 // Note: we do this prior to materializing the JNIEnv* and static's jclass to
213 // give as many free registers for the shuffle as possible
214 mr_conv->ResetIterator(FrameOffset(frame_size+main_out_arg_size));
215 uint32_t args_count = 0;
216 while (mr_conv->HasNext()) {
217 args_count++;
218 mr_conv->Next();
219 }
220
221 // Do a backward pass over arguments, so that the generated code will be "mov
222 // R2, R3; mov R1, R2" instead of "mov R1, R2; mov R2, R3."
223 // TODO: A reverse iterator to improve readability.
224 for (uint32_t i = 0; i < args_count; ++i) {
225 mr_conv->ResetIterator(FrameOffset(frame_size + main_out_arg_size));
226 main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size));
227 main_jni_conv->Next(); // Skip JNIEnv*.
228 if (is_static) {
229 main_jni_conv->Next(); // Skip Class for now.
230 }
231 // Skip to the argument we're interested in.
232 for (uint32_t j = 0; j < args_count - i - 1; ++j) {
233 mr_conv->Next();
234 main_jni_conv->Next();
235 }
236 CopyParameter(jni_asm.get(), mr_conv.get(), main_jni_conv.get(), frame_size, main_out_arg_size);
237 }
238 if (is_static) {
239 // Create argument for Class
240 mr_conv->ResetIterator(FrameOffset(frame_size+main_out_arg_size));
241 main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size));
242 main_jni_conv->Next(); // Skip JNIEnv*
243 FrameOffset sirt_offset = main_jni_conv->CurrentParamSirtEntryOffset();
244 if (main_jni_conv->IsCurrentParamOnStack()) {
245 FrameOffset out_off = main_jni_conv->CurrentParamStackOffset();
246 __ CreateSirtEntry(out_off, sirt_offset,
247 mr_conv->InterproceduralScratchRegister(),
248 false);
249 } else {
250 ManagedRegister out_reg = main_jni_conv->CurrentParamRegister();
251 __ CreateSirtEntry(out_reg, sirt_offset,
252 ManagedRegister::NoRegister(), false);
253 }
254 }
255
256 // 8. Create 1st argument, the JNI environment ptr.
257 main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size));
258 // Register that will hold local indirect reference table
259 if (main_jni_conv->IsCurrentParamInRegister()) {
260 ManagedRegister jni_env = main_jni_conv->CurrentParamRegister();
261 DCHECK(!jni_env.Equals(main_jni_conv->InterproceduralScratchRegister()));
262 __ LoadRawPtrFromThread(jni_env, Thread::JniEnvOffset());
263 } else {
264 FrameOffset jni_env = main_jni_conv->CurrentParamStackOffset();
265 __ CopyRawPtrFromThread(jni_env, Thread::JniEnvOffset(),
266 main_jni_conv->InterproceduralScratchRegister());
267 }
268
269 // 9. Plant call to native code associated with method.
Brian Carlstromea46f952013-07-30 01:26:50 -0700270 __ Call(main_jni_conv->MethodStackOffset(), mirror::ArtMethod::NativeMethodOffset(),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700271 mr_conv->InterproceduralScratchRegister());
272
273 // 10. Fix differences in result widths.
274 if (instruction_set == kX86) {
275 if (main_jni_conv->GetReturnType() == Primitive::kPrimByte ||
276 main_jni_conv->GetReturnType() == Primitive::kPrimShort) {
277 __ SignExtend(main_jni_conv->ReturnRegister(),
278 Primitive::ComponentSize(main_jni_conv->GetReturnType()));
279 } else if (main_jni_conv->GetReturnType() == Primitive::kPrimBoolean ||
280 main_jni_conv->GetReturnType() == Primitive::kPrimChar) {
281 __ ZeroExtend(main_jni_conv->ReturnRegister(),
282 Primitive::ComponentSize(main_jni_conv->GetReturnType()));
283 }
284 }
285
286 // 11. Save return value
287 FrameOffset return_save_location = main_jni_conv->ReturnValueSaveLocation();
288 if (main_jni_conv->SizeOfReturnValue() != 0 && !reference_return) {
289 if (instruction_set == kMips && main_jni_conv->GetReturnType() == Primitive::kPrimDouble &&
290 return_save_location.Uint32Value() % 8 != 0) {
291 // Ensure doubles are 8-byte aligned for MIPS
292 return_save_location = FrameOffset(return_save_location.Uint32Value() + kPointerSize);
293 }
294 CHECK_LT(return_save_location.Uint32Value(), frame_size+main_out_arg_size);
295 __ Store(return_save_location, main_jni_conv->ReturnRegister(), main_jni_conv->SizeOfReturnValue());
296 }
297
298 // 12. Call into JNI method end possibly passing a returned reference, the method and the current
299 // thread.
300 end_jni_conv->ResetIterator(FrameOffset(end_out_arg_size));
Ian Rogers848871b2013-08-05 10:56:33 -0700301 ThreadOffset jni_end(-1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302 if (reference_return) {
303 // Pass result.
Ian Rogers7655f292013-07-29 11:07:13 -0700304 jni_end = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(pJniMethodEndWithReferenceSynchronized)
305 : QUICK_ENTRYPOINT_OFFSET(pJniMethodEndWithReference);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700306 SetNativeParameter(jni_asm.get(), end_jni_conv.get(), end_jni_conv->ReturnRegister());
307 end_jni_conv->Next();
308 } else {
Ian Rogers7655f292013-07-29 11:07:13 -0700309 jni_end = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(pJniMethodEndSynchronized)
310 : QUICK_ENTRYPOINT_OFFSET(pJniMethodEnd);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700311 }
312 // Pass saved local reference state.
313 if (end_jni_conv->IsCurrentParamOnStack()) {
314 FrameOffset out_off = end_jni_conv->CurrentParamStackOffset();
315 __ Copy(out_off, saved_cookie_offset, end_jni_conv->InterproceduralScratchRegister(), 4);
316 } else {
317 ManagedRegister out_reg = end_jni_conv->CurrentParamRegister();
318 __ Load(out_reg, saved_cookie_offset, 4);
319 }
320 end_jni_conv->Next();
321 if (is_synchronized) {
322 // Pass object for unlocking.
323 if (end_jni_conv->IsCurrentParamOnStack()) {
324 FrameOffset out_off = end_jni_conv->CurrentParamStackOffset();
325 __ CreateSirtEntry(out_off, locked_object_sirt_offset,
326 end_jni_conv->InterproceduralScratchRegister(),
327 false);
328 } else {
329 ManagedRegister out_reg = end_jni_conv->CurrentParamRegister();
330 __ CreateSirtEntry(out_reg, locked_object_sirt_offset,
331 ManagedRegister::NoRegister(), false);
332 }
333 end_jni_conv->Next();
334 }
335 if (end_jni_conv->IsCurrentParamInRegister()) {
336 __ GetCurrentThread(end_jni_conv->CurrentParamRegister());
337 __ Call(end_jni_conv->CurrentParamRegister(), Offset(jni_end),
338 end_jni_conv->InterproceduralScratchRegister());
339 } else {
340 __ GetCurrentThread(end_jni_conv->CurrentParamStackOffset(),
341 end_jni_conv->InterproceduralScratchRegister());
342 __ Call(ThreadOffset(jni_end), end_jni_conv->InterproceduralScratchRegister());
343 }
344
345 // 13. Reload return value
346 if (main_jni_conv->SizeOfReturnValue() != 0 && !reference_return) {
347 __ Load(mr_conv->ReturnRegister(), return_save_location, mr_conv->SizeOfReturnValue());
348 }
349
350 // 14. Move frame up now we're done with the out arg space.
351 __ DecreaseFrameSize(max_out_arg_size);
352
353 // 15. Process pending exceptions from JNI call or monitor exit.
354 __ ExceptionPoll(main_jni_conv->InterproceduralScratchRegister(), 0);
355
Mathieu Chartier8770e5c2013-10-16 14:49:01 -0700356 // 16. Remove activation - need to restore callee save registers since the GC may have changed
Brian Carlstrom7940e442013-07-12 13:46:57 -0700357 // them.
Mathieu Chartier8770e5c2013-10-16 14:49:01 -0700358 __ RemoveFrame(frame_size, callee_save_regs);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700359
360 // 17. Finalize code generation
361 __ EmitSlowPaths();
362 size_t cs = __ CodeSize();
363 std::vector<uint8_t> managed_code(cs);
364 MemoryRegion code(&managed_code[0], managed_code.size());
365 __ FinalizeInstructions(code);
Mathieu Chartier193bad92013-08-29 18:46:00 -0700366 return new CompiledMethod(compiler,
367 instruction_set,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700368 managed_code,
369 frame_size,
370 main_jni_conv->CoreSpillMask(),
371 main_jni_conv->FpSpillMask());
372}
373
374// Copy a single parameter from the managed to the JNI calling convention
375static void CopyParameter(Assembler* jni_asm,
376 ManagedRuntimeCallingConvention* mr_conv,
377 JniCallingConvention* jni_conv,
378 size_t frame_size, size_t out_arg_size) {
379 bool input_in_reg = mr_conv->IsCurrentParamInRegister();
380 bool output_in_reg = jni_conv->IsCurrentParamInRegister();
381 FrameOffset sirt_offset(0);
382 bool null_allowed = false;
383 bool ref_param = jni_conv->IsCurrentParamAReference();
384 CHECK(!ref_param || mr_conv->IsCurrentParamAReference());
385 // input may be in register, on stack or both - but not none!
386 CHECK(input_in_reg || mr_conv->IsCurrentParamOnStack());
387 if (output_in_reg) { // output shouldn't straddle registers and stack
388 CHECK(!jni_conv->IsCurrentParamOnStack());
389 } else {
390 CHECK(jni_conv->IsCurrentParamOnStack());
391 }
392 // References need placing in SIRT and the entry address passing
393 if (ref_param) {
394 null_allowed = mr_conv->IsCurrentArgPossiblyNull();
395 // Compute SIRT offset. Note null is placed in the SIRT but the jobject
396 // passed to the native code must be null (not a pointer into the SIRT
397 // as with regular references).
398 sirt_offset = jni_conv->CurrentParamSirtEntryOffset();
399 // Check SIRT offset is within frame.
400 CHECK_LT(sirt_offset.Uint32Value(), (frame_size + out_arg_size));
401 }
402 if (input_in_reg && output_in_reg) {
403 ManagedRegister in_reg = mr_conv->CurrentParamRegister();
404 ManagedRegister out_reg = jni_conv->CurrentParamRegister();
405 if (ref_param) {
406 __ CreateSirtEntry(out_reg, sirt_offset, in_reg, null_allowed);
407 } else {
408 if (!mr_conv->IsCurrentParamOnStack()) {
409 // regular non-straddling move
410 __ Move(out_reg, in_reg, mr_conv->CurrentParamSize());
411 } else {
412 UNIMPLEMENTED(FATAL); // we currently don't expect to see this case
413 }
414 }
415 } else if (!input_in_reg && !output_in_reg) {
416 FrameOffset out_off = jni_conv->CurrentParamStackOffset();
417 if (ref_param) {
418 __ CreateSirtEntry(out_off, sirt_offset, mr_conv->InterproceduralScratchRegister(),
419 null_allowed);
420 } else {
421 FrameOffset in_off = mr_conv->CurrentParamStackOffset();
422 size_t param_size = mr_conv->CurrentParamSize();
423 CHECK_EQ(param_size, jni_conv->CurrentParamSize());
424 __ Copy(out_off, in_off, mr_conv->InterproceduralScratchRegister(), param_size);
425 }
426 } else if (!input_in_reg && output_in_reg) {
427 FrameOffset in_off = mr_conv->CurrentParamStackOffset();
428 ManagedRegister out_reg = jni_conv->CurrentParamRegister();
429 // Check that incoming stack arguments are above the current stack frame.
430 CHECK_GT(in_off.Uint32Value(), frame_size);
431 if (ref_param) {
432 __ CreateSirtEntry(out_reg, sirt_offset, ManagedRegister::NoRegister(), null_allowed);
433 } else {
434 size_t param_size = mr_conv->CurrentParamSize();
435 CHECK_EQ(param_size, jni_conv->CurrentParamSize());
436 __ Load(out_reg, in_off, param_size);
437 }
438 } else {
439 CHECK(input_in_reg && !output_in_reg);
440 ManagedRegister in_reg = mr_conv->CurrentParamRegister();
441 FrameOffset out_off = jni_conv->CurrentParamStackOffset();
442 // Check outgoing argument is within frame
443 CHECK_LT(out_off.Uint32Value(), frame_size);
444 if (ref_param) {
445 // TODO: recycle value in in_reg rather than reload from SIRT
446 __ CreateSirtEntry(out_off, sirt_offset, mr_conv->InterproceduralScratchRegister(),
447 null_allowed);
448 } else {
449 size_t param_size = mr_conv->CurrentParamSize();
450 CHECK_EQ(param_size, jni_conv->CurrentParamSize());
451 if (!mr_conv->IsCurrentParamOnStack()) {
452 // regular non-straddling store
453 __ Store(out_off, in_reg, param_size);
454 } else {
455 // store where input straddles registers and stack
456 CHECK_EQ(param_size, 8u);
457 FrameOffset in_off = mr_conv->CurrentParamStackOffset();
458 __ StoreSpanning(out_off, in_reg, in_off, mr_conv->InterproceduralScratchRegister());
459 }
460 }
461 }
462}
463
464static void SetNativeParameter(Assembler* jni_asm,
465 JniCallingConvention* jni_conv,
466 ManagedRegister in_reg) {
467 if (jni_conv->IsCurrentParamOnStack()) {
468 FrameOffset dest = jni_conv->CurrentParamStackOffset();
469 __ StoreRawPtr(dest, in_reg);
470 } else {
471 if (!jni_conv->CurrentParamRegister().Equals(in_reg)) {
472 __ Move(jni_conv->CurrentParamRegister(), in_reg, jni_conv->CurrentParamSize());
473 }
474 }
475}
476
477} // namespace art
478
479extern "C" art::CompiledMethod* ArtQuickJniCompileMethod(art::CompilerDriver& compiler,
480 uint32_t access_flags, uint32_t method_idx,
481 const art::DexFile& dex_file) {
482 return ArtJniCompileMethodInternal(compiler, access_flags, method_idx, dex_file);
483}