2
|
1 |
/*
|
45714
|
2 |
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.jdi;
|
|
27 |
|
45714
|
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;
|
2
|
38 |
|
|
39 |
public class ClassLoaderReferenceImpl extends ObjectReferenceImpl
|
45714
|
40 |
implements ClassLoaderReference
|
|
41 |
{
|
2
|
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() {
|
45714
|
61 |
ArrayList<ReferenceType> definedClasses = new ArrayList<>();
|
2
|
62 |
for (ReferenceType type : vm.allClasses()) {
|
|
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;
|
45714
|
83 |
classes = new ArrayList<>(jdwpClasses.length);
|
2
|
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;
|
11277
|
91 |
if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
|
2
|
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();
|
11277
|
106 |
Iterator<ReferenceType> iter = types.iterator();
|
2
|
107 |
while (iter.hasNext()) {
|
11277
|
108 |
ReferenceType type = iter.next();
|
2
|
109 |
if (type.signature().equals(signature)) {
|
|
110 |
return type;
|
|
111 |
}
|
|
112 |
}
|
|
113 |
JNITypeParser parser = new JNITypeParser(signature);
|
|
114 |
throw new ClassNotLoadedException(parser.typeName(),
|
|
115 |
"Class " + parser.typeName() + " not loaded");
|
|
116 |
}
|
|
117 |
|
|
118 |
byte typeValueKey() {
|
|
119 |
return JDWP.Tag.CLASS_LOADER;
|
|
120 |
}
|
|
121 |
}
|