本文整理了Java中java.lang.instrument.Instrumentation.getAllLoadedClasses()
方法的一些代码示例,展示了Instrumentation.getAllLoadedClasses()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instrumentation.getAllLoadedClasses()
方法的具体详情如下:
包路径:java.lang.instrument.Instrumentation
类名称:Instrumentation
方法名:getAllLoadedClasses
暂无
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Iterable<Iterable<Class<?>>> resolve(Instrumentation instrumentation) {
return Collections.<Iterable<Class<?>>>singleton(Arrays.<Class<?>>asList(instrumentation.getAllLoadedClasses()));
}
}
代码示例来源:origin: alibaba/jvm-sandbox
@Override
public Iterator<Class<?>> iteratorForLoadedClasses() {
return new Iterator<Class<?>>() {
final Class<?>[] loaded = inst.getAllLoadedClasses();
int pos = 0;
@Override
public boolean hasNext() {
return pos < loaded.length;
}
@Override
public Class<?> next() {
return loaded[pos++];
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public boolean hasNext() {
if (types == null) {
types = new ArrayList<Class<?>>();
for (Class<?> type : instrumentation.getAllLoadedClasses()) {
if (type != null && processed.add(type)) {
types.add(type);
}
}
}
return !types.isEmpty();
}
代码示例来源:origin: oldmanpushcart/greys-anatomy
@Override
public Collection<Class<?>> allLoadedClasses() {
final Class<?>[] classArray = inst.getAllLoadedClasses();
return null == classArray
? new ArrayList<Class<?>>()
: Arrays.asList(classArray);
}
});
代码示例来源:origin: alibaba/jvm-sandbox
@Override
public Set<Class<?>> list() {
final Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
for (Class<?> clazz : inst.getAllLoadedClasses()) {
classes.add(clazz);
}
return classes;
}
代码示例来源:origin: stackoverflow.com
public class Main {
public static void main(String[] args) {
Instrumentation inst = InstrumentHook.getInstrumentation();
for (Class<?> clazz: inst.getAllLoadedClasses()) {
System.err.println(clazz.getName());
}
}
}
代码示例来源:origin: oldmanpushcart/greys-anatomy
private Set<ClassLoader> listLoadedClassLoader(Instrumentation inst) {
final Set<ClassLoader> classLoaderSet = new HashSet<ClassLoader>();
for (Class<?> clazz : inst.getAllLoadedClasses()) {
if (null == clazz) {
continue;
}
final ClassLoader loader = clazz.getClassLoader();
if (null != loader) {
classLoaderSet.add(loader);
}
}
return classLoaderSet;
}
代码示例来源:origin: scouter-project/scouter
private Class getClass(String className) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
for (Class c : loadedClasses) {
if (c.getName().equals(className)) {
return c;
}
}
return null;
}
@RequestHandler(RequestCmd.OBJECT_CHECK_RESOURCE_FILE)
代码示例来源:origin: scouter-project/scouter
private Class getClass(String className) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
for (Class c : loadedClasses) {
if (c.getName().equals(className)) {
return c;
}
}
return null;
}
@RequestHandler(RequestCmd.OBJECT_CHECK_RESOURCE_FILE)
代码示例来源:origin: scouter-project/scouter
public static Object invokeStaticMethod(String className, String methodName) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Integer tryCount = tryCountMap.get(className);
if (tryCount != null && tryCount.intValue() > 20) return null;
Method m = (Method) reflCache.get(className);
if (m == null) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
for (Class c : loadedClasses) {
if (c.getName().equals(className)) {
m = c.getMethod(methodName);
reflCache.put(className, m);
tryCountMap.remove(className);
break;
}
}
}
if (m == null) {
tryCountMap.put(className, new Integer(tryCount.intValue() + 1));
return null;
}
return m.invoke(null, new Object[]{});
}
代码示例来源:origin: scouter-project/scouter
public static Object invokeStaticMethod(String className, String methodName) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Integer tryCount = tryCountMap.get(className);
if (tryCount != null && tryCount.intValue() > 20) return null;
Method m = (Method) reflCache.get(className);
if (m == null) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
for (Class c : loadedClasses) {
if (c.getName().equals(className)) {
m = c.getMethod(methodName);
reflCache.put(className, m);
tryCountMap.remove(className);
break;
}
}
}
if (m == null) {
tryCountMap.put(className, new Integer(tryCount.intValue() + 1));
return null;
}
return m.invoke(null, new Object[]{});
}
代码示例来源:origin: scouter-project/scouter
private void redefine(StringSet clazzes) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>();
boolean allSuccess = true;
for (int i = 0; i < loadedClasses.length; i++) {
if (clazzes.hasKey(loadedClasses[i].getName())) {
try {
byte[] buff = ClassUtil.getByteCode(loadedClasses[i]);
if (buff == null) {
continue;
}
definitionList.add(new ClassDefinition(loadedClasses[i], buff));
} catch (Exception e) {
allSuccess = false;
break;
}
}
}
if (definitionList.size() > 0 && allSuccess) {
try {
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
} catch (Throwable th) {
Logger.println("A183", "redefine error : " + loadedClasses);
}
}
}
代码示例来源:origin: scouter-project/scouter
private void redefine(StringSet clazzes) {
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>();
boolean allSuccess = true;
for (int i = 0; i < loadedClasses.length; i++) {
if (clazzes.hasKey(loadedClasses[i].getName())) {
try {
byte[] buff = ClassUtil.getByteCode(loadedClasses[i]);
if (buff == null) {
continue;
}
definitionList.add(new ClassDefinition(loadedClasses[i], buff));
} catch (Exception e) {
allSuccess = false;
break;
}
}
}
if (definitionList.size() > 0 && allSuccess) {
try {
JavaAgent.getInstrumentation().redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()]));
} catch (Throwable th) {
Logger.println("A183", "redefine error : " + loadedClasses);
}
}
}
代码示例来源:origin: scouter-project/scouter
p.put("totalPage", 0);
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
if (loadedClasses != null) {
List<Class> classList = new ArrayList<Class>();
代码示例来源:origin: scouter-project/scouter
p.put("totalPage", 0);
Class[] loadedClasses = JavaAgent.getInstrumentation().getAllLoadedClasses();
if (loadedClasses != null) {
List<Class> classList = new ArrayList<Class>();
代码示例来源:origin: scouter-project/scouter
paramSet.add(className);
Class[] classes = JavaAgent.getInstrumentation().getAllLoadedClasses();
代码示例来源:origin: scouter-project/scouter
paramSet.add(className);
Class[] classes = JavaAgent.getInstrumentation().getAllLoadedClasses();
ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>();
boolean allSuccess = true;
代码示例来源:origin: scouter-project/scouter
paramSet.add(className);
Class[] classes = JavaAgent.getInstrumentation().getAllLoadedClasses();
代码示例来源:origin: btraceio/btrace
debugPrint("filtering loaded classes");
ClassCache cc = ClassCache.getInstance();
for (Class c : inst.getAllLoadedClasses()) {
if (c != null) {
cc.get(c);
代码示例来源:origin: rhuss/jolokia
/**
* Tests if the given class name has been loaded by the JVM. Don't use this method
* in case you have access to the class loader which will be loading the class
* because the used approach is not very efficient.
* @param className the name of the class to check
* @param instrumentation
* @return true if the class has been loaded by the JVM
* @throws IllegalArgumentException in case instrumentation or the provided class is null
*/
protected boolean isClassLoaded(String className, Instrumentation instrumentation) {
if (instrumentation == null || className == null) {
throw new IllegalArgumentException("instrumentation and className must not be null");
}
Class<?>[] classes = instrumentation.getAllLoadedClasses();
for (Class<?> c : classes) {
if (className.equals(c.getName())) {
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!