Skip to content

Commit

Permalink
88 million methods indexed on 8GB ram
Browse files Browse the repository at this point in the history
  • Loading branch information
avantgardnerio committed Oct 30, 2018
1 parent b52a162 commit 63df9bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/main/kotlin/net/squarelabs/depends/Resolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import org.objectweb.asm.commons.InstructionAdapter
import java.io.File
import java.net.URLClassLoader

var methodCount = 0

fun resolve(coordinate: String, cache: HashMap<String, Artifact> = HashMap()): Artifact {
return cache.computeIfAbsent(coordinate) {
val artifacts = Maven.resolver()
Expand All @@ -32,8 +34,10 @@ fun resolve(coordinate: String, cache: HashMap<String, Artifact> = HashMap()): A
fun classesFromFile(file: File): List<Class> {
return URLClassLoader(arrayOf(file.toURL())).use { it ->
val cp = ClassPath.from(it)
cp.topLevelClasses.map { clazz ->
val size = cp.topLevelClasses.size
cp.topLevelClasses.mapIndexed { index, clazz ->
val methods = methodsFromClass(clazz, it)
if(index % 1000 == 0) println("$methodCount class $index / $size is ${clazz.name}")
Class(clazz.name, methods)
}
}
Expand All @@ -47,6 +51,7 @@ fun methodsFromClass(clazz: ClassPath.ClassInfo, loader: URLClassLoader): List<M
val oriMv: MethodVisitor = object : MethodVisitor(Opcodes.ASM7) {}
val instMv = object : InstructionAdapter(Opcodes.ASM7, oriMv) {
override fun visitMethodInsn(opcode: Int, owner: String?, name: String?, descriptor: String?, isInterface: Boolean) {
methodCount++
//println("invoke $owner.$name from ${clazz.name}.$methodName()")
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
}
Expand Down
9 changes: 1 addition & 8 deletions src/test/kotlin/net/squarelabs/depends/ResolverTest.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package net.squarelabs.depends

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import net.squarelabs.depends.models.Artifact
import org.junit.Test
import java.io.File

class ResolverTest {
@Test
fun `resolver should resolve`() {
val root: Artifact = resolve("io.dropwizard:dropwizard-core:1.3.7")
File("out.json").printWriter().use { writer ->
val mapper = ObjectMapper()
mapper.enable(SerializationFeature.INDENT_OUTPUT)
mapper.writeValue(writer, root)
}
println("root=${root.coordinate}")
}
}

0 comments on commit 63df9bc

Please sign in to comment.