Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2017 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_CLASS_LOADER_H_ |
| 33 | #define ART_OPENJDKJVMTI_TI_CLASS_LOADER_H_ |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 34 | |
| 35 | #include <string> |
| 36 | |
| 37 | #include <jni.h> |
| 38 | |
David Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 39 | #include "base/globals.h" |
Vladimir Marko | 5924a4a | 2018-05-29 17:40:41 +0100 | [diff] [blame] | 40 | #include "base/mutex.h" |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 41 | #include "jvmti.h" |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 42 | #include "mirror/array.h" |
Vladimir Marko | 5924a4a | 2018-05-29 17:40:41 +0100 | [diff] [blame] | 43 | |
| 44 | namespace art { |
| 45 | |
| 46 | class DexFile; |
| 47 | template <class MirrorType> class Handle; |
| 48 | template <class MirrorType> class ObjPtr; |
| 49 | class Thread; |
| 50 | |
| 51 | } // namespace art |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 52 | |
| 53 | namespace openjdkjvmti { |
| 54 | |
| 55 | // Class that can redefine a single class's methods. |
| 56 | // TODO We should really make this be driven by an outside class so we can do multiple classes at |
| 57 | // the same time and have less required cleanup. |
| 58 | class ClassLoaderHelper { |
| 59 | public: |
| 60 | static bool AddToClassLoader(art::Thread* self, |
| 61 | art::Handle<art::mirror::ClassLoader> loader, |
| 62 | const art::DexFile* dex_file) |
| 63 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 64 | |
| 65 | // Finds a java.lang.DexFile object that is associated with the given ClassLoader. Each of these |
| 66 | // j.l.DexFile objects holds several art::DexFile*s in it. |
| 67 | // TODO This should return the actual source java.lang.DexFile object for the klass being loaded. |
| 68 | static art::ObjPtr<art::mirror::Object> FindSourceDexFileObject( |
| 69 | art::Thread* self, art::Handle<art::mirror::ClassLoader> loader) |
| 70 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 71 | |
Alex Light | c758875 | 2018-02-20 11:15:54 -0800 | [diff] [blame] | 72 | // Calls visitor on each java.lang.DexFile associated with the given loader. The visitor should |
| 73 | // return true to continue on to the next DexFile or false to stop iterating. |
| 74 | template<typename Visitor> |
| 75 | static inline void VisitDexFileObjects(art::Thread* self, |
| 76 | art::Handle<art::mirror::ClassLoader> loader, |
| 77 | const Visitor& visitor) |
| 78 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 79 | |
Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 80 | static art::ObjPtr<art::mirror::LongArray> GetDexFileCookie( |
| 81 | art::Handle<art::mirror::Object> java_dex_file) REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 82 | |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 83 | static art::ObjPtr<art::mirror::LongArray> AllocateNewDexFileCookie( |
| 84 | art::Thread* self, |
Alex Light | 1babae0 | 2017-02-01 15:35:34 -0800 | [diff] [blame] | 85 | art::Handle<art::mirror::LongArray> old_dex_file_cookie, |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 86 | const art::DexFile* new_dex_file) REQUIRES_SHARED(art::Locks::mutator_lock_); |
| 87 | |
| 88 | static void UpdateJavaDexFile(art::ObjPtr<art::mirror::Object> java_dex_file, |
| 89 | art::ObjPtr<art::mirror::LongArray> new_cookie) |
| 90 | REQUIRES(art::Roles::uninterruptible_) REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | c758875 | 2018-02-20 11:15:54 -0800 | [diff] [blame] | 91 | |
| 92 | private: |
| 93 | static art::ObjPtr<art::mirror::ObjectArray<art::mirror::Object>> GetDexElementList( |
| 94 | art::Thread* self, art::Handle<art::mirror::ClassLoader> loader) |
| 95 | REQUIRES_SHARED(art::Locks::mutator_lock_); |
Alex Light | eb98b08 | 2017-01-25 13:02:32 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace openjdkjvmti |
Andreas Gampe | 06c42a5 | 2017-07-26 14:17:14 -0700 | [diff] [blame] | 99 | #endif // ART_OPENJDKJVMTI_TI_CLASS_LOADER_H_ |