blob: 5175dceed36cd6fa95ed1f53e9e9ec8ae7f24ad3 [file] [log] [blame]
Narayan Kamath9823e782016-08-03 12:46:58 +01001/*
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 Kamath208f8572016-08-03 12:46:58 +010022#include "dex_instruction.h"
23#include "jvalue.h"
24
Narayan Kamath9823e782016-08-03 12:46:58 +010025namespace art {
26
Narayan Kamath208f8572016-08-03 12:46:58 +010027namespace mirror {
28 class MethodType;
29}
30
31class ShadowFrame;
32
Narayan Kamath9823e782016-08-03 12:46:58 +010033// 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.
39enum MethodHandleKind {
40 kInvokeVirtual = 0,
41 kInvokeSuper,
42 kInvokeDirect,
43 kInvokeStatic,
44 kInvokeInterface,
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010045 kInvokeTransform,
Narayan Kamath9823e782016-08-03 12:46:58 +010046 kInstanceGet,
47 kInstancePut,
48 kStaticGet,
49 kStaticPut,
50 kLastValidKind = kStaticPut,
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010051 kLastInvokeKind = kInvokeTransform
Narayan Kamath9823e782016-08-03 12:46:58 +010052};
53
54// Whether the given method handle kind is some variant of an invoke.
55inline bool IsInvoke(const MethodHandleKind handle_kind) {
56 return handle_kind <= kLastInvokeKind;
57}
58
Narayan Kamathda246502016-10-20 18:39:22 +010059// Performs a single argument conversion from type |from| to a distinct
60// type |to|. Returns true on success, false otherwise.
61REQUIRES_SHARED(Locks::mutator_lock_)
62bool ConvertJValue(Handle<mirror::Class> from,
63 Handle<mirror::Class> to,
64 const JValue& from_value,
65 JValue* to_value) ALWAYS_INLINE;
66
Narayan Kamath208f8572016-08-03 12:46:58 +010067// 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.
72template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_)
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010073bool 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|.
84template <bool is_range> REQUIRES_SHARED(Locks::mutator_lock_)
85bool 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 Kamath208f8572016-08-03 12:46:58 +010091
Narayan Kamath9823e782016-08-03 12:46:58 +010092} // namespace art
93
94#endif // ART_RUNTIME_METHOD_HANDLES_H_