blob: 5feb602a9e5b7cbf2e640ca5b5aaf42b4d117a9d [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:
Ian Rogersef7d42f2014-01-06 12:55:46 -080028 Class* GetInterface(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029 Class* interface = Get((i * kMax) + kInterface)->AsClass();
30 DCHECK(interface != NULL);
31 return interface;
32 }
33
34 void SetInterface(int32_t i, Class* interface) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
35
Ian Rogersef7d42f2014-01-06 12:55:46 -080036 ObjectArray<ArtMethod>* GetMethodArray(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070037 ObjectArray<ArtMethod>* method_array =
38 down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039 DCHECK(method_array != NULL);
40 return method_array;
41 }
42
Ian Rogersef7d42f2014-01-06 12:55:46 -080043 size_t GetMethodArrayCount(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070044 ObjectArray<ArtMethod>* method_array =
45 down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 if (method_array == NULL) {
47 return 0;
48 }
49 return method_array->GetLength();
50 }
51
Brian Carlstromea46f952013-07-30 01:26:50 -070052 void SetMethodArray(int32_t i, ObjectArray<ArtMethod>* new_ma)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
54 DCHECK(new_ma != NULL);
55 DCHECK(Get((i * kMax) + kMethodArray) == NULL);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010056 Set<false>((i * kMax) + kMethodArray, new_ma);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080057 }
58
Ian Rogersef7d42f2014-01-06 12:55:46 -080059 size_t Count() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060 return GetLength() / kMax;
61 }
62
63 enum {
64 // Points to the interface class.
65 kInterface = 0,
66 // Method pointers into the vtable, allow fast map from interface method index to concrete
67 // instance method.
68 kMethodArray = 1,
69 kMax = 2,
70 };
71
72 private:
73 DISALLOW_IMPLICIT_CONSTRUCTORS(IfTable);
74};
75
76} // namespace mirror
77} // namespace art
78
Brian Carlstromfc0e3212013-07-17 14:40:12 -070079#endif // ART_RUNTIME_MIRROR_IFTABLE_H_