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, |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame^] | 45 | kInvokeTransform, |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 46 | kInstanceGet, |
| 47 | kInstancePut, |
| 48 | kStaticGet, |
| 49 | kStaticPut, |
| 50 | kLastValidKind = kStaticPut, |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame^] | 51 | kLastInvokeKind = kInvokeTransform |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | // Whether the given method handle kind is some variant of an invoke. |
| 55 | inline bool IsInvoke(const MethodHandleKind handle_kind) { |
| 56 | return handle_kind <= kLastInvokeKind; |
| 57 | } |
| 58 | |
Narayan Kamath | da24650 | 2016-10-20 18:39:22 +0100 | [diff] [blame] | 59 | // Performs a single argument conversion from type |from| to a distinct |
| 60 | // type |to|. Returns true on success, false otherwise. |
| 61 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 62 | bool ConvertJValue(Handle<mirror::Class> from, |
| 63 | Handle<mirror::Class> to, |
| 64 | const JValue& from_value, |
| 65 | JValue* to_value) ALWAYS_INLINE; |
| 66 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 67 | // Perform argument conversions between |callsite_type| (the type of the |
| 68 | // incoming arguments) and |callee_type| (the type of the method being |
| 69 | // invoked). These include widening and narrowing conversions as well as |
| 70 | // boxing and unboxing. Returns true on success, on false on failure. A |
| 71 | // pending exception will always be set on failure. |
| 72 | template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_) |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame^] | 73 | bool ConvertAndCopyArgumentsFromCallerFrame(Thread* self, |
| 74 | Handle<mirror::MethodType> callsite_type, |
| 75 | Handle<mirror::MethodType> callee_type, |
| 76 | const ShadowFrame& caller_frame, |
| 77 | uint32_t first_src_reg, |
| 78 | uint32_t first_dest_reg, |
| 79 | const uint32_t (&arg)[Instruction::kMaxVarArgRegs], |
| 80 | ShadowFrame* callee_frame); |
| 81 | |
| 82 | // Similar to |ConvertAndCopyArgumentsFromCallerFrame|, except that the |
| 83 | // arguments are copied from an |EmulatedStackFrame|. |
| 84 | template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_) |
| 85 | bool ConvertAndCopyArgumentsFromEmulatedStackFrame(Thread* self, |
| 86 | ObjPtr<mirror::Object> emulated_stack_frame, |
| 87 | Handle<mirror::MethodType> callee_type, |
| 88 | const uint32_t first_dest_reg, |
| 89 | ShadowFrame* callee_frame); |
| 90 | |
Narayan Kamath | 208f857 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 91 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 92 | } // namespace art |
| 93 | |
| 94 | #endif // ART_RUNTIME_METHOD_HANDLES_H_ |