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