• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef ART_RUNTIME_MIRROR_IFTABLE_H_
18 #define ART_RUNTIME_MIRROR_IFTABLE_H_
19 
20 #include "object_array.h"
21 
22 namespace art {
23 namespace mirror {
24 
25 class MANAGED IfTable : public ObjectArray<Object> {
26  public:
GetInterface(int32_t i)27   Class* GetInterface(int32_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
28     Class* interface = Get((i * kMax) + kInterface)->AsClass();
29     DCHECK(interface != NULL);
30     return interface;
31   }
32 
33   void SetInterface(int32_t i, Class* interface) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
34 
GetMethodArray(int32_t i)35   ObjectArray<ArtMethod>* GetMethodArray(int32_t i) const
36       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
37     ObjectArray<ArtMethod>* method_array =
38         down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
39     DCHECK(method_array != NULL);
40     return method_array;
41   }
42 
GetMethodArrayCount(int32_t i)43   size_t GetMethodArrayCount(int32_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
44     ObjectArray<ArtMethod>* method_array =
45         down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
46     if (method_array == NULL) {
47       return 0;
48     }
49     return method_array->GetLength();
50   }
51 
SetMethodArray(int32_t i,ObjectArray<ArtMethod> * new_ma)52   void SetMethodArray(int32_t i, ObjectArray<ArtMethod>* new_ma)
53       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
54     DCHECK(new_ma != NULL);
55     DCHECK(Get((i * kMax) + kMethodArray) == NULL);
56     Set((i * kMax) + kMethodArray, new_ma);
57   }
58 
Count()59   size_t Count() const {
60     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 
79 #endif  // ART_RUNTIME_MIRROR_IFTABLE_H_
80