Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef ART_RUNTIME_METHOD_HANDLES_H_ |
| 18 | #define ART_RUNTIME_METHOD_HANDLES_H_ |
| 19 | |
| 20 | #include <ostream> |
| 21 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame^] | 22 | #include "dex_instruction.h" |
| 23 | #include "jvalue.h" |
| 24 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 25 | namespace art { |
| 26 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame^] | 27 | namespace mirror { |
| 28 | class MethodType; |
| 29 | } |
| 30 | |
| 31 | class ShadowFrame; |
| 32 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 33 | // Defines the behaviour of a given method handle. The behaviour |
| 34 | // of a handle of a given kind is identical to the dex bytecode behaviour |
| 35 | // of the equivalent instruction. |
| 36 | // |
| 37 | // NOTE: These must be kept in sync with the constants defined in |
| 38 | // java.lang.invoke.MethodHandle. |
| 39 | enum MethodHandleKind { |
| 40 | kInvokeVirtual = 0, |
| 41 | kInvokeSuper, |
| 42 | kInvokeDirect, |
| 43 | kInvokeStatic, |
| 44 | kInvokeInterface, |
| 45 | kInstanceGet, |
| 46 | kInstancePut, |
| 47 | kStaticGet, |
| 48 | kStaticPut, |
| 49 | kLastValidKind = kStaticPut, |
| 50 | kLastInvokeKind = kInvokeInterface |
| 51 | }; |
| 52 | |
| 53 | // Whether the given method handle kind is some variant of an invoke. |
| 54 | inline bool IsInvoke(const MethodHandleKind handle_kind) { |
| 55 | return handle_kind <= kLastInvokeKind; |
| 56 | } |
| 57 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame^] | 58 | // Perform argument conversions between |callsite_type| (the type of the |
| 59 | // incoming arguments) and |callee_type| (the type of the method being |
| 60 | // invoked). These include widening and narrowing conversions as well as |
| 61 | // boxing and unboxing. Returns true on success, on false on failure. A |
| 62 | // pending exception will always be set on failure. |
| 63 | template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_) |
| 64 | bool PerformArgumentConversions(Thread* self, |
| 65 | Handle<mirror::MethodType> callsite_type, |
| 66 | Handle<mirror::MethodType> callee_type, |
| 67 | const ShadowFrame& caller_frame, |
| 68 | uint32_t first_src_reg, |
| 69 | uint32_t first_dest_reg, |
| 70 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 71 | ShadowFrame* callee_frame, |
| 72 | JValue* result); |
| 73 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 74 | } // namespace art |
| 75 | |
| 76 | #endif // ART_RUNTIME_METHOD_HANDLES_H_ |