Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 17 | #include "jni_compiler.h" |
| 18 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | #include <algorithm> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 20 | #include <memory> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include <vector> |
Dave Allison | 65fcc2c | 2014-04-28 13:45:27 -0700 | [diff] [blame] | 22 | #include <fstream> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | |
| 24 | #include "base/logging.h" |
| 25 | #include "base/macros.h" |
| 26 | #include "calling_convention.h" |
| 27 | #include "class_linker.h" |
| 28 | #include "compiled_method.h" |
| 29 | #include "dex_file-inl.h" |
| 30 | #include "driver/compiler_driver.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 31 | #include "entrypoints/quick/quick_entrypoints.h" |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 32 | #include "jni_env_ext.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 33 | #include "mirror/art_method.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 34 | #include "utils/assembler.h" |
| 35 | #include "utils/managed_register.h" |
| 36 | #include "utils/arm/managed_register_arm.h" |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 37 | #include "utils/arm64/managed_register_arm64.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 38 | #include "utils/mips/managed_register_mips.h" |
| 39 | #include "utils/x86/managed_register_x86.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 40 | #include "thread.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 41 | |
| 42 | #define __ jni_asm-> |
| 43 | |
| 44 | namespace art { |
| 45 | |
| 46 | static void CopyParameter(Assembler* jni_asm, |
| 47 | ManagedRuntimeCallingConvention* mr_conv, |
| 48 | JniCallingConvention* jni_conv, |
| 49 | size_t frame_size, size_t out_arg_size); |
| 50 | static void SetNativeParameter(Assembler* jni_asm, |
| 51 | JniCallingConvention* jni_conv, |
| 52 | ManagedRegister in_reg); |
| 53 | |
| 54 | // Generate the JNI bridge for the given method, general contract: |
| 55 | // - Arguments are in the managed runtime format, either on stack or in |
| 56 | // registers, a reference to the method object is supplied as part of this |
| 57 | // convention. |
| 58 | // |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 59 | CompiledMethod* ArtJniCompileMethodInternal(CompilerDriver* driver, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 60 | uint32_t access_flags, uint32_t method_idx, |
| 61 | const DexFile& dex_file) { |
| 62 | const bool is_native = (access_flags & kAccNative) != 0; |
| 63 | CHECK(is_native); |
| 64 | const bool is_static = (access_flags & kAccStatic) != 0; |
| 65 | const bool is_synchronized = (access_flags & kAccSynchronized) != 0; |
| 66 | const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 67 | InstructionSet instruction_set = driver->GetInstructionSet(); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 68 | const bool is_64_bit_target = Is64BitInstructionSet(instruction_set); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 69 | // Calling conventions used to iterate over parameters to method |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 70 | std::unique_ptr<JniCallingConvention> main_jni_conv( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | JniCallingConvention::Create(is_static, is_synchronized, shorty, instruction_set)); |
| 72 | bool reference_return = main_jni_conv->IsReturnAReference(); |
| 73 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 74 | std::unique_ptr<ManagedRuntimeCallingConvention> mr_conv( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 75 | ManagedRuntimeCallingConvention::Create(is_static, is_synchronized, shorty, instruction_set)); |
| 76 | |
| 77 | // Calling conventions to call into JNI method "end" possibly passing a returned reference, the |
| 78 | // method and the current thread. |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 79 | const char* jni_end_shorty; |
| 80 | if (reference_return && is_synchronized) { |
| 81 | jni_end_shorty = "ILL"; |
| 82 | } else if (reference_return) { |
| 83 | jni_end_shorty = "IL"; |
| 84 | } else if (is_synchronized) { |
| 85 | jni_end_shorty = "VL"; |
| 86 | } else { |
| 87 | jni_end_shorty = "V"; |
| 88 | } |
| 89 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 90 | std::unique_ptr<JniCallingConvention> end_jni_conv( |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 91 | JniCallingConvention::Create(is_static, is_synchronized, jni_end_shorty, instruction_set)); |
| 92 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 93 | // Assembler that holds generated instructions |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 94 | std::unique_ptr<Assembler> jni_asm(Assembler::Create(instruction_set)); |
Tong Shen | 547cdfd | 2014-08-05 01:54:19 -0700 | [diff] [blame] | 95 | jni_asm->InitializeFrameDescriptionEntry(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 96 | |
| 97 | // Offsets into data structures |
| 98 | // TODO: if cross compiling these offsets are for the host not the target |
| 99 | const Offset functions(OFFSETOF_MEMBER(JNIEnvExt, functions)); |
| 100 | const Offset monitor_enter(OFFSETOF_MEMBER(JNINativeInterface, MonitorEnter)); |
| 101 | const Offset monitor_exit(OFFSETOF_MEMBER(JNINativeInterface, MonitorExit)); |
| 102 | |
| 103 | // 1. Build the frame saving all callee saves |
| 104 | const size_t frame_size(main_jni_conv->FrameSize()); |
| 105 | const std::vector<ManagedRegister>& callee_save_regs = main_jni_conv->CalleeSaveRegisters(); |
| 106 | __ BuildFrame(frame_size, mr_conv->MethodRegister(), callee_save_regs, mr_conv->EntrySpills()); |
| 107 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 108 | // 2. Set up the HandleScope |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 109 | mr_conv->ResetIterator(FrameOffset(frame_size)); |
| 110 | main_jni_conv->ResetIterator(FrameOffset(0)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 111 | __ StoreImmediateToFrame(main_jni_conv->HandleScopeNumRefsOffset(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 112 | main_jni_conv->ReferenceCount(), |
| 113 | mr_conv->InterproceduralScratchRegister()); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 114 | |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 115 | if (is_64_bit_target) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 116 | __ CopyRawPtrFromThread64(main_jni_conv->HandleScopeLinkOffset(), |
| 117 | Thread::TopHandleScopeOffset<8>(), |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 118 | mr_conv->InterproceduralScratchRegister()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 119 | __ StoreStackOffsetToThread64(Thread::TopHandleScopeOffset<8>(), |
| 120 | main_jni_conv->HandleScopeOffset(), |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 121 | mr_conv->InterproceduralScratchRegister()); |
| 122 | } else { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 123 | __ CopyRawPtrFromThread32(main_jni_conv->HandleScopeLinkOffset(), |
| 124 | Thread::TopHandleScopeOffset<4>(), |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 125 | mr_conv->InterproceduralScratchRegister()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 126 | __ StoreStackOffsetToThread32(Thread::TopHandleScopeOffset<4>(), |
| 127 | main_jni_conv->HandleScopeOffset(), |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 128 | mr_conv->InterproceduralScratchRegister()); |
| 129 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 130 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 131 | // 3. Place incoming reference arguments into handle scope |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 132 | main_jni_conv->Next(); // Skip JNIEnv* |
| 133 | // 3.5. Create Class argument for static methods out of passed method |
| 134 | if (is_static) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 135 | FrameOffset handle_scope_offset = main_jni_conv->CurrentParamHandleScopeEntryOffset(); |
| 136 | // Check handle scope offset is within frame |
| 137 | CHECK_LT(handle_scope_offset.Uint32Value(), frame_size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 138 | __ LoadRef(main_jni_conv->InterproceduralScratchRegister(), |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 139 | mr_conv->MethodRegister(), mirror::ArtMethod::DeclaringClassOffset()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 140 | __ VerifyObject(main_jni_conv->InterproceduralScratchRegister(), false); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 141 | __ StoreRef(handle_scope_offset, main_jni_conv->InterproceduralScratchRegister()); |
| 142 | main_jni_conv->Next(); // in handle scope so move to next argument |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 143 | } |
| 144 | while (mr_conv->HasNext()) { |
| 145 | CHECK(main_jni_conv->HasNext()); |
| 146 | bool ref_param = main_jni_conv->IsCurrentParamAReference(); |
| 147 | CHECK(!ref_param || mr_conv->IsCurrentParamAReference()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 148 | // References need placing in handle scope and the entry value passing |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 149 | if (ref_param) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 150 | // Compute handle scope entry, note null is placed in the handle scope but its boxed value |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 151 | // must be NULL |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 152 | FrameOffset handle_scope_offset = main_jni_conv->CurrentParamHandleScopeEntryOffset(); |
| 153 | // Check handle scope offset is within frame and doesn't run into the saved segment state |
| 154 | CHECK_LT(handle_scope_offset.Uint32Value(), frame_size); |
| 155 | CHECK_NE(handle_scope_offset.Uint32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 156 | main_jni_conv->SavedLocalReferenceCookieOffset().Uint32Value()); |
| 157 | bool input_in_reg = mr_conv->IsCurrentParamInRegister(); |
| 158 | bool input_on_stack = mr_conv->IsCurrentParamOnStack(); |
| 159 | CHECK(input_in_reg || input_on_stack); |
| 160 | |
| 161 | if (input_in_reg) { |
| 162 | ManagedRegister in_reg = mr_conv->CurrentParamRegister(); |
| 163 | __ VerifyObject(in_reg, mr_conv->IsCurrentArgPossiblyNull()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 164 | __ StoreRef(handle_scope_offset, in_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 165 | } else if (input_on_stack) { |
| 166 | FrameOffset in_off = mr_conv->CurrentParamStackOffset(); |
| 167 | __ VerifyObject(in_off, mr_conv->IsCurrentArgPossiblyNull()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 168 | __ CopyRef(handle_scope_offset, in_off, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 169 | mr_conv->InterproceduralScratchRegister()); |
| 170 | } |
| 171 | } |
| 172 | mr_conv->Next(); |
| 173 | main_jni_conv->Next(); |
| 174 | } |
| 175 | |
| 176 | // 4. Write out the end of the quick frames. |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 177 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 178 | __ StoreStackPointerToThread64(Thread::TopOfManagedStackOffset<8>()); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 179 | } else { |
| 180 | __ StoreStackPointerToThread32(Thread::TopOfManagedStackOffset<4>()); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 181 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 182 | |
| 183 | // 5. Move frame down to allow space for out going args. |
| 184 | const size_t main_out_arg_size = main_jni_conv->OutArgSize(); |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 185 | size_t current_out_arg_size = main_out_arg_size; |
| 186 | __ IncreaseFrameSize(main_out_arg_size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 187 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 188 | // 6. Call into appropriate JniMethodStart passing Thread* so that transition out of Runnable |
| 189 | // can occur. The result is the saved JNI local state that is restored by the exit call. We |
| 190 | // abuse the JNI calling convention here, that is guaranteed to support passing 2 pointer |
| 191 | // arguments. |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 192 | ThreadOffset<4> jni_start32 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(4, pJniMethodStartSynchronized) |
| 193 | : QUICK_ENTRYPOINT_OFFSET(4, pJniMethodStart); |
| 194 | ThreadOffset<8> jni_start64 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(8, pJniMethodStartSynchronized) |
| 195 | : QUICK_ENTRYPOINT_OFFSET(8, pJniMethodStart); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 196 | main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size)); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 197 | FrameOffset locked_object_handle_scope_offset(0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 198 | if (is_synchronized) { |
| 199 | // Pass object for locking. |
| 200 | main_jni_conv->Next(); // Skip JNIEnv. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 201 | locked_object_handle_scope_offset = main_jni_conv->CurrentParamHandleScopeEntryOffset(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 202 | main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size)); |
| 203 | if (main_jni_conv->IsCurrentParamOnStack()) { |
| 204 | FrameOffset out_off = main_jni_conv->CurrentParamStackOffset(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 205 | __ CreateHandleScopeEntry(out_off, locked_object_handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 206 | mr_conv->InterproceduralScratchRegister(), |
| 207 | false); |
| 208 | } else { |
| 209 | ManagedRegister out_reg = main_jni_conv->CurrentParamRegister(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 210 | __ CreateHandleScopeEntry(out_reg, locked_object_handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 211 | ManagedRegister::NoRegister(), false); |
| 212 | } |
| 213 | main_jni_conv->Next(); |
| 214 | } |
| 215 | if (main_jni_conv->IsCurrentParamInRegister()) { |
| 216 | __ GetCurrentThread(main_jni_conv->CurrentParamRegister()); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 217 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 218 | __ Call(main_jni_conv->CurrentParamRegister(), Offset(jni_start64), |
| 219 | main_jni_conv->InterproceduralScratchRegister()); |
| 220 | } else { |
| 221 | __ Call(main_jni_conv->CurrentParamRegister(), Offset(jni_start32), |
| 222 | main_jni_conv->InterproceduralScratchRegister()); |
| 223 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 224 | } else { |
| 225 | __ GetCurrentThread(main_jni_conv->CurrentParamStackOffset(), |
| 226 | main_jni_conv->InterproceduralScratchRegister()); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 227 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 228 | __ CallFromThread64(jni_start64, main_jni_conv->InterproceduralScratchRegister()); |
| 229 | } else { |
| 230 | __ CallFromThread32(jni_start32, main_jni_conv->InterproceduralScratchRegister()); |
| 231 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 232 | } |
| 233 | if (is_synchronized) { // Check for exceptions from monitor enter. |
| 234 | __ ExceptionPoll(main_jni_conv->InterproceduralScratchRegister(), main_out_arg_size); |
| 235 | } |
| 236 | FrameOffset saved_cookie_offset = main_jni_conv->SavedLocalReferenceCookieOffset(); |
| 237 | __ Store(saved_cookie_offset, main_jni_conv->IntReturnRegister(), 4); |
| 238 | |
| 239 | // 7. Iterate over arguments placing values from managed calling convention in |
| 240 | // to the convention required for a native call (shuffling). For references |
| 241 | // place an index/pointer to the reference after checking whether it is |
| 242 | // NULL (which must be encoded as NULL). |
| 243 | // Note: we do this prior to materializing the JNIEnv* and static's jclass to |
| 244 | // give as many free registers for the shuffle as possible |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 245 | mr_conv->ResetIterator(FrameOffset(frame_size + main_out_arg_size)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 246 | uint32_t args_count = 0; |
| 247 | while (mr_conv->HasNext()) { |
| 248 | args_count++; |
| 249 | mr_conv->Next(); |
| 250 | } |
| 251 | |
| 252 | // Do a backward pass over arguments, so that the generated code will be "mov |
| 253 | // R2, R3; mov R1, R2" instead of "mov R1, R2; mov R2, R3." |
| 254 | // TODO: A reverse iterator to improve readability. |
| 255 | for (uint32_t i = 0; i < args_count; ++i) { |
| 256 | mr_conv->ResetIterator(FrameOffset(frame_size + main_out_arg_size)); |
| 257 | main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size)); |
| 258 | main_jni_conv->Next(); // Skip JNIEnv*. |
| 259 | if (is_static) { |
| 260 | main_jni_conv->Next(); // Skip Class for now. |
| 261 | } |
| 262 | // Skip to the argument we're interested in. |
| 263 | for (uint32_t j = 0; j < args_count - i - 1; ++j) { |
| 264 | mr_conv->Next(); |
| 265 | main_jni_conv->Next(); |
| 266 | } |
| 267 | CopyParameter(jni_asm.get(), mr_conv.get(), main_jni_conv.get(), frame_size, main_out_arg_size); |
| 268 | } |
| 269 | if (is_static) { |
| 270 | // Create argument for Class |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 271 | mr_conv->ResetIterator(FrameOffset(frame_size + main_out_arg_size)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 272 | main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size)); |
| 273 | main_jni_conv->Next(); // Skip JNIEnv* |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 274 | FrameOffset handle_scope_offset = main_jni_conv->CurrentParamHandleScopeEntryOffset(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 275 | if (main_jni_conv->IsCurrentParamOnStack()) { |
| 276 | FrameOffset out_off = main_jni_conv->CurrentParamStackOffset(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 277 | __ CreateHandleScopeEntry(out_off, handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 278 | mr_conv->InterproceduralScratchRegister(), |
| 279 | false); |
| 280 | } else { |
| 281 | ManagedRegister out_reg = main_jni_conv->CurrentParamRegister(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 282 | __ CreateHandleScopeEntry(out_reg, handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 283 | ManagedRegister::NoRegister(), false); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | // 8. Create 1st argument, the JNI environment ptr. |
| 288 | main_jni_conv->ResetIterator(FrameOffset(main_out_arg_size)); |
| 289 | // Register that will hold local indirect reference table |
| 290 | if (main_jni_conv->IsCurrentParamInRegister()) { |
| 291 | ManagedRegister jni_env = main_jni_conv->CurrentParamRegister(); |
| 292 | DCHECK(!jni_env.Equals(main_jni_conv->InterproceduralScratchRegister())); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 293 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 294 | __ LoadRawPtrFromThread64(jni_env, Thread::JniEnvOffset<8>()); |
| 295 | } else { |
| 296 | __ LoadRawPtrFromThread32(jni_env, Thread::JniEnvOffset<4>()); |
| 297 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 298 | } else { |
| 299 | FrameOffset jni_env = main_jni_conv->CurrentParamStackOffset(); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 300 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 301 | __ CopyRawPtrFromThread64(jni_env, Thread::JniEnvOffset<8>(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 302 | main_jni_conv->InterproceduralScratchRegister()); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 303 | } else { |
| 304 | __ CopyRawPtrFromThread32(jni_env, Thread::JniEnvOffset<4>(), |
| 305 | main_jni_conv->InterproceduralScratchRegister()); |
| 306 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // 9. Plant call to native code associated with method. |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 310 | MemberOffset jni_entrypoint_offset = mirror::ArtMethod::EntryPointFromJniOffset( |
| 311 | InstructionSetPointerSize(instruction_set)); |
| 312 | __ Call(main_jni_conv->MethodStackOffset(), jni_entrypoint_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 313 | mr_conv->InterproceduralScratchRegister()); |
| 314 | |
| 315 | // 10. Fix differences in result widths. |
Andreas Gampe | d110432 | 2014-05-01 14:38:56 -0700 | [diff] [blame] | 316 | if (main_jni_conv->RequiresSmallResultTypeExtension()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 317 | if (main_jni_conv->GetReturnType() == Primitive::kPrimByte || |
| 318 | main_jni_conv->GetReturnType() == Primitive::kPrimShort) { |
| 319 | __ SignExtend(main_jni_conv->ReturnRegister(), |
| 320 | Primitive::ComponentSize(main_jni_conv->GetReturnType())); |
| 321 | } else if (main_jni_conv->GetReturnType() == Primitive::kPrimBoolean || |
| 322 | main_jni_conv->GetReturnType() == Primitive::kPrimChar) { |
| 323 | __ ZeroExtend(main_jni_conv->ReturnRegister(), |
| 324 | Primitive::ComponentSize(main_jni_conv->GetReturnType())); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // 11. Save return value |
| 329 | FrameOffset return_save_location = main_jni_conv->ReturnValueSaveLocation(); |
| 330 | if (main_jni_conv->SizeOfReturnValue() != 0 && !reference_return) { |
| 331 | if (instruction_set == kMips && main_jni_conv->GetReturnType() == Primitive::kPrimDouble && |
| 332 | return_save_location.Uint32Value() % 8 != 0) { |
| 333 | // Ensure doubles are 8-byte aligned for MIPS |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 334 | return_save_location = FrameOffset(return_save_location.Uint32Value() + kMipsPointerSize); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 335 | } |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 336 | CHECK_LT(return_save_location.Uint32Value(), frame_size + main_out_arg_size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 337 | __ Store(return_save_location, main_jni_conv->ReturnRegister(), main_jni_conv->SizeOfReturnValue()); |
| 338 | } |
| 339 | |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 340 | // Increase frame size for out args if needed by the end_jni_conv. |
| 341 | const size_t end_out_arg_size = end_jni_conv->OutArgSize(); |
| 342 | if (end_out_arg_size > current_out_arg_size) { |
| 343 | size_t out_arg_size_diff = end_out_arg_size - current_out_arg_size; |
| 344 | current_out_arg_size = end_out_arg_size; |
| 345 | __ IncreaseFrameSize(out_arg_size_diff); |
| 346 | saved_cookie_offset = FrameOffset(saved_cookie_offset.SizeValue() + out_arg_size_diff); |
| 347 | locked_object_handle_scope_offset = |
| 348 | FrameOffset(locked_object_handle_scope_offset.SizeValue() + out_arg_size_diff); |
| 349 | return_save_location = FrameOffset(return_save_location.SizeValue() + out_arg_size_diff); |
| 350 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 351 | // thread. |
| 352 | end_jni_conv->ResetIterator(FrameOffset(end_out_arg_size)); |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 353 | ThreadOffset<4> jni_end32(-1); |
| 354 | ThreadOffset<8> jni_end64(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 355 | if (reference_return) { |
| 356 | // Pass result. |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 357 | jni_end32 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(4, pJniMethodEndWithReferenceSynchronized) |
| 358 | : QUICK_ENTRYPOINT_OFFSET(4, pJniMethodEndWithReference); |
| 359 | jni_end64 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(8, pJniMethodEndWithReferenceSynchronized) |
| 360 | : QUICK_ENTRYPOINT_OFFSET(8, pJniMethodEndWithReference); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 361 | SetNativeParameter(jni_asm.get(), end_jni_conv.get(), end_jni_conv->ReturnRegister()); |
| 362 | end_jni_conv->Next(); |
| 363 | } else { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 364 | jni_end32 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(4, pJniMethodEndSynchronized) |
| 365 | : QUICK_ENTRYPOINT_OFFSET(4, pJniMethodEnd); |
| 366 | jni_end64 = is_synchronized ? QUICK_ENTRYPOINT_OFFSET(8, pJniMethodEndSynchronized) |
| 367 | : QUICK_ENTRYPOINT_OFFSET(8, pJniMethodEnd); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 368 | } |
| 369 | // Pass saved local reference state. |
| 370 | if (end_jni_conv->IsCurrentParamOnStack()) { |
| 371 | FrameOffset out_off = end_jni_conv->CurrentParamStackOffset(); |
| 372 | __ Copy(out_off, saved_cookie_offset, end_jni_conv->InterproceduralScratchRegister(), 4); |
| 373 | } else { |
| 374 | ManagedRegister out_reg = end_jni_conv->CurrentParamRegister(); |
| 375 | __ Load(out_reg, saved_cookie_offset, 4); |
| 376 | } |
| 377 | end_jni_conv->Next(); |
| 378 | if (is_synchronized) { |
| 379 | // Pass object for unlocking. |
| 380 | if (end_jni_conv->IsCurrentParamOnStack()) { |
| 381 | FrameOffset out_off = end_jni_conv->CurrentParamStackOffset(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 382 | __ CreateHandleScopeEntry(out_off, locked_object_handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 383 | end_jni_conv->InterproceduralScratchRegister(), |
| 384 | false); |
| 385 | } else { |
| 386 | ManagedRegister out_reg = end_jni_conv->CurrentParamRegister(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 387 | __ CreateHandleScopeEntry(out_reg, locked_object_handle_scope_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 388 | ManagedRegister::NoRegister(), false); |
| 389 | } |
| 390 | end_jni_conv->Next(); |
| 391 | } |
| 392 | if (end_jni_conv->IsCurrentParamInRegister()) { |
| 393 | __ GetCurrentThread(end_jni_conv->CurrentParamRegister()); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 394 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 395 | __ Call(end_jni_conv->CurrentParamRegister(), Offset(jni_end64), |
| 396 | end_jni_conv->InterproceduralScratchRegister()); |
| 397 | } else { |
| 398 | __ Call(end_jni_conv->CurrentParamRegister(), Offset(jni_end32), |
| 399 | end_jni_conv->InterproceduralScratchRegister()); |
| 400 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 401 | } else { |
| 402 | __ GetCurrentThread(end_jni_conv->CurrentParamStackOffset(), |
| 403 | end_jni_conv->InterproceduralScratchRegister()); |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 404 | if (is_64_bit_target) { |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 405 | __ CallFromThread64(ThreadOffset<8>(jni_end64), end_jni_conv->InterproceduralScratchRegister()); |
| 406 | } else { |
| 407 | __ CallFromThread32(ThreadOffset<4>(jni_end32), end_jni_conv->InterproceduralScratchRegister()); |
| 408 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | // 13. Reload return value |
| 412 | if (main_jni_conv->SizeOfReturnValue() != 0 && !reference_return) { |
| 413 | __ Load(mr_conv->ReturnRegister(), return_save_location, mr_conv->SizeOfReturnValue()); |
| 414 | } |
| 415 | |
| 416 | // 14. Move frame up now we're done with the out arg space. |
Vladimir Marko | 4e24b9d | 2014-07-24 17:01:58 +0100 | [diff] [blame] | 417 | __ DecreaseFrameSize(current_out_arg_size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 418 | |
| 419 | // 15. Process pending exceptions from JNI call or monitor exit. |
| 420 | __ ExceptionPoll(main_jni_conv->InterproceduralScratchRegister(), 0); |
| 421 | |
Mathieu Chartier | 8770e5c | 2013-10-16 14:49:01 -0700 | [diff] [blame] | 422 | // 16. Remove activation - need to restore callee save registers since the GC may have changed |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 423 | // them. |
Mathieu Chartier | 8770e5c | 2013-10-16 14:49:01 -0700 | [diff] [blame] | 424 | __ RemoveFrame(frame_size, callee_save_regs); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 425 | |
| 426 | // 17. Finalize code generation |
| 427 | __ EmitSlowPaths(); |
| 428 | size_t cs = __ CodeSize(); |
| 429 | std::vector<uint8_t> managed_code(cs); |
| 430 | MemoryRegion code(&managed_code[0], managed_code.size()); |
| 431 | __ FinalizeInstructions(code); |
Tong Shen | 547cdfd | 2014-08-05 01:54:19 -0700 | [diff] [blame] | 432 | jni_asm->FinalizeFrameDescriptionEntry(); |
Andreas Gampe | e21dc3d | 2014-12-08 16:59:43 -0800 | [diff] [blame] | 433 | std::vector<uint8_t>* fde(jni_asm->GetFrameDescriptionEntry()); |
| 434 | ArrayRef<const uint8_t> cfi_ref; |
| 435 | if (fde != nullptr) { |
| 436 | cfi_ref = ArrayRef<const uint8_t>(*fde); |
| 437 | } |
| 438 | return CompiledMethod::SwapAllocCompiledMethodCFI(driver, |
| 439 | instruction_set, |
| 440 | ArrayRef<const uint8_t>(managed_code), |
| 441 | frame_size, |
| 442 | main_jni_conv->CoreSpillMask(), |
| 443 | main_jni_conv->FpSpillMask(), |
| 444 | cfi_ref); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // Copy a single parameter from the managed to the JNI calling convention |
| 448 | static void CopyParameter(Assembler* jni_asm, |
| 449 | ManagedRuntimeCallingConvention* mr_conv, |
| 450 | JniCallingConvention* jni_conv, |
| 451 | size_t frame_size, size_t out_arg_size) { |
| 452 | bool input_in_reg = mr_conv->IsCurrentParamInRegister(); |
| 453 | bool output_in_reg = jni_conv->IsCurrentParamInRegister(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 454 | FrameOffset handle_scope_offset(0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 455 | bool null_allowed = false; |
| 456 | bool ref_param = jni_conv->IsCurrentParamAReference(); |
| 457 | CHECK(!ref_param || mr_conv->IsCurrentParamAReference()); |
| 458 | // input may be in register, on stack or both - but not none! |
| 459 | CHECK(input_in_reg || mr_conv->IsCurrentParamOnStack()); |
| 460 | if (output_in_reg) { // output shouldn't straddle registers and stack |
| 461 | CHECK(!jni_conv->IsCurrentParamOnStack()); |
| 462 | } else { |
| 463 | CHECK(jni_conv->IsCurrentParamOnStack()); |
| 464 | } |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 465 | // References need placing in handle scope and the entry address passing |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 466 | if (ref_param) { |
| 467 | null_allowed = mr_conv->IsCurrentArgPossiblyNull(); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 468 | // Compute handle scope offset. Note null is placed in the handle scope but the jobject |
| 469 | // passed to the native code must be null (not a pointer into the handle scope |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 470 | // as with regular references). |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 471 | handle_scope_offset = jni_conv->CurrentParamHandleScopeEntryOffset(); |
| 472 | // Check handle scope offset is within frame. |
| 473 | CHECK_LT(handle_scope_offset.Uint32Value(), (frame_size + out_arg_size)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 474 | } |
| 475 | if (input_in_reg && output_in_reg) { |
| 476 | ManagedRegister in_reg = mr_conv->CurrentParamRegister(); |
| 477 | ManagedRegister out_reg = jni_conv->CurrentParamRegister(); |
| 478 | if (ref_param) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 479 | __ CreateHandleScopeEntry(out_reg, handle_scope_offset, in_reg, null_allowed); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 480 | } else { |
| 481 | if (!mr_conv->IsCurrentParamOnStack()) { |
| 482 | // regular non-straddling move |
| 483 | __ Move(out_reg, in_reg, mr_conv->CurrentParamSize()); |
| 484 | } else { |
| 485 | UNIMPLEMENTED(FATAL); // we currently don't expect to see this case |
| 486 | } |
| 487 | } |
| 488 | } else if (!input_in_reg && !output_in_reg) { |
| 489 | FrameOffset out_off = jni_conv->CurrentParamStackOffset(); |
| 490 | if (ref_param) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 491 | __ CreateHandleScopeEntry(out_off, handle_scope_offset, mr_conv->InterproceduralScratchRegister(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 492 | null_allowed); |
| 493 | } else { |
| 494 | FrameOffset in_off = mr_conv->CurrentParamStackOffset(); |
| 495 | size_t param_size = mr_conv->CurrentParamSize(); |
| 496 | CHECK_EQ(param_size, jni_conv->CurrentParamSize()); |
| 497 | __ Copy(out_off, in_off, mr_conv->InterproceduralScratchRegister(), param_size); |
| 498 | } |
| 499 | } else if (!input_in_reg && output_in_reg) { |
| 500 | FrameOffset in_off = mr_conv->CurrentParamStackOffset(); |
| 501 | ManagedRegister out_reg = jni_conv->CurrentParamRegister(); |
| 502 | // Check that incoming stack arguments are above the current stack frame. |
| 503 | CHECK_GT(in_off.Uint32Value(), frame_size); |
| 504 | if (ref_param) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 505 | __ CreateHandleScopeEntry(out_reg, handle_scope_offset, ManagedRegister::NoRegister(), null_allowed); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 506 | } else { |
| 507 | size_t param_size = mr_conv->CurrentParamSize(); |
| 508 | CHECK_EQ(param_size, jni_conv->CurrentParamSize()); |
| 509 | __ Load(out_reg, in_off, param_size); |
| 510 | } |
| 511 | } else { |
| 512 | CHECK(input_in_reg && !output_in_reg); |
| 513 | ManagedRegister in_reg = mr_conv->CurrentParamRegister(); |
| 514 | FrameOffset out_off = jni_conv->CurrentParamStackOffset(); |
| 515 | // Check outgoing argument is within frame |
| 516 | CHECK_LT(out_off.Uint32Value(), frame_size); |
| 517 | if (ref_param) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 518 | // TODO: recycle value in in_reg rather than reload from handle scope |
| 519 | __ CreateHandleScopeEntry(out_off, handle_scope_offset, mr_conv->InterproceduralScratchRegister(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 520 | null_allowed); |
| 521 | } else { |
| 522 | size_t param_size = mr_conv->CurrentParamSize(); |
| 523 | CHECK_EQ(param_size, jni_conv->CurrentParamSize()); |
| 524 | if (!mr_conv->IsCurrentParamOnStack()) { |
| 525 | // regular non-straddling store |
| 526 | __ Store(out_off, in_reg, param_size); |
| 527 | } else { |
| 528 | // store where input straddles registers and stack |
| 529 | CHECK_EQ(param_size, 8u); |
| 530 | FrameOffset in_off = mr_conv->CurrentParamStackOffset(); |
| 531 | __ StoreSpanning(out_off, in_reg, in_off, mr_conv->InterproceduralScratchRegister()); |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | static void SetNativeParameter(Assembler* jni_asm, |
| 538 | JniCallingConvention* jni_conv, |
| 539 | ManagedRegister in_reg) { |
| 540 | if (jni_conv->IsCurrentParamOnStack()) { |
| 541 | FrameOffset dest = jni_conv->CurrentParamStackOffset(); |
| 542 | __ StoreRawPtr(dest, in_reg); |
| 543 | } else { |
| 544 | if (!jni_conv->CurrentParamRegister().Equals(in_reg)) { |
| 545 | __ Move(jni_conv->CurrentParamRegister(), in_reg, jni_conv->CurrentParamSize()); |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 550 | CompiledMethod* ArtQuickJniCompileMethod(CompilerDriver* compiler, uint32_t access_flags, |
| 551 | uint32_t method_idx, const DexFile& dex_file) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 552 | return ArtJniCompileMethodInternal(compiler, access_flags, method_idx, dex_file); |
| 553 | } |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 554 | |
| 555 | } // namespace art |