blob: 126f94a61d514656b430cec82131dc2e8d0d7e89 [file] [log] [blame]
Alex Lightd6251582016-10-31 11:12:30 -07001/*
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
Alex Lighta01de592016-11-15 10:43:06 -080020#include "array.h"
Alex Light4f2e9572017-03-16 13:13:31 -070021#include "class.h"
Alex Lighta01de592016-11-15 10:43:06 -080022#include "dex_cache.h"
Alex Lightd6251582016-10-31 11:12:30 -070023#include "object.h"
Alex Lighta01de592016-11-15 10:43:06 -080024#include "object_array.h"
Alex Lightd6251582016-10-31 11:12:30 -070025#include "string.h"
26
27namespace art {
28
29struct ClassExtOffsets;
30
31namespace mirror {
32
33// C++ mirror of dalvik.system.ClassExt
34class MANAGED ClassExt : public Object {
35 public:
Alex Light4f2e9572017-03-16 13:13:31 -070036 static uint32_t ClassSize(PointerSize pointer_size);
Alex Lightd6251582016-10-31 11:12:30 -070037
38 // Size of an instance of dalvik.system.ClassExt.
39 static constexpr uint32_t InstanceSize() {
40 return sizeof(ClassExt);
41 }
42
43 void SetVerifyError(ObjPtr<Object> obj) REQUIRES_SHARED(Locks::mutator_lock_);
44
45 Object* GetVerifyError() REQUIRES_SHARED(Locks::mutator_lock_) {
46 return GetFieldObject<ClassExt>(OFFSET_OF_OBJECT_MEMBER(ClassExt, verify_error_));
47 }
48
Alex Lighta01de592016-11-15 10:43:06 -080049 ObjectArray<DexCache>* GetObsoleteDexCaches() REQUIRES_SHARED(Locks::mutator_lock_) {
50 return GetFieldObject<ObjectArray<DexCache>>(
51 OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_dex_caches_));
52 }
53
Alex Light4f2e9572017-03-16 13:13:31 -070054 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
55 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
56 inline PointerArray* GetObsoleteMethods() REQUIRES_SHARED(Locks::mutator_lock_) {
57 return GetFieldObject<PointerArray, kVerifyFlags, kReadBarrierOption>(
58 OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_methods_));
Alex Lighta01de592016-11-15 10:43:06 -080059 }
60
Alex Light2f814aa2017-03-24 15:21:34 +000061 Object* GetOriginalDexFile() REQUIRES_SHARED(Locks::mutator_lock_) {
62 return GetFieldObject<Object>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_));
Alex Lighta7e38d82017-01-19 14:57:28 -080063 }
64
Alex Light2f814aa2017-03-24 15:21:34 +000065 void SetOriginalDexFile(ObjPtr<Object> bytes) REQUIRES_SHARED(Locks::mutator_lock_);
Alex Lighta7e38d82017-01-19 14:57:28 -080066
David Brazdil1a658632018-12-01 17:54:26 +000067 uint16_t GetPreRedefineClassDefIndex() REQUIRES_SHARED(Locks::mutator_lock_) {
68 return static_cast<uint16_t>(
69 GetField32(OFFSET_OF_OBJECT_MEMBER(ClassExt, pre_redefine_class_def_index_)));
70 }
71
72 void SetPreRedefineClassDefIndex(uint16_t index) REQUIRES_SHARED(Locks::mutator_lock_);
73
74 const DexFile* GetPreRedefineDexFile() REQUIRES_SHARED(Locks::mutator_lock_) {
75 return reinterpret_cast<const DexFile*>(static_cast<uintptr_t>(
76 GetField64(OFFSET_OF_OBJECT_MEMBER(ClassExt, pre_redefine_dex_file_ptr_))));
77 }
78
79 void SetPreRedefineDexFile(const DexFile* dex_file) REQUIRES_SHARED(Locks::mutator_lock_);
80
Alex Lighta01de592016-11-15 10:43:06 -080081 void SetObsoleteArrays(ObjPtr<PointerArray> methods, ObjPtr<ObjectArray<DexCache>> dex_caches)
82 REQUIRES_SHARED(Locks::mutator_lock_);
83
84 // Extend the obsolete arrays by the given amount.
85 bool ExtendObsoleteArrays(Thread* self, uint32_t increase)
86 REQUIRES_SHARED(Locks::mutator_lock_);
87
Alex Light4f2e9572017-03-16 13:13:31 -070088 template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier, class Visitor>
89 inline void VisitNativeRoots(Visitor& visitor, PointerSize pointer_size)
90 REQUIRES_SHARED(Locks::mutator_lock_);
91
Alex Lightd6251582016-10-31 11:12:30 -070092 static ClassExt* Alloc(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
93
94 private:
95 // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
Alex Lighta01de592016-11-15 10:43:06 -080096 HeapReference<ObjectArray<DexCache>> obsolete_dex_caches_;
97
98 HeapReference<PointerArray> obsolete_methods_;
99
Alex Light2f814aa2017-03-24 15:21:34 +0000100 HeapReference<Object> original_dex_file_;
Alex Lighta01de592016-11-15 10:43:06 -0800101
102 // The saved verification error of this class.
Alex Lightd6251582016-10-31 11:12:30 -0700103 HeapReference<Object> verify_error_;
104
David Brazdil1a658632018-12-01 17:54:26 +0000105 // Native pointer to DexFile and ClassDef index of this class before it was JVMTI-redefined.
106 int64_t pre_redefine_dex_file_ptr_;
107 int32_t pre_redefine_class_def_index_;
108
Alex Lightd6251582016-10-31 11:12:30 -0700109 friend struct art::ClassExtOffsets; // for verifying offset information
110 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassExt);
111};
112
113} // namespace mirror
114} // namespace art
115
116#endif // ART_RUNTIME_MIRROR_CLASS_EXT_H_