blob: 296c163ef775ca729ea238138da26b2e606c7816 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_IFTABLE_H_
18#define ART_RUNTIME_MIRROR_IFTABLE_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "base/casts.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "object_array.h"
22
23namespace art {
24namespace mirror {
25
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026class MANAGED IfTable FINAL : public ObjectArray<Object> {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027 public:
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070028 ALWAYS_INLINE Class* GetInterface(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070029 Class* interface = GetWithoutChecks((i * kMax) + kInterface)->AsClass();
Mathieu Chartier2cebb242015-04-21 16:50:40 -070030 DCHECK(interface != nullptr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031 return interface;
32 }
33
Mathieu Chartier31e88222016-10-14 18:43:19 -070034 ALWAYS_INLINE void SetInterface(int32_t i, ObjPtr<Class> interface)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070035 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036
Mathieu Chartierfbc31082016-01-24 11:59:56 -080037 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
38 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070039 PointerArray* GetMethodArray(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierfbc31082016-01-24 11:59:56 -080040 auto* method_array = down_cast<PointerArray*>(Get<kVerifyFlags, kReadBarrierOption>(
41 (i * kMax) + kMethodArray));
Mathieu Chartier2cebb242015-04-21 16:50:40 -070042 DCHECK(method_array != nullptr);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043 return method_array;
44 }
45
Mathieu Chartierdfe02f62016-02-01 20:15:11 -080046 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
47 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070048 size_t GetMethodArrayCount(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartierdfe02f62016-02-01 20:15:11 -080049 auto* method_array = down_cast<PointerArray*>(
50 Get<kVerifyFlags, kReadBarrierOption>((i * kMax) + kMethodArray));
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 return method_array == nullptr ? 0u : method_array->GetLength();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 }
53
Mathieu Chartier31e88222016-10-14 18:43:19 -070054 void SetMethodArray(int32_t i, ObjPtr<PointerArray> arr) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070056 size_t Count() REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 return GetLength() / kMax;
58 }
59
60 enum {
61 // Points to the interface class.
62 kInterface = 0,
63 // Method pointers into the vtable, allow fast map from interface method index to concrete
64 // instance method.
65 kMethodArray = 1,
66 kMax = 2,
67 };
68
69 private:
70 DISALLOW_IMPLICIT_CONSTRUCTORS(IfTable);
71};
72
73} // namespace mirror
74} // namespace art
75
Brian Carlstromfc0e3212013-07-17 14:40:12 -070076#endif // ART_RUNTIME_MIRROR_IFTABLE_H_