Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/ClassLoaderReferenceImpl.java
41161 views
1
/*
2
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.tools.jdi;
27
28
import java.util.ArrayList;
29
import java.util.Collections;
30
import java.util.Iterator;
31
import java.util.List;
32
33
import com.sun.jdi.ClassLoaderReference;
34
import com.sun.jdi.ClassNotLoadedException;
35
import com.sun.jdi.ReferenceType;
36
import com.sun.jdi.Type;
37
import com.sun.jdi.VirtualMachine;
38
39
public class ClassLoaderReferenceImpl extends ObjectReferenceImpl
40
implements ClassLoaderReference
41
{
42
// This is cached only while the VM is suspended
43
private static class Cache extends ObjectReferenceImpl.Cache {
44
List<ReferenceType> visibleClasses = null;
45
}
46
47
protected ObjectReferenceImpl.Cache newCache() {
48
return new Cache();
49
}
50
51
ClassLoaderReferenceImpl(VirtualMachine aVm, long ref) {
52
super(aVm, ref);
53
vm.state().addListener(this);
54
}
55
56
protected String description() {
57
return "ClassLoaderReference " + uniqueID();
58
}
59
60
public List<ReferenceType> definedClasses() {
61
ArrayList<ReferenceType> definedClasses = new ArrayList<>();
62
vm.forEachClass(type -> {
63
if (type.isPrepared() &&
64
equals(type.classLoader())) {
65
definedClasses.add(type);
66
}
67
});
68
return definedClasses;
69
}
70
71
public List<ReferenceType> visibleClasses() {
72
List<ReferenceType> classes = null;
73
try {
74
Cache local = (Cache)getCache();
75
76
if (local != null) {
77
classes = local.visibleClasses;
78
}
79
if (classes == null) {
80
JDWP.ClassLoaderReference.VisibleClasses.ClassInfo[]
81
jdwpClasses = JDWP.ClassLoaderReference.VisibleClasses.
82
process(vm, this).classes;
83
classes = new ArrayList<>(jdwpClasses.length);
84
for (int i = 0; i < jdwpClasses.length; ++i) {
85
classes.add(vm.referenceType(jdwpClasses[i].typeID,
86
jdwpClasses[i].refTypeTag));
87
}
88
classes = Collections.unmodifiableList(classes);
89
if (local != null) {
90
local.visibleClasses = classes;
91
if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
92
vm.printTrace(description() +
93
" temporarily caching visible classes (count = " +
94
classes.size() + ")");
95
}
96
}
97
}
98
} catch (JDWPException exc) {
99
throw exc.toJDIException();
100
}
101
return classes;
102
}
103
104
Type findType(String signature) throws ClassNotLoadedException {
105
List<ReferenceType> types = visibleClasses();
106
107
// first check already loaded classes and possibly avoid massive signature retrieval later
108
for (ReferenceType type : vm.classesBySignature(signature)) {
109
if (types.contains(type)) {
110
return type;
111
}
112
}
113
114
for (ReferenceType type : types) {
115
if (type.signature().equals(signature)) {
116
return type;
117
}
118
}
119
120
String typeName = new JNITypeParser(signature).typeName();
121
throw new ClassNotLoadedException(typeName, "Class " + typeName + " not loaded");
122
}
123
124
byte typeValueKey() {
125
return JDWP.Tag.CLASS_LOADER;
126
}
127
}
128
129