Skip to content

Commit

Permalink
Add booster-cha-asm to support ASM based CHA
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee committed Jun 27, 2022
1 parent a83d7c2 commit 269c882
Show file tree
Hide file tree
Showing 28 changed files with 415 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,6 @@ val BaseVariant.packageBundleTask: Task?
)
val BaseVariant.mergeJavaResourceTask: Task?
get() = project.tasks.findByName(getTaskName("merge", "JavaResource"))

val BaseVariant.jars: Set<File>
get() = project.getJars(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.didiglobal.booster.gradle

import org.gradle.api.Task

private val NOP: (String) -> Unit = {}

val Task.d: (String) -> Unit
get() {
val debug: (String) -> Unit = logger::debug
return debug.takeIf { logger.isDebugEnabled } ?: NOP
}

val Task.i: (String) -> Unit
get() {
val info: (String) -> Unit = logger::info
return info.takeIf { logger.isInfoEnabled } ?: NOP
}

val Task.w: (String) -> Unit
get() {
val warn: (String) -> Unit = logger::warn
return warn.takeIf { logger.isWarnEnabled } ?: NOP
}

val Task.e: (String) -> Unit
get() {
val error: (String) -> Unit = logger::error
return error.takeIf { logger.isErrorEnabled } ?: NOP
}
3 changes: 3 additions & 0 deletions booster-cha-asm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# booster-cha-asm

This module provides ASM based CHA (class hierarchy analysis) implementation
7 changes: 7 additions & 0 deletions booster-cha-asm/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apply from: "$rootDir/gradle/booster.gradle"

dependencies {
api project(':booster-cha')
api project(':booster-transform-asm')
testImplementation project(':booster-transform-asm')
}
3 changes: 3 additions & 0 deletions booster-cha-asm/packages-zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Package com.didiglobal.booster.cha.asm

提供了基于 ASM 的类继承分析
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.didiglobal.booster.task.analyser
package com.didiglobal.booster.cha.asm

import com.didiglobal.booster.cha.ClassFileParser
import com.didiglobal.booster.transform.asm.asClassNode
import org.objectweb.asm.tree.ClassNode
import java.io.InputStream

internal object AsmClassFileParser : ClassFileParser<ClassNode> {
object AsmClassFileParser : ClassFileParser<ClassNode> {

override fun parse(input: InputStream): ClassNode {
return input.asClassNode()
}
override fun parse(input: InputStream): ClassNode = input.asClassNode()

override fun getClassName(classNode: ClassNode): String = classNode.name

override fun getSuperName(classNode: ClassNode): String? = classNode.superName
override fun getAccessFlags(classNode: ClassNode): Int = classNode.access

override fun getInterfaces(classNode: ClassNode): Array<String> = classNode.interfaces.toTypedArray()

override fun getAccessFlags(classNode: ClassNode): Int = classNode.access
override fun getSuperName(classNode: ClassNode): String? = classNode.superName

override fun getClassName(classNode: ClassNode): String = classNode.name

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.didiglobal.booster.cha.asm

import com.didiglobal.booster.cha.ClassSet
import org.objectweb.asm.tree.ClassNode
import java.io.File

typealias AsmClassSet = ClassSet<ClassNode, AsmClassFileParser>

fun ClassSet.Companion.from(file: File) = from(file, AsmClassFileParser)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.didiglobal.booster.cha.asm

import org.objectweb.asm.tree.ClassNode
import java.time.Duration

typealias ProgressListener = (ClassNode, Float, Duration) -> Unit
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.didiglobal.booster.task.analyser.reference
package com.didiglobal.booster.cha.asm

import com.didiglobal.booster.graph.GroupedNode

data class ReferenceNode(
data class Reference(
val component: String,
val klass: String
) : GroupedNode<String> {
Expand Down
Loading

0 comments on commit 269c882

Please sign in to comment.