| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2016 The Android Open Source Project |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | * |
| 4 | * This file implements interfaces from the file jvmti.h. This implementation |
| 5 | * is licensed under the same terms as the file jvmti.h. The |
| 6 | * copyright and license information for the file jvmti.h follows. |
| 7 | * |
| 8 | * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
| 9 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 10 | * |
| 11 | * This code is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License version 2 only, as |
| 13 | * published by the Free Software Foundation. Oracle designates this |
| 14 | * particular file as subject to the "Classpath" exception as provided |
| 15 | * by Oracle in the LICENSE file that accompanied this code. |
| 16 | * |
| 17 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 20 | * version 2 for more details (a copy is included in the LICENSE file that |
| 21 | * accompanied this code). |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License version |
| 24 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 25 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 26 | * |
| 27 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 28 | * or visit www.oracle.com if you need additional information or have any |
| 29 | * questions. |
| 30 | */ |
| 31 | |
| Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 32 | #ifndef ART_OPENJDKJVMTI_TI_REDEFINE_H_ |
| 33 | #define ART_OPENJDKJVMTI_TI_REDEFINE_H_ |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 34 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 35 | #include <functional> |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 36 | #include <string> |
| 37 | |
| 38 | #include <jni.h> |
| 39 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 40 | #include "art_field.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 41 | #include "art_jvmti.h" |
| Vladimir Marko | e1993c7 | 2017-06-14 17:01:38 +0100 | [diff] [blame] | 42 | #include "base/array_ref.h" |
| David Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 43 | #include "base/globals.h" |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 44 | #include "dex/class_accessor.h" |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 45 | #include "dex/dex_file.h" |
| 46 | #include "dex/dex_file_structs.h" |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 47 | #include "jni/jni_env_ext-inl.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 48 | #include "jvmti.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 49 | #include "mirror/array.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 50 | #include "mirror/class.h" |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 51 | #include "mirror/dex_cache.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 52 | #include "obj_ptr.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 53 | |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 54 | namespace art { |
| Alex Light | 270db1c | 2019-12-03 12:20:01 +0000 | [diff] [blame] | 55 | class ClassAccessor; |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 56 | namespace dex { |
| 57 | struct ClassDef; |
| 58 | } // namespace dex |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 59 | } // namespace art |
| 60 | |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 61 | namespace openjdkjvmti { |
| 62 | |
| Vladimir Marko | 5924a4a | 2018-05-29 17:40:41 +0100 | [diff] [blame] | 63 | class ArtClassDefinition; |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 64 | class RedefinitionDataHolder; |
| Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 65 | class RedefinitionDataIter; |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 66 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 67 | enum class RedefinitionType { |
| 68 | kStructural, |
| 69 | kNormal, |
| 70 | }; |
| 71 | |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 72 | // Class that can redefine a single class's methods. |
| 73 | class Redefiner { |
| 74 | public: |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 75 | // Redefine the given classes with the given dex data. Note this function does not take ownership |
| 76 | // of the dex_data pointers. It is not used after this call however and may be freed if desired. |
| Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 77 | // The caller is responsible for freeing it. The runtime makes its own copy of the data. This |
| 78 | // function does not call the transformation events. |
| Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 79 | static jvmtiError RedefineClassesDirect(ArtJvmTiEnv* env, |
| 80 | art::Runtime* runtime, |
| 81 | art::Thread* self, |
| 82 | const std::vector<ArtClassDefinition>& definitions, |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 83 | RedefinitionType type, |
| Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 84 | /*out*/std::string* error_msg); |
| 85 | |
| 86 | // Redefine the given classes with the given dex data. Note this function does not take ownership |
| 87 | // of the dex_data pointers. It is not used after this call however and may be freed if desired. |
| Alex Light | 0b77257 | 2016-12-02 17:27:31 -0800 | [diff] [blame] | 88 | // The caller is responsible for freeing it. The runtime makes its own copy of the data. |
| Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 89 | static jvmtiError RedefineClasses(jvmtiEnv* env, |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 90 | jint class_count, |
| Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 91 | const jvmtiClassDefinition* definitions); |
| Alex Light | d55b844 | 2019-10-15 15:46:07 -0700 | [diff] [blame] | 92 | static jvmtiError StructurallyRedefineClasses(jvmtiEnv* env, |
| 93 | jint class_count, |
| 94 | const jvmtiClassDefinition* definitions); |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 95 | |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 96 | static jvmtiError IsModifiableClass(jvmtiEnv* env, jclass klass, jboolean* is_redefinable); |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 97 | static jvmtiError IsStructurallyModifiableClass(jvmtiEnv* env, |
| 98 | jclass klass, |
| 99 | jboolean* is_redefinable); |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 100 | |
| Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 101 | static art::MemMap MoveDataToMemMap(const std::string& original_location, |
| 102 | art::ArrayRef<const unsigned char> data, |
| 103 | std::string* error_msg); |
| Alex Light | 440b5d9 | 2017-01-24 15:32:25 -0800 | [diff] [blame] | 104 | |
| Alex Light | 9e7859c | 2018-04-05 13:49:43 -0700 | [diff] [blame] | 105 | // Helper for checking if redefinition/retransformation is allowed. |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 106 | template<RedefinitionType kType = RedefinitionType::kNormal> |
| Alex Light | 9e7859c | 2018-04-05 13:49:43 -0700 | [diff] [blame] | 107 | static jvmtiError GetClassRedefinitionError(jclass klass, /*out*/std::string* error_msg) |
| 108 | REQUIRES(!art::Locks::mutator_lock_); |
| 109 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 110 | static jvmtiError StructurallyRedefineClassDirect(jvmtiEnv* env, |
| 111 | jclass klass, |
| 112 | const unsigned char* data, |
| 113 | jint data_size); |
| 114 | |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 115 | private: |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 116 | class ClassRedefinition { |
| 117 | public: |
| 118 | ClassRedefinition(Redefiner* driver, |
| 119 | jclass klass, |
| 120 | const art::DexFile* redefined_dex_file, |
| Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 121 | const char* class_sig, |
| Vladimir Marko | e1993c7 | 2017-06-14 17:01:38 +0100 | [diff] [blame] | 122 | art::ArrayRef<const unsigned char> orig_dex_file) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 123 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 124 | |
| 125 | // NO_THREAD_SAFETY_ANALYSIS so we can unlock the class in the destructor. |
| 126 | ~ClassRedefinition() NO_THREAD_SAFETY_ANALYSIS; |
| 127 | |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 128 | // Move assignment so we can sort these in a vector. |
| 129 | ClassRedefinition& operator=(ClassRedefinition&& other) { |
| 130 | driver_ = other.driver_; |
| 131 | klass_ = other.klass_; |
| 132 | dex_file_ = std::move(other.dex_file_); |
| 133 | class_sig_ = std::move(other.class_sig_); |
| 134 | original_dex_file_ = other.original_dex_file_; |
| 135 | other.driver_ = nullptr; |
| 136 | return *this; |
| 137 | } |
| 138 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 139 | // Move constructor so we can put these into a vector. |
| 140 | ClassRedefinition(ClassRedefinition&& other) |
| 141 | : driver_(other.driver_), |
| 142 | klass_(other.klass_), |
| 143 | dex_file_(std::move(other.dex_file_)), |
| Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 144 | class_sig_(std::move(other.class_sig_)), |
| 145 | original_dex_file_(other.original_dex_file_) { |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 146 | other.driver_ = nullptr; |
| 147 | } |
| 148 | |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 149 | // No copy! |
| 150 | ClassRedefinition(ClassRedefinition&) = delete; |
| 151 | ClassRedefinition& operator=(ClassRedefinition&) = delete; |
| 152 | |
| Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 153 | art::ObjPtr<art::mirror::Class> GetMirrorClass() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Vladimir Marko | c524e9e | 2019-03-26 10:54:50 +0000 | [diff] [blame] | 154 | art::ObjPtr<art::mirror::ClassLoader> GetClassLoader() |
| 155 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 156 | |
| Alex Light | 7916f20 | 2017-01-27 09:00:15 -0800 | [diff] [blame] | 157 | const art::DexFile& GetDexFile() { |
| 158 | return *dex_file_; |
| 159 | } |
| 160 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 161 | art::mirror::DexCache* CreateNewDexCache(art::Handle<art::mirror::ClassLoader> loader) |
| 162 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 163 | |
| Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 164 | // This may return nullptr with a OOME pending if allocation fails. |
| Alex Light | 2f814aa | 2017-03-24 15:21:34 +0000 | [diff] [blame] | 165 | art::mirror::Object* AllocateOrGetOriginalDexFile() |
| Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 166 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 167 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 168 | void RecordFailure(jvmtiError e, const std::string& err) { |
| 169 | driver_->RecordFailure(e, class_sig_, err); |
| 170 | } |
| 171 | |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 172 | bool FinishRemainingCommonAllocations(/*out*/RedefinitionDataIter* cur_data) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 173 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 174 | |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 175 | bool FinishNewClassAllocations(RedefinitionDataHolder& holder, |
| 176 | /*out*/RedefinitionDataIter* cur_data) |
| 177 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 178 | bool CollectAndCreateNewInstances(/*out*/RedefinitionDataIter* cur_data) |
| 179 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 180 | |
| Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 181 | bool AllocateAndRememberNewDexFileCookie( |
| Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 182 | art::Handle<art::mirror::ClassLoader> source_class_loader, |
| 183 | art::Handle<art::mirror::Object> dex_file_obj, |
| Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 184 | /*out*/RedefinitionDataIter* cur_data) |
| Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 185 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 186 | |
| Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 187 | void FindAndAllocateObsoleteMethods(art::ObjPtr<art::mirror::Class> art_klass) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 188 | REQUIRES(art::Locks::mutator_lock_); |
| 189 | |
| Alex Light | 270db1c | 2019-12-03 12:20:01 +0000 | [diff] [blame] | 190 | art::ObjPtr<art::mirror::Class> AllocateNewClassObject( |
| 191 | art::Handle<art::mirror::Class> old_class, |
| 192 | art::Handle<art::mirror::Class> super_class, |
| 193 | art::Handle<art::mirror::DexCache> cache, |
| 194 | uint16_t dex_class_def_index) REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 195 | art::ObjPtr<art::mirror::Class> AllocateNewClassObject(art::Handle<art::mirror::DexCache> cache) |
| 196 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 197 | |
| Alex Light | 270db1c | 2019-12-03 12:20:01 +0000 | [diff] [blame] | 198 | uint32_t GetNewClassSize(art::ClassAccessor& accessor) |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 199 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 200 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 201 | // Checks that the dex file contains only the single expected class and that the top-level class |
| 202 | // data has not been modified in an incompatible manner. |
| 203 | bool CheckClass() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 204 | |
| Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 205 | // Checks that the contained class can be successfully verified. |
| Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 206 | bool CheckVerification(const RedefinitionDataIter& holder) |
| Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 207 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 208 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 209 | // Preallocates all needed allocations in klass so that we can pause execution safely. |
| Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 210 | bool EnsureClassAllocationsFinished(/*out*/RedefinitionDataIter* data) |
| 211 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 212 | |
| 213 | // This will check that no constraints are violated (more than 1 class in dex file, any changes |
| 214 | // in number/declaration of methods & fields, changes in access flags, etc.) |
| 215 | bool CheckRedefinitionIsValid() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 216 | |
| 217 | // Checks that the class can even be redefined. |
| 218 | bool CheckRedefinable() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 219 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 220 | // Checks that the dex file does not add/remove methods, or change their modifiers or types in |
| 221 | // illegal ways. |
| 222 | bool CheckMethods() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 223 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 224 | // Checks that the dex file does not modify fields types or modifiers in illegal ways. |
| 225 | bool CheckFields() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 226 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 227 | // Temporary check that a class undergoing structural redefinition has no instances. This |
| 228 | // requirement will be removed in time. |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 229 | void UpdateJavaDexFile(art::ObjPtr<art::mirror::Object> java_dex_file, |
| 230 | art::ObjPtr<art::mirror::LongArray> new_cookie) |
| 231 | REQUIRES(art::Locks::mutator_lock_); |
| 232 | |
| 233 | void UpdateFields(art::ObjPtr<art::mirror::Class> mclass) |
| 234 | REQUIRES(art::Locks::mutator_lock_); |
| 235 | |
| 236 | void UpdateMethods(art::ObjPtr<art::mirror::Class> mclass, |
| Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 237 | const art::dex::ClassDef& class_def) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 238 | REQUIRES(art::Locks::mutator_lock_); |
| 239 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 240 | void UpdateClass(const RedefinitionDataIter& cur_data) |
| 241 | REQUIRES(art::Locks::mutator_lock_); |
| 242 | |
| 243 | void CollectNewFieldAndMethodMappings(const RedefinitionDataIter& data, |
| 244 | std::map<art::ArtMethod*, art::ArtMethod*>* method_map, |
| 245 | std::map<art::ArtField*, art::ArtField*>* field_map) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 246 | REQUIRES(art::Locks::mutator_lock_); |
| 247 | |
| Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 248 | void RestoreObsoleteMethodMapsIfUnneeded(const RedefinitionDataIter* cur_data) |
| 249 | REQUIRES(art::Locks::mutator_lock_); |
| 250 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 251 | void ReleaseDexFile() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 252 | |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 253 | // This should be done with all threads suspended. |
| Alex Light | e34fe44 | 2018-02-21 17:35:55 -0800 | [diff] [blame] | 254 | void UnregisterJvmtiBreakpoints() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 5643caf | 2017-02-08 11:39:07 -0800 | [diff] [blame] | 255 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 256 | void RecordNewMethodAdded(); |
| 257 | void RecordNewFieldAdded(); |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 258 | void RecordHasVirtualMembers() { |
| 259 | has_virtuals_ = true; |
| 260 | } |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 261 | |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 262 | bool HasVirtualMembers() const { |
| 263 | return has_virtuals_; |
| 264 | } |
| 265 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 266 | bool IsStructuralRedefinition() const { |
| 267 | DCHECK(!(added_fields_ || added_methods_) || driver_->IsStructuralRedefinition()) |
| 268 | << "added_fields_: " << added_fields_ << " added_methods_: " << added_methods_ |
| 269 | << " driver_->IsStructuralRedefinition(): " << driver_->IsStructuralRedefinition(); |
| 270 | return driver_->IsStructuralRedefinition() && (added_fields_ || added_methods_); |
| 271 | } |
| 272 | |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 273 | private: |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 274 | void UpdateClassStructurally(const RedefinitionDataIter& cur_data) |
| 275 | REQUIRES(art::Locks::mutator_lock_); |
| 276 | |
| 277 | void UpdateClassInPlace(const RedefinitionDataIter& cur_data) |
| 278 | REQUIRES(art::Locks::mutator_lock_); |
| 279 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 280 | Redefiner* driver_; |
| 281 | jclass klass_; |
| 282 | std::unique_ptr<const art::DexFile> dex_file_; |
| 283 | std::string class_sig_; |
| Vladimir Marko | e1993c7 | 2017-06-14 17:01:38 +0100 | [diff] [blame] | 284 | art::ArrayRef<const unsigned char> original_dex_file_; |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 285 | |
| 286 | bool added_fields_ = false; |
| 287 | bool added_methods_ = false; |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 288 | bool has_virtuals_ = false; |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 289 | }; |
| 290 | |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 291 | ArtJvmTiEnv* env_; |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 292 | jvmtiError result_; |
| 293 | art::Runtime* runtime_; |
| 294 | art::Thread* self_; |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 295 | RedefinitionType type_; |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 296 | std::vector<ClassRedefinition> redefinitions_; |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 297 | // Kept as a jclass since we have weird run-state changes that make keeping it around as a |
| 298 | // mirror::Class difficult and confusing. |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 299 | std::string* error_msg_; |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 300 | |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 301 | Redefiner(ArtJvmTiEnv* env, |
| 302 | art::Runtime* runtime, |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 303 | art::Thread* self, |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 304 | RedefinitionType type, |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 305 | std::string* error_msg) |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 306 | : env_(env), |
| 307 | result_(ERR(INTERNAL)), |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 308 | runtime_(runtime), |
| 309 | self_(self), |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 310 | type_(type), |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 311 | redefinitions_(), |
| 312 | error_msg_(error_msg) { } |
| 313 | |
| Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 314 | jvmtiError AddRedefinition(ArtJvmTiEnv* env, const ArtClassDefinition& def) |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 315 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 316 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 317 | template<RedefinitionType kType = RedefinitionType::kNormal> |
| Alex Light | d55b844 | 2019-10-15 15:46:07 -0700 | [diff] [blame] | 318 | static jvmtiError RedefineClassesGeneric(jvmtiEnv* env, |
| 319 | jint class_count, |
| 320 | const jvmtiClassDefinition* definitions); |
| 321 | |
| 322 | template<RedefinitionType kType = RedefinitionType::kNormal> |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 323 | static jvmtiError IsModifiableClassGeneric(jvmtiEnv* env, jclass klass, jboolean* is_redefinable); |
| 324 | |
| 325 | template<RedefinitionType kType = RedefinitionType::kNormal> |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 326 | static jvmtiError GetClassRedefinitionError(art::Handle<art::mirror::Class> klass, |
| 327 | /*out*/std::string* error_msg) |
| 328 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 329 | |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 330 | jvmtiError Run() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 331 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 332 | bool CheckAllRedefinitionAreValid() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 333 | bool CheckAllClassesAreVerified(RedefinitionDataHolder& holder) |
| Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 334 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 335 | void MarkStructuralChanges(RedefinitionDataHolder& holder) |
| 336 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 337 | bool EnsureAllClassAllocationsFinished(RedefinitionDataHolder& holder) |
| 338 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | fb53708 | 2019-12-10 14:38:34 -0800 | [diff] [blame] | 339 | bool FinishAllRemainingCommonAllocations(RedefinitionDataHolder& holder) |
| 340 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 341 | bool FinishAllNewClassAllocations(RedefinitionDataHolder& holder) |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 342 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 343 | bool CollectAndCreateNewInstances(RedefinitionDataHolder& holder) |
| 344 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 345 | void ReleaseAllDexFiles() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | c2d0c96 | 2019-10-23 14:14:25 -0700 | [diff] [blame] | 346 | void ReverifyClasses(RedefinitionDataHolder& holder) REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 5643caf | 2017-02-08 11:39:07 -0800 | [diff] [blame] | 347 | void UnregisterAllBreakpoints() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 348 | // Restores the old obsolete methods maps if it turns out they weren't needed (ie there were no |
| 349 | // new obsolete methods). |
| 350 | void RestoreObsoleteMethodMapsIfUnneeded(RedefinitionDataHolder& holder) |
| 351 | REQUIRES(art::Locks::mutator_lock_); |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 352 | |
| Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 353 | bool IsStructuralRedefinition() const { |
| 354 | return type_ == RedefinitionType::kStructural; |
| 355 | } |
| 356 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 357 | void RecordFailure(jvmtiError result, const std::string& class_sig, const std::string& error_msg); |
| 358 | void RecordFailure(jvmtiError result, const std::string& error_msg) { |
| 359 | RecordFailure(result, "NO CLASS", error_msg); |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 362 | friend struct CallbackCtx; |
| Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 363 | friend class RedefinitionDataHolder; |
| 364 | friend class RedefinitionDataIter; |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | } // namespace openjdkjvmti |
| 368 | |
| Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 369 | #endif // ART_OPENJDKJVMTI_TI_REDEFINE_H_ |