Skip to content

Commit

Permalink
feat:启动时后台加载isa解析资源,减少首次加载字节码的卡顿感
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Jun 16, 2024
1 parent db89ac5 commit ca6628d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions kra/src/main/java/me/yricky/oh/abcd/AbcBuf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ class AbcBuf(

private val _methodCache = HashMap<Int,MethodItem>()
fun method(offset: Int):MethodItem{
println("offset:0x${offset.toString(16)}")
return _methodCache[offset]?.also {
println("hitCache:0x${offset.toString(16)}")
} ?: (if(isForeignOffset(offset)) ForeignMethod(this,offset) else AbcMethod(this,offset)).also {
return _methodCache[offset] ?: (if(isForeignOffset(offset)) ForeignMethod(this,offset) else AbcMethod(this,offset)).also {
_methodCache[offset] = it
}
}
Expand Down
6 changes: 4 additions & 2 deletions kra/src/main/java/me/yricky/oh/abcd/isa/Asm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class Asm(
val code: Code,
) {
companion object{
val yaml = YAMLMapper()
val asmMap = AsmMap(yaml.readValue(Asm::class.java.classLoader.getResourceAsStream("abcde/isa.yaml"),object : TypeReference<Isa>(){}))
val asmMap by lazy {
val yaml = YAMLMapper()
AsmMap(yaml.readValue(Asm::class.java.classLoader.getResourceAsStream("abcde/isa.yaml"),object : TypeReference<Isa>(){}))
}
}
val list:List<AsmItem> by lazy{
val li = ArrayList<AsmItem>()
Expand Down
1 change: 1 addition & 0 deletions kra/src/main/java/me/yricky/oh/abcd/isa/AsmMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AsmMap(
val insMap:Map<Byte,Inst>

init {
println("init AsmMap")
val _prefixInstMap:Map<Byte,MutableMap<Byte,Inst>> = isa.prefixes.associate { Pair(it.opcodeIdx, mutableMapOf()) }
insMap = mutableMapOf()
isa.groups.forEach { ig ->
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/me/yricky/abcde/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.yricky.abcde.page.ClassListPage
import me.yricky.abcde.page.ClassViewPage
import me.yricky.abcde.page.CodeViewPage
import me.yricky.abcde.page.WelcomePage
import me.yricky.abcde.ui.Icons
import me.yricky.abcde.ui.isDarkTheme
import me.yricky.oh.abcd.AbcBuf
import me.yricky.oh.abcd.isa.Asm
import java.awt.Dimension
import java.io.File
import java.nio.channels.FileChannel
Expand Down Expand Up @@ -137,6 +140,9 @@ fun main(args: Array<String>) = application {
// ){
LaunchedEffect(null){
window.minimumSize = Dimension(1280,800)
launch(Dispatchers.IO){
Asm.asmMap
}
}
if(isLinux){
CompositionLocalProvider(LocalDensity provides Density(1.5f,1f)){
Expand Down

0 comments on commit ca6628d

Please sign in to comment.