Home | History | Annotate | Download | only in mirror
      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_MIRROR_CLASS_EXT_H_
     18 #define ART_RUNTIME_MIRROR_CLASS_EXT_H_
     19 
     20 #include "array.h"
     21 #include "class.h"
     22 #include "dex_cache.h"
     23 #include "gc_root.h"
     24 #include "object.h"
     25 #include "object_array.h"
     26 #include "string.h"
     27 
     28 namespace art {
     29 
     30 struct ClassExtOffsets;
     31 
     32 namespace mirror {
     33 
     34 // C++ mirror of dalvik.system.ClassExt
     35 class MANAGED ClassExt : public Object {
     36  public:
     37   static uint32_t ClassSize(PointerSize pointer_size);
     38 
     39   // Size of an instance of dalvik.system.ClassExt.
     40   static constexpr uint32_t InstanceSize() {
     41     return sizeof(ClassExt);
     42   }
     43 
     44   void SetVerifyError(ObjPtr<Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
     45 
     46   Object* GetVerifyError() REQUIRES_SHARED(Locks::mutator_lock_) {
     47     return GetFieldObject<ClassExt>(OFFSET_OF_OBJECT_MEMBER(ClassExt, verify_error_));
     48   }
     49 
     50   ObjectArray<DexCache>* GetObsoleteDexCaches() REQUIRES_SHARED(Locks::mutator_lock_) {
     51     return GetFieldObject<ObjectArray<DexCache>>(
     52         OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_dex_caches_));
     53   }
     54 
     55   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
     56            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
     57   inline PointerArray* GetObsoleteMethods() REQUIRES_SHARED(Locks::mutator_lock_) {
     58     return GetFieldObject<PointerArray, kVerifyFlags, kReadBarrierOption>(
     59         OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_methods_));
     60   }
     61 
     62   Object* GetOriginalDexFile() REQUIRES_SHARED(Locks::mutator_lock_) {
     63     return GetFieldObject<Object>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_));
     64   }
     65 
     66   void SetOriginalDexFile(ObjPtr<Object> bytes) REQUIRES_SHARED(Locks::mutator_lock_);
     67 
     68   void SetObsoleteArrays(ObjPtr<PointerArray> methods, ObjPtr<ObjectArray<DexCache>> dex_caches)
     69       REQUIRES_SHARED(Locks::mutator_lock_);
     70 
     71   // Extend the obsolete arrays by the given amount.
     72   bool ExtendObsoleteArrays(Thread* self, uint32_t increase)
     73       REQUIRES_SHARED(Locks::mutator_lock_);
     74 
     75   static void SetClass(ObjPtr<Class> dalvik_system_ClassExt);
     76   static void ResetClass();
     77   static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
     78 
     79   template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor>
     80   inline void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size)
     81       REQUIRES_SHARED(Locks::mutator_lock_);
     82 
     83   static ClassExt* Alloc(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
     84 
     85  private:
     86   // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
     87   HeapReference<ObjectArray<DexCache>> obsolete_dex_caches_;
     88 
     89   HeapReference<PointerArray> obsolete_methods_;
     90 
     91   HeapReference<Object> original_dex_file_;
     92 
     93   // The saved verification error of this class.
     94   HeapReference<Object> verify_error_;
     95 
     96   static GcRoot<Class> dalvik_system_ClassExt_;
     97 
     98   friend struct art::ClassExtOffsets;  // for verifying offset information
     99   DISALLOW_IMPLICIT_CONSTRUCTORS(ClassExt);
    100 };
    101 
    102 }  // namespace mirror
    103 }  // namespace art
    104 
    105 #endif  // ART_RUNTIME_MIRROR_CLASS_EXT_H_
    106