xref: /aosp_15_r20/art/openjdkjvmti/ti_class_loader-inl.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /* Copyright (C) 2017 The Android Open Source Project
2*795d594fSAndroid Build Coastguard Worker  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * This file implements interfaces from the file jvmti.h. This implementation
5*795d594fSAndroid Build Coastguard Worker  * is licensed under the same terms as the file jvmti.h.  The
6*795d594fSAndroid Build Coastguard Worker  * copyright and license information for the file jvmti.h follows.
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
9*795d594fSAndroid Build Coastguard Worker  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10*795d594fSAndroid Build Coastguard Worker  *
11*795d594fSAndroid Build Coastguard Worker  * This code is free software; you can redistribute it and/or modify it
12*795d594fSAndroid Build Coastguard Worker  * under the terms of the GNU General Public License version 2 only, as
13*795d594fSAndroid Build Coastguard Worker  * published by the Free Software Foundation.  Oracle designates this
14*795d594fSAndroid Build Coastguard Worker  * particular file as subject to the "Classpath" exception as provided
15*795d594fSAndroid Build Coastguard Worker  * by Oracle in the LICENSE file that accompanied this code.
16*795d594fSAndroid Build Coastguard Worker  *
17*795d594fSAndroid Build Coastguard Worker  * This code is distributed in the hope that it will be useful, but WITHOUT
18*795d594fSAndroid Build Coastguard Worker  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19*795d594fSAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20*795d594fSAndroid Build Coastguard Worker  * version 2 for more details (a copy is included in the LICENSE file that
21*795d594fSAndroid Build Coastguard Worker  * accompanied this code).
22*795d594fSAndroid Build Coastguard Worker  *
23*795d594fSAndroid Build Coastguard Worker  * You should have received a copy of the GNU General Public License version
24*795d594fSAndroid Build Coastguard Worker  * 2 along with this work; if not, write to the Free Software Foundation,
25*795d594fSAndroid Build Coastguard Worker  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26*795d594fSAndroid Build Coastguard Worker  *
27*795d594fSAndroid Build Coastguard Worker  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28*795d594fSAndroid Build Coastguard Worker  * or visit www.oracle.com if you need additional information or have any
29*795d594fSAndroid Build Coastguard Worker  * questions.
30*795d594fSAndroid Build Coastguard Worker  */
31*795d594fSAndroid Build Coastguard Worker 
32*795d594fSAndroid Build Coastguard Worker #ifndef ART_OPENJDKJVMTI_TI_CLASS_LOADER_INL_H_
33*795d594fSAndroid Build Coastguard Worker #define ART_OPENJDKJVMTI_TI_CLASS_LOADER_INL_H_
34*795d594fSAndroid Build Coastguard Worker 
35*795d594fSAndroid Build Coastguard Worker #include "ti_class_loader.h"
36*795d594fSAndroid Build Coastguard Worker #include "art_field-inl.h"
37*795d594fSAndroid Build Coastguard Worker #include "handle.h"
38*795d594fSAndroid Build Coastguard Worker #include "handle_scope.h"
39*795d594fSAndroid Build Coastguard Worker #include "jni/jni_internal.h"
40*795d594fSAndroid Build Coastguard Worker #include "mirror/object.h"
41*795d594fSAndroid Build Coastguard Worker #include "mirror/object_array-inl.h"
42*795d594fSAndroid Build Coastguard Worker #include "well_known_classes.h"
43*795d594fSAndroid Build Coastguard Worker 
44*795d594fSAndroid Build Coastguard Worker namespace openjdkjvmti {
45*795d594fSAndroid Build Coastguard Worker 
46*795d594fSAndroid Build Coastguard Worker template<typename Visitor>
VisitDexFileObjects(art::Thread * self,art::Handle<art::mirror::ClassLoader> loader,const Visitor & visitor)47*795d594fSAndroid Build Coastguard Worker inline void ClassLoaderHelper::VisitDexFileObjects(art::Thread* self,
48*795d594fSAndroid Build Coastguard Worker                                                    art::Handle<art::mirror::ClassLoader> loader,
49*795d594fSAndroid Build Coastguard Worker                                                    const Visitor& visitor) {
50*795d594fSAndroid Build Coastguard Worker   art::StackHandleScope<1> hs(self);
51*795d594fSAndroid Build Coastguard Worker   art::ArtField* element_dex_file_field =
52*795d594fSAndroid Build Coastguard Worker       art::WellKnownClasses::dalvik_system_DexPathList__Element_dexFile;
53*795d594fSAndroid Build Coastguard Worker 
54*795d594fSAndroid Build Coastguard Worker   art::Handle<art::mirror::ObjectArray<art::mirror::Object>> dex_elements_list(
55*795d594fSAndroid Build Coastguard Worker       hs.NewHandle(GetDexElementList(self, loader)));
56*795d594fSAndroid Build Coastguard Worker   if (dex_elements_list == nullptr) {
57*795d594fSAndroid Build Coastguard Worker     return;
58*795d594fSAndroid Build Coastguard Worker   }
59*795d594fSAndroid Build Coastguard Worker 
60*795d594fSAndroid Build Coastguard Worker   // Iterate over the DexPathList$Element to find the right one
61*795d594fSAndroid Build Coastguard Worker   for (auto current_element : dex_elements_list.Iterate<art::mirror::Object>()) {
62*795d594fSAndroid Build Coastguard Worker     CHECK(!current_element.IsNull());
63*795d594fSAndroid Build Coastguard Worker     art::ObjPtr<art::mirror::Object> dex_file(element_dex_file_field->GetObject(current_element));
64*795d594fSAndroid Build Coastguard Worker     if (!dex_file.IsNull()) {
65*795d594fSAndroid Build Coastguard Worker       if (!visitor(dex_file)) {
66*795d594fSAndroid Build Coastguard Worker         return;
67*795d594fSAndroid Build Coastguard Worker       }
68*795d594fSAndroid Build Coastguard Worker     }
69*795d594fSAndroid Build Coastguard Worker   }
70*795d594fSAndroid Build Coastguard Worker }
71*795d594fSAndroid Build Coastguard Worker 
72*795d594fSAndroid Build Coastguard Worker }  // namespace openjdkjvmti
73*795d594fSAndroid Build Coastguard Worker 
74*795d594fSAndroid Build Coastguard Worker #endif  // ART_OPENJDKJVMTI_TI_CLASS_LOADER_INL_H_
75