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" |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 44 | #include "dex/dex_file.h" |
| 45 | #include "dex/dex_file_structs.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 46 | #include "jni/jni_env_ext-inl.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 47 | #include "jvmti.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 48 | #include "mirror/array.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 49 | #include "mirror/class.h" |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 50 | #include "mirror/dex_cache.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 51 | #include "obj_ptr.h" |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 52 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 53 | namespace art { |
| 54 | namespace dex { |
| 55 | struct ClassDef; |
| 56 | } // namespace dex |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 57 | } // namespace art |
| 58 | |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 59 | namespace openjdkjvmti { |
| 60 | |
Vladimir Marko | 5924a4a | 2018-05-29 17:40:41 +0100 | [diff] [blame] | 61 | class ArtClassDefinition; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 62 | class RedefinitionDataHolder; |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 63 | class RedefinitionDataIter; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 64 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 65 | enum class RedefinitionType { |
| 66 | kStructural, |
| 67 | kNormal, |
| 68 | }; |
| 69 | |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 70 | // Class that can redefine a single class's methods. |
| 71 | class Redefiner { |
| 72 | public: |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 73 | // Redefine the given classes with the given dex data. Note this function does not take ownership |
| 74 | // 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] | 75 | // The caller is responsible for freeing it. The runtime makes its own copy of the data. This |
| 76 | // function does not call the transformation events. |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 77 | static jvmtiError RedefineClassesDirect(ArtJvmTiEnv* env, |
| 78 | art::Runtime* runtime, |
| 79 | art::Thread* self, |
| 80 | const std::vector<ArtClassDefinition>& definitions, |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 81 | RedefinitionType type, |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 82 | /*out*/std::string* error_msg); |
| 83 | |
| 84 | // Redefine the given classes with the given dex data. Note this function does not take ownership |
| 85 | // 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] | 86 | // 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] | 87 | static jvmtiError RedefineClasses(jvmtiEnv* env, |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 88 | jint class_count, |
Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 89 | const jvmtiClassDefinition* definitions); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 90 | |
Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 91 | static jvmtiError IsModifiableClass(jvmtiEnv* env, jclass klass, jboolean* is_redefinable); |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 92 | static jvmtiError IsStructurallyModifiableClass(jvmtiEnv* env, |
| 93 | jclass klass, |
| 94 | jboolean* is_redefinable); |
Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 95 | |
Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 96 | static art::MemMap MoveDataToMemMap(const std::string& original_location, |
| 97 | art::ArrayRef<const unsigned char> data, |
| 98 | std::string* error_msg); |
Alex Light | 440b5d9 | 2017-01-24 15:32:25 -0800 | [diff] [blame] | 99 | |
Alex Light | 9e7859c | 2018-04-05 13:49:43 -0700 | [diff] [blame] | 100 | // Helper for checking if redefinition/retransformation is allowed. |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 101 | template<RedefinitionType kType = RedefinitionType::kNormal> |
Alex Light | 9e7859c | 2018-04-05 13:49:43 -0700 | [diff] [blame] | 102 | static jvmtiError GetClassRedefinitionError(jclass klass, /*out*/std::string* error_msg) |
| 103 | REQUIRES(!art::Locks::mutator_lock_); |
| 104 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 105 | static jvmtiError StructurallyRedefineClassDirect(jvmtiEnv* env, |
| 106 | jclass klass, |
| 107 | const unsigned char* data, |
| 108 | jint data_size); |
| 109 | |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 110 | private: |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 111 | class ClassRedefinition { |
| 112 | public: |
| 113 | ClassRedefinition(Redefiner* driver, |
| 114 | jclass klass, |
| 115 | const art::DexFile* redefined_dex_file, |
Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 116 | const char* class_sig, |
Vladimir Marko | e1993c7 | 2017-06-14 17:01:38 +0100 | [diff] [blame] | 117 | art::ArrayRef<const unsigned char> orig_dex_file) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 118 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 119 | |
| 120 | // NO_THREAD_SAFETY_ANALYSIS so we can unlock the class in the destructor. |
| 121 | ~ClassRedefinition() NO_THREAD_SAFETY_ANALYSIS; |
| 122 | |
| 123 | // Move constructor so we can put these into a vector. |
| 124 | ClassRedefinition(ClassRedefinition&& other) |
| 125 | : driver_(other.driver_), |
| 126 | klass_(other.klass_), |
| 127 | dex_file_(std::move(other.dex_file_)), |
Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 128 | class_sig_(std::move(other.class_sig_)), |
| 129 | original_dex_file_(other.original_dex_file_) { |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 130 | other.driver_ = nullptr; |
| 131 | } |
| 132 | |
Vladimir Marko | 4617d58 | 2019-03-28 13:48:31 +0000 | [diff] [blame] | 133 | art::ObjPtr<art::mirror::Class> GetMirrorClass() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Vladimir Marko | c524e9e | 2019-03-26 10:54:50 +0000 | [diff] [blame] | 134 | art::ObjPtr<art::mirror::ClassLoader> GetClassLoader() |
| 135 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 136 | |
Alex Light | 7916f20 | 2017-01-27 09:00:15 -0800 | [diff] [blame] | 137 | const art::DexFile& GetDexFile() { |
| 138 | return *dex_file_; |
| 139 | } |
| 140 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 141 | art::mirror::DexCache* CreateNewDexCache(art::Handle<art::mirror::ClassLoader> loader) |
| 142 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 143 | |
Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 144 | // This may return nullptr with a OOME pending if allocation fails. |
Alex Light | 2f814aa | 2017-03-24 15:21:34 +0000 | [diff] [blame] | 145 | art::mirror::Object* AllocateOrGetOriginalDexFile() |
Alex Light | a7e38d8 | 2017-01-19 14:57:28 -0800 | [diff] [blame] | 146 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 147 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 148 | void RecordFailure(jvmtiError e, const std::string& err) { |
| 149 | driver_->RecordFailure(e, class_sig_, err); |
| 150 | } |
| 151 | |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 152 | bool FinishRemainingAllocations(/*out*/RedefinitionDataIter* cur_data) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 153 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 154 | |
Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 155 | bool AllocateAndRememberNewDexFileCookie( |
Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 156 | art::Handle<art::mirror::ClassLoader> source_class_loader, |
| 157 | art::Handle<art::mirror::Object> dex_file_obj, |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 158 | /*out*/RedefinitionDataIter* cur_data) |
Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 159 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 160 | |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 161 | void FindAndAllocateObsoleteMethods(art::ObjPtr<art::mirror::Class> art_klass) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 162 | REQUIRES(art::Locks::mutator_lock_); |
| 163 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 164 | art::ObjPtr<art::mirror::Class> AllocateNewClassObject(art::Handle<art::mirror::DexCache> cache) |
| 165 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 166 | |
| 167 | uint32_t GetNewClassSize(bool with_embedded_tables, art::Handle<art::mirror::Class> old_class) |
| 168 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 169 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 170 | // Checks that the dex file contains only the single expected class and that the top-level class |
| 171 | // data has not been modified in an incompatible manner. |
| 172 | bool CheckClass() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 173 | |
Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 174 | // Checks that the contained class can be successfully verified. |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 175 | bool CheckVerification(const RedefinitionDataIter& holder) |
Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 176 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 177 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 178 | // 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] | 179 | bool EnsureClassAllocationsFinished(/*out*/RedefinitionDataIter* data) |
| 180 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 181 | |
| 182 | // This will check that no constraints are violated (more than 1 class in dex file, any changes |
| 183 | // in number/declaration of methods & fields, changes in access flags, etc.) |
| 184 | bool CheckRedefinitionIsValid() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 185 | |
| 186 | // Checks that the class can even be redefined. |
| 187 | bool CheckRedefinable() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 188 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 189 | // Checks that the dex file does not add/remove methods, or change their modifiers or types in |
| 190 | // illegal ways. |
| 191 | bool CheckMethods() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 192 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 193 | // Checks that the dex file does not modify fields types or modifiers in illegal ways. |
| 194 | bool CheckFields() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 195 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 196 | // Temporary check that a class undergoing structural redefinition has no instances. This |
| 197 | // requirement will be removed in time. |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 198 | void UpdateJavaDexFile(art::ObjPtr<art::mirror::Object> java_dex_file, |
| 199 | art::ObjPtr<art::mirror::LongArray> new_cookie) |
| 200 | REQUIRES(art::Locks::mutator_lock_); |
| 201 | |
| 202 | void UpdateFields(art::ObjPtr<art::mirror::Class> mclass) |
| 203 | REQUIRES(art::Locks::mutator_lock_); |
| 204 | |
| 205 | void UpdateMethods(art::ObjPtr<art::mirror::Class> mclass, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 206 | const art::dex::ClassDef& class_def) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 207 | REQUIRES(art::Locks::mutator_lock_); |
| 208 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 209 | void UpdateClass(const RedefinitionDataIter& cur_data) |
| 210 | REQUIRES(art::Locks::mutator_lock_); |
| 211 | |
Alex Light | b1eebde | 2019-10-22 16:30:47 +0000 | [diff] [blame] | 212 | void ReverifyClass(const RedefinitionDataIter& cur_data) |
| 213 | REQUIRES(art::Locks::mutator_lock_); |
| 214 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 215 | void CollectNewFieldAndMethodMappings(const RedefinitionDataIter& data, |
| 216 | std::map<art::ArtMethod*, art::ArtMethod*>* method_map, |
| 217 | std::map<art::ArtField*, art::ArtField*>* field_map) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 218 | REQUIRES(art::Locks::mutator_lock_); |
| 219 | |
Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 220 | void RestoreObsoleteMethodMapsIfUnneeded(const RedefinitionDataIter* cur_data) |
| 221 | REQUIRES(art::Locks::mutator_lock_); |
| 222 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 223 | void ReleaseDexFile() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 224 | |
Alex Light | 5643caf | 2017-02-08 11:39:07 -0800 | [diff] [blame] | 225 | void UnregisterBreakpoints() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 226 | // This should be done with all threads suspended. |
Alex Light | e34fe44 | 2018-02-21 17:35:55 -0800 | [diff] [blame] | 227 | void UnregisterJvmtiBreakpoints() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 5643caf | 2017-02-08 11:39:07 -0800 | [diff] [blame] | 228 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 229 | void RecordNewMethodAdded(); |
| 230 | void RecordNewFieldAdded(); |
| 231 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 232 | private: |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 233 | bool IsStructuralRedefinition() const { |
| 234 | DCHECK(!(added_fields_ || added_methods_) || driver_->IsStructuralRedefinition()) |
| 235 | << "added_fields_: " << added_fields_ << " added_methods_: " << added_methods_ |
| 236 | << " driver_->IsStructuralRedefinition(): " << driver_->IsStructuralRedefinition(); |
| 237 | return driver_->IsStructuralRedefinition() && (added_fields_ || added_methods_); |
| 238 | } |
| 239 | |
| 240 | void UpdateClassStructurally(const RedefinitionDataIter& cur_data) |
| 241 | REQUIRES(art::Locks::mutator_lock_); |
| 242 | |
| 243 | void UpdateClassInPlace(const RedefinitionDataIter& cur_data) |
| 244 | REQUIRES(art::Locks::mutator_lock_); |
| 245 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 246 | Redefiner* driver_; |
| 247 | jclass klass_; |
| 248 | std::unique_ptr<const art::DexFile> dex_file_; |
| 249 | std::string class_sig_; |
Vladimir Marko | e1993c7 | 2017-06-14 17:01:38 +0100 | [diff] [blame] | 250 | art::ArrayRef<const unsigned char> original_dex_file_; |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 251 | |
| 252 | bool added_fields_ = false; |
| 253 | bool added_methods_ = false; |
Alex Light | b1eebde | 2019-10-22 16:30:47 +0000 | [diff] [blame] | 254 | |
| 255 | // Does the class need to be reverified due to verification soft-fails possibly forcing |
| 256 | // interpreter or lock-counting? |
| 257 | bool needs_reverify_ = false; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 258 | }; |
| 259 | |
Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 260 | ArtJvmTiEnv* env_; |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 261 | jvmtiError result_; |
| 262 | art::Runtime* runtime_; |
| 263 | art::Thread* self_; |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 264 | RedefinitionType type_; |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 265 | std::vector<ClassRedefinition> redefinitions_; |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 266 | // Kept as a jclass since we have weird run-state changes that make keeping it around as a |
| 267 | // mirror::Class difficult and confusing. |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 268 | std::string* error_msg_; |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 269 | |
Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 270 | Redefiner(ArtJvmTiEnv* env, |
| 271 | art::Runtime* runtime, |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 272 | art::Thread* self, |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 273 | RedefinitionType type, |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 274 | std::string* error_msg) |
Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 275 | : env_(env), |
| 276 | result_(ERR(INTERNAL)), |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 277 | runtime_(runtime), |
| 278 | self_(self), |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 279 | type_(type), |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 280 | redefinitions_(), |
| 281 | error_msg_(error_msg) { } |
| 282 | |
Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 283 | jvmtiError AddRedefinition(ArtJvmTiEnv* env, const ArtClassDefinition& def) |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 284 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 285 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 286 | template<RedefinitionType kType = RedefinitionType::kNormal> |
| 287 | static jvmtiError IsModifiableClassGeneric(jvmtiEnv* env, jclass klass, jboolean* is_redefinable); |
| 288 | |
| 289 | template<RedefinitionType kType = RedefinitionType::kNormal> |
Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 290 | static jvmtiError GetClassRedefinitionError(art::Handle<art::mirror::Class> klass, |
| 291 | /*out*/std::string* error_msg) |
| 292 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 293 | |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 294 | jvmtiError Run() REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 295 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 296 | bool CheckAllRedefinitionAreValid() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 297 | bool CheckAllClassesAreVerified(RedefinitionDataHolder& holder) |
Alex Light | 8c889d2 | 2017-02-06 13:58:27 -0800 | [diff] [blame] | 298 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 299 | bool EnsureAllClassAllocationsFinished(RedefinitionDataHolder& holder) |
| 300 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 301 | bool FinishAllRemainingAllocations(RedefinitionDataHolder& holder) |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 302 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 303 | void ReleaseAllDexFiles() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | b1eebde | 2019-10-22 16:30:47 +0000 | [diff] [blame] | 304 | void ReverifyClasses(RedefinitionDataHolder& holder) REQUIRES(art::Locks::mutator_lock_); |
Alex Light | 5643caf | 2017-02-08 11:39:07 -0800 | [diff] [blame] | 305 | void UnregisterAllBreakpoints() REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | 1e3926a | 2017-04-07 10:38:06 -0700 | [diff] [blame] | 306 | // Restores the old obsolete methods maps if it turns out they weren't needed (ie there were no |
| 307 | // new obsolete methods). |
| 308 | void RestoreObsoleteMethodMapsIfUnneeded(RedefinitionDataHolder& holder) |
| 309 | REQUIRES(art::Locks::mutator_lock_); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 310 | |
Nicolas Geoffray | 4ac0e15 | 2019-09-18 06:14:50 +0000 | [diff] [blame] | 311 | bool IsStructuralRedefinition() const { |
| 312 | return type_ == RedefinitionType::kStructural; |
| 313 | } |
| 314 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 315 | void RecordFailure(jvmtiError result, const std::string& class_sig, const std::string& error_msg); |
| 316 | void RecordFailure(jvmtiError result, const std::string& error_msg) { |
| 317 | RecordFailure(result, "NO CLASS", error_msg); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 320 | friend struct CallbackCtx; |
Alex Light | c5f5a6e | 2017-03-01 16:57:08 -0800 | [diff] [blame] | 321 | friend class RedefinitionDataHolder; |
| 322 | friend class RedefinitionDataIter; |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | } // namespace openjdkjvmti |
| 326 | |
Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 327 | #endif // ART_OPENJDKJVMTI_TI_REDEFINE_H_ |