blob: 577c28585ebcd3b1f80e6378fe822e4c68316f57 [file] [log] [blame]
Alex Lighteb98b082017-01-25 13:02:32 -08001/* 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 Gampe06c42a52017-07-26 14:17:14 -070032#ifndef ART_OPENJDKJVMTI_TI_CLASS_LOADER_H_
33#define ART_OPENJDKJVMTI_TI_CLASS_LOADER_H_
Alex Lighteb98b082017-01-25 13:02:32 -080034
35#include <string>
36
37#include <jni.h>
38
David Sehr1979c642018-04-26 14:41:18 -070039#include "base/globals.h"
Vladimir Marko5924a4a2018-05-29 17:40:41 +010040#include "base/mutex.h"
Alex Lighteb98b082017-01-25 13:02:32 -080041#include "jvmti.h"
Alex Lighteb98b082017-01-25 13:02:32 -080042#include "mirror/array.h"
Vladimir Marko5924a4a2018-05-29 17:40:41 +010043
44namespace art {
45
46class DexFile;
47template <class MirrorType> class Handle;
48template <class MirrorType> class ObjPtr;
49class Thread;
50
51} // namespace art
Alex Lighteb98b082017-01-25 13:02:32 -080052
53namespace 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.
58class 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 Lightc7588752018-02-20 11:15:54 -080072 // 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 Light1babae02017-02-01 15:35:34 -080080 static art::ObjPtr<art::mirror::LongArray> GetDexFileCookie(
81 art::Handle<art::mirror::Object> java_dex_file) REQUIRES_SHARED(art::Locks::mutator_lock_);
82
Alex Lighteb98b082017-01-25 13:02:32 -080083 static art::ObjPtr<art::mirror::LongArray> AllocateNewDexFileCookie(
84 art::Thread* self,
Alex Light1babae02017-02-01 15:35:34 -080085 art::Handle<art::mirror::LongArray> old_dex_file_cookie,
Alex Lighteb98b082017-01-25 13:02:32 -080086 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 Lightc7588752018-02-20 11:15:54 -080091
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 Lighteb98b082017-01-25 13:02:32 -080096};
97
98} // namespace openjdkjvmti
Andreas Gampe06c42a52017-07-26 14:17:14 -070099#endif // ART_OPENJDKJVMTI_TI_CLASS_LOADER_H_