use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat by apache.
the class ContextConfig method populateJavaClassCache.
private void populateJavaClassCache(String className, Map<String, JavaClassCacheEntry> javaClassCache) {
if (!javaClassCache.containsKey(className)) {
String name = className.replace('.', '/') + ".class";
try (InputStream is = context.getLoader().getClassLoader().getResourceAsStream(name)) {
if (is == null) {
return;
}
ClassParser parser = new ClassParser(is);
JavaClass clazz = parser.parse();
populateJavaClassCache(clazz.getClassName(), clazz, javaClassCache);
} catch (ClassFormatException | IOException e) {
log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
}
}
}
use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat by apache.
the class TesterPerformance method testClassParserPerformance.
@Test
public void testClassParserPerformance() throws IOException {
File libDir = new File(JAR_LOCATION);
String[] libs = libDir.list();
Assert.assertNotNull(libs);
Set<URL> jarURLs = new HashSet<>();
for (String lib : libs) {
if (!lib.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
continue;
}
jarURLs.add(new URL("jar:" + new File(libDir, lib).toURI().toURL().toExternalForm() + "!/"));
}
long duration = 0;
for (URL jarURL : jarURLs) {
try (Jar jar = JarFactory.newInstance(jarURL)) {
jar.nextEntry();
String jarEntryName = jar.getEntryName();
while (jarEntryName != null) {
if (jarEntryName.endsWith(".class")) {
InputStream is = jar.getEntryInputStream();
long start = System.nanoTime();
ClassParser cp = new ClassParser(is);
cp.parse();
duration += System.nanoTime() - start;
}
jar.nextEntry();
jarEntryName = jar.getEntryName();
}
}
}
System.out.println("ClassParser performance test took: " + duration + " ns");
}
Aggregations