Share
Embed
Writing Your First Kotlin Compiler Plugin
The Kotlin compiler plugin API gives us powerful features like Parcelize and the synthetic view accessor methods in kotlinx.android. These features could not be built using similar, but more limited, mechanisms, such as annotation processing.
The Kotlin compiler plugin API is not currently well-documented, but that doesn't mean that it can't be explored! In this talk, we will start from scratch and show how we can build a compiler plugin and deploy an artifact to a public location, so that we can build plugins that can be applied as easily as the official compiler plugins.
This version was presented at KotlinConf 2018: https://kotlinconf.com/schedule/#date=4-october&session=41262
Kevin Most
October 04, 2018
Transcript
275 slides
-
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: • Your code runs at compile-time -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: • Your code runs at compile-time • Private, undocumented API -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: • Your code runs at compile-time • Private, undocumented API • Emit Java bytecode (or LLVM IR) -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: • Your code runs at compile-time • Private, undocumented API • Emit Java bytecode (or LLVM IR) • Works on Kotlin source code only -
Are these basically annotation processors? • Annotation Processors: • Your
code runs at compile-time • Public, documented API • Emit Java source code • Works on Kotlin/Java source code • Multiplatform not supported • Compiler Plugins: • Your code runs at compile-time • Private, undocumented API • Emit Java bytecode (or LLVM IR) • Works on Kotlin source code only • Multiplatform supported -
Why write compiler plugins? • Incredibly powerful API; you can
modify function/class internals -
Why write compiler plugins? • Incredibly powerful API; you can
modify function/class internals • Enables you to solve new classes of metaprogramming problems -
Why write compiler plugins? • Incredibly powerful API; you can
modify function/class internals • Enables you to solve new classes of metaprogramming problems • Annotation processors are JVM-only, while compiler plugins aren't -
Why NOT write compiler plugins? • Annotation processors are much
easier to write (if you only care about JVM) -
Why NOT write compiler plugins? • Annotation processors are much
easier to write (if you only care about JVM) • Compiler plugins are a lot of work. You need to write: -
Why NOT write compiler plugins? • Annotation processors are much
easier to write (if you only care about JVM) • Compiler plugins are a lot of work. You need to write: • An IntelliJ plugin (if creating synthetic members) -
Why NOT write compiler plugins? • Annotation processors are much
easier to write (if you only care about JVM) • Compiler plugins are a lot of work. You need to write: • An IntelliJ plugin (if creating synthetic members) • A Gradle (or Maven, or other build tool) plugin -
Why NOT write compiler plugins? • Annotation processors are much
easier to write (if you only care about JVM) • Compiler plugins are a lot of work. You need to write: • An IntelliJ plugin (if creating synthetic members) • A Gradle (or Maven, or other build tool) plugin • Slightly different extensions for JVM, JS, and Native targets -
Examples of compiler plugins • allopen: Modifies annotated class to
be open • noarg: Modifies annotated class to have a zero-argument constructor -
Examples of compiler plugins • allopen: Modifies annotated class to
be open • noarg: Modifies annotated class to have a zero-argument constructor • android-extensions: findViewById(R.id.foo) aliased, and automatic Parcelable impl generation via @Parcelize -
Examples of compiler plugins • allopen: Modifies annotated class to
be open • noarg: Modifies annotated class to have a zero-argument constructor • android-extensions: findViewById(R.id.foo) aliased, and automatic Parcelable impl generation via @Parcelize • kotlin-serialization: Automatic generation of Serializable impl -
Examples of compiler plugins • allopen: Modifies annotated class to
be open • noarg: Modifies annotated class to have a zero-argument constructor • android-extensions: findViewById(R.id.foo) aliased, and automatic Parcelable impl generation via @Parcelize • kotlin-serialization: Automatic generation of Serializable impl • First multiplatform-ready plugin (generates LLVM IR for native too) -
• All existing compiler plugins are 1st party (github.com/JetBrains/kotlin) •
plugins/{name}/ ... for the actual plugin business logic Examples of compiler plugins -
• All existing compiler plugins are 1st party (github.com/JetBrains/kotlin) •
plugins/{name}/ ... for the actual plugin business logic • libraries/tools/kotlin-{name}/ ... for the Gradle wrappers Examples of compiler plugins -
• All existing compiler plugins are 1st party (github.com/JetBrains/kotlin) •
plugins/{name}/ ... for the actual plugin business logic • libraries/tools/kotlin-{name}/ ... for the Gradle wrappers • libraries/tools/kotlin-maven-{name}/ ... for the Maven wrappers Examples of compiler plugins -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Gradle
API (totally unrelated to Kotlin) -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Gradle
API (totally unrelated to Kotlin) • Provides an entry point from a build.gradle script -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Gradle
API (totally unrelated to Kotlin) • Provides an entry point from a build.gradle script • Allows configuration via Gradle extensions -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • The
interface between the Gradle and Kotlin APIs -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • The
interface between the Gradle and Kotlin APIs • Read Gradle extension options -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • The
interface between the Gradle and Kotlin APIs • Read Gradle extension options • Write out Kotlin SubpluginOptions -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • The
interface between the Gradle and Kotlin APIs • Read Gradle extension options • Write out Kotlin SubpluginOptions • Define the compiler plugin's ID (internal unique key) -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • The
interface between the Gradle and Kotlin APIs • Read Gradle extension options • Write out Kotlin SubpluginOptions • Define the compiler plugin's ID (internal unique key) • Define the Kotlin plugin's Maven coordinates so the compiler can download it -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Reads
kotlinc -Xplugin args • Subplugin options actually get passed through this pipeline -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Reads
kotlinc -Xplugin args • Subplugin options actually get passed through this pipeline • Write CompilerConfigurationKeys -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Read
CompilerConfigurationKeys -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Read
CompilerConfigurationKeys • Register Extensions -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: • ExpressionCodegenExtension -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: • ExpressionCodegenExtension • ClassBuilderInterceptorExtension -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: • ExpressionCodegenExtension • ClassBuilderInterceptorExtension • StorageComponentContainerContributor -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: • ExpressionCodegenExtension • ClassBuilderInterceptorExtension • StorageComponentContainerContributor • IrGenerationExtension ( !!) -
Plugin Architecture Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • Generates
code (finally!) • Multiple types of extensions, such as: • ExpressionCodegenExtension • ClassBuilderInterceptorExtension • StorageComponentContainerContributor • IrGenerationExtension ( !!) • Write bytecode (or LLVM IR!!) -
Let's build our own! • We'll build a compiler plugin
that traces method calls -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging • Could not be an annotation processor; modifies the function body -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging • Could not be an annotation processor; modifies the function body • Prior art: -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging • Could not be an annotation processor; modifies the function body • Prior art: • Hugo: github.com/jakewharton/hugo -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging • Could not be an annotation processor; modifies the function body • Prior art: • Hugo: github.com/jakewharton/hugo • Firebase Performance Monitoring: firebase.google.com/docs/perf-mon -
Let's build our own! • We'll build a compiler plugin
that traces method calls • A method annotated with a debug-log annotation will have its method body modified to include logging • Could not be an annotation processor; modifies the function body • Prior art: • Hugo: github.com/jakewharton/hugo • Firebase Performance Monitoring: firebase.google.com/docs/perf-mon • Both use AspectJ bytecode weaving + Android Gradle Transform API -
fun prime(n: Int): Long { println("⇢ prime(n=$n)") val startTime =
System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("⇠ prime [ran in $timeToRun ms]") return result } The goal -
fun prime(n: Int): Long { println("⇢ prime(n=$n)") val startTime =
System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("⇠ prime [ran in $timeToRun ms]") return result } The goal -
@DebugLog fun prime(n: Int): Long = primeNumberSequence.take(n).last() fun prime(n: Int):
Long { println("⇢ prime(n=$n)") val startTime = System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("⇠ prime [ran in $timeToRun ms]") return result } The goal -
gradle-plugin/build.gradle apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt"
gradlePlugin { plugins { simplePlugin { id = "debuglog.plugin" implementationClass = "debuglog.DebugLogGradlePlugin" } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" gradlePlugin
{ plugins { simplePlugin { id = "debuglog.plugin" implementationClass = "debuglog.DebugLogGradlePlugin" } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } gradle-plugin/build.gradle -
apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" gradlePlugin
{ plugins { simplePlugin { id = "debuglog.plugin" // `apply plugin: "debuglog.plugin"` implementationClass = "debuglog.DebugLogGradlePlugin" } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } gradle-plugin/build.gradle -
apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" gradlePlugin
{ plugins { simplePlugin { id = "debuglog.plugin" // `apply plugin: "debuglog.plugin"` implementationClass = "debuglog.DebugLogGradlePlugin" // entry-point class } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } gradle-plugin/build.gradle -
gradle-plugin/build.gradle apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt"
gradlePlugin { plugins { simplePlugin { id = "debuglog.plugin" // `apply plugin: "debuglog.plugin"` implementationClass = "debuglog.DebugLogGradlePlugin" // entry-point class } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
gradle-plugin/build.gradle apply plugin: "java-gradle-plugin" apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt"
gradlePlugin { plugins { simplePlugin { id = "debuglog.plugin" // `apply plugin: "debuglog.plugin"` implementationClass = "debuglog.DebugLogGradlePlugin" // entry-point class } } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
class DebugLogGradlePlugin : org.gradle.api.Plugin<Project> { override fun apply(project: Project) {
project.extensions.create( "debugLog", DebugLogGradleExtension ::class.java ) } } open class DebugLogGradleExtension { var enabled: Boolean = true var annotations: List<String> = emptyList() } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = TODO() override fun getCompilerPluginId(): String = TODO() override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = TODO() override fun getCompilerPluginId(): String = TODO() override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = TODO() override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = TODO() override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = TODO() override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = TODO() override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( groupId = "debuglog", artifactId = "kotlin-plugin", version = "0.0.1" ) override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
override fun isApplicable( project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( groupId = "debuglog", artifactId = "kotlin-plugin", version = "0.0.1" ) override fun apply(project: Project, /* ... */): List<SubpluginOption> { TODO() } } -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 override fun isApplicable(
project: Project, task: AbstractCompile ): Boolean = project.plugins.hasPlugin(DebugLogGradlePlugin ::class.java) override fun getCompilerPluginId(): String = "debuglog" override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( groupId = "debuglog", artifactId = "kotlin-plugin", version = "0.0.1" ) override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ TODO() }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 // other method
impls override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ TODO()Z }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 // other method
impls override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ val extension = project.extensions.findByType<DebugLogGradleExtension>() ?: DebugLogGradleExtension() if (extension.enabled && extension.annotations.isEmpty()) error("DebugLog is enabled, but no annotations were set") val annotationOptions = extension.annotations .map { SubpluginOption(key = "debugLogAnnotation", value = it) } val enabledOption = SubpluginOption( key = "enabled", value = extension.enabled.toString()) return annotationOptions + enabledOption }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 // other method
impls override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ val extension = project.extensions.findByType<DebugLogGradleExtension>() ?: DebugLogGradleExtension() if (extension.enabled && extension.annotations.isEmpty()) error("DebugLog is enabled, but no annotations were set") val annotationOptions = extension.annotations .map { SubpluginOption(key = "debugLogAnnotation", value = it) } val enabledOption = SubpluginOption( key = "enabled", value = extension.enabled.toString()) return annotationOptions + enabledOption }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 // other method
impls override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ val extension = project.extensions.findByType<DebugLogGradleExtension>() ?: DebugLogGradleExtension() if (extension.enabled && extension.annotations.isEmpty()) error("DebugLog is enabled, but no annotations were set") val annotationOptions = extension.annotations .map { SubpluginOption(key = "debugLogAnnotation", value = it) } val enabledOption = SubpluginOption( key = "enabled", value = extension.enabled.toString()) return annotationOptions + enabledOption }2 }1 -
@AutoService(KotlinGradleSubplugin ::class) // don't forget! class DebugLogGradleSubplugin1:1KotlinGradleSubplugin<AbstractCompile>1{1 // other method
impls override fun apply(project: Project, /* ... */): List<SubpluginOption>1{ val extension = project.extensions.findByType<DebugLogGradleExtension>() ?: DebugLogGradleExtension() if (extension.enabled && extension.annotations.isEmpty()) error("DebugLog is enabled, but no annotations were set") val annotationOptions = extension.annotations .map { SubpluginOption(key = "debugLogAnnotation", value = it) } val enabledOption = SubpluginOption( key = "enabled", value = extension.enabled.toString()) return annotationOptions + enabledOption }2 }1 -
kotlin-plugin/build.gradle apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" dependencies { implementation
"org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
kotlin-plugin/build.gradle apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" dependencies { implementation
"org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
kotlin-plugin/build.gradle apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" dependencies { implementation
"org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
kotlin-plugin/build.gradle apply plugin: "org.jetbrains.kotlin.jvm" apply plugin: "kotlin-kapt" dependencies { implementation
"org.jetbrains.kotlin:kotlin-stdlib:$ktVersion" compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$ktVersion" compileOnly "com.google.auto.service:auto-service:1.0-rc4" kapt "com.google.auto.service:auto-service:1.0-rc4" } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = TODO() override val pluginOptions: Collection<CliOption> = listOf( ) override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = TODO() override val pluginOptions: Collection<CliOption> = listOf( ) override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( ) override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( ) override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( )P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() }2 }1 -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() }2 }1 -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) { TODO() } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) = when (option.name) { } } -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) = when (option.name) { "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean()) }2 }1 -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) = when (option.name) { "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean()) "debugLogAnnotation" -> configuration.appendList(KEY_ANNOTATIONS, value) }2 }1 -
@AutoService(CommandLineProcessor ::class) class DebugLogCommandLineProcessor : CommandLineProcessor { override val pluginId:
String = "debuglog" // same as ID from subplugin override val pluginOptions: Collection<CliOption> = listOf( CliOption("enabled", "<true|false>", "whether plugin is enabled"), CliOption( "debugLogAnnotation", "<fqname>", "debug-log annotation names", required = true, allowMultipleOccurrences = true))P override fun processOption( option: CliOption, value: String, configuration: CompilerConfiguration ) = when (option.name) { "enabled" -> configuration.put(KEY_ENABLED, value.toBoolean()) "debugLogAnnotation" -> configuration.appendList(KEY_ANNOTATIONS, value) else -> error("Unexpected config option ${option.name}") }2 -
@AutoService(ComponentRegistrar ::class) class DebugLogComponentRegistrar : ComponentRegistrar { override fun registerProjectComponents(
project: MockProject, configuration: CompilerConfiguration ) { if (configuration[KEY_ENABLED] == false) { return } ClassBuilderInterceptorExtension.registerExtension( project, DebugLogClassGenerationInterceptor( debugLogAnnotations = configuration[KEY_ANNOTATIONS] ?: error("debuglog plugin requires at least one annotation class option passed to it") ) ) } } -
@AutoService(ComponentRegistrar ::class) class DebugLogComponentRegistrar : ComponentRegistrar { override fun registerProjectComponents(
project: MockProject, configuration: CompilerConfiguration ) { if (configuration[KEY_ENABLED] == false) { return } ClassBuilderInterceptorExtension.registerExtension( project, DebugLogClassGenerationInterceptor( debugLogAnnotations = configuration[KEY_ANNOTATIONS] ?: error("debuglog plugin requires at least one annotation class option passed to it") ) ) } } -
class DebugLogClassGenerationInterceptor( val debugLogAnnotations: List<String> ) : ClassBuilderInterceptorExtension { override
fun interceptClassBuilderFactory( interceptedFactory: ClassBuilderFactory, bindingContext: BindingContext, diagnostics: DiagnosticSink ): ClassBuilderFactory = TODO() } kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassGenerationInterceptor.kt -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassGenerationInterceptor.kt class DebugLogClassGenerationInterceptor( val debugLogAnnotations: List<String> ) : ClassBuilderInterceptorExtension {
override fun interceptClassBuilderFactory( interceptedFactory: ClassBuilderFactory, bindingContext: BindingContext, diagnostics: DiagnosticSink ): ClassBuilderFactory = object: ClassBuilderFactory by interceptedFactory }1 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassGenerationInterceptor.kt class DebugLogClassGenerationInterceptor( val debugLogAnnotations: List<String> ) : ClassBuilderInterceptorExtension {
override fun interceptClassBuilderFactory( interceptedFactory: ClassBuilderFactory, bindingContext: BindingContext, diagnostics: DiagnosticSink ): ClassBuilderFactory = object: ClassBuilderFactory by interceptedFactory { override fun newClassBuilder(origin: JvmDeclarationOrigin) = DebugLogClassBuilder( annotations = debugLogAnnotations, delegateBuilder = interceptedFactory.newClassBuilder(origin)) } }1 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt private class DebugLogClassBuilder( val annotations: List<String>, delegateBuilder: ClassBuilder )
: DelegatingClassBuilder(delegateBuilder) { override fun newMethod( origin: JvmDeclarationOrigin, access: Int, name: String, desc: String, signature: String?, exceptions: Array<out String>? ): MethodVisitor { }1 }2 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt private class DebugLogClassBuilder( val annotations: List<String>, delegateBuilder: ClassBuilder )
: DelegatingClassBuilder(delegateBuilder) { override fun newMethod( origin: JvmDeclarationOrigin, ... ): MethodVisitor { }1 }2 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt private class DebugLogClassBuilder( val annotations: List<String>, delegateBuilder: ClassBuilder )
: DelegatingClassBuilder(delegateBuilder) { override fun newMethod( origin: JvmDeclarationOrigin, ... ): MethodVisitor { val original = super.newMethod(origin, ...) val function = origin.descriptor as? FunctionDescriptor ?: return original if (annotations.none { descriptor.annotations.hasAnnotation(it) }) { return original } }1 }2 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt private class DebugLogClassBuilder( val annotations: List<String>, delegateBuilder: ClassBuilder )
: DelegatingClassBuilder(delegateBuilder) { override fun newMethod( origin: JvmDeclarationOrigin, ... ): MethodVisitor { val original = super.newMethod(origin, ...) val function = origin.descriptor as? FunctionDescriptor ?: return original if (annotations.none { descriptor.annotations.hasAnnotation(it) }) { return original } return object : MethodVisitor(Opcodes.ASM5, original) { }3 }1 }2 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).apply { TODO("on method entry") } }4 }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).apply { TODO("on method entry") } }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN /* void */, ARETURN /* object */, IRETURN /* int */ -> { InstructionAdapter(this).apply { TODO("on method exit") } } } super.visitInsn(opcode) } }3 -
What now? • You write bytecode • Uses the ObjectWeb
ASM API • Neither related to ASM (assembly) or Web ASM (wasm) in any way -
What now? • You write bytecode • Uses the ObjectWeb
ASM API • Neither related to ASM (assembly) or Web ASM (wasm) in any way • An API for modifying JVM bytecode -
What now? • You write bytecode • Uses the ObjectWeb
ASM API • Neither related to ASM (assembly) or Web ASM (wasm) in any way • An API for modifying JVM bytecode • The JVM is a stack machine -
What now? • You write bytecode • Uses the ObjectWeb
ASM API • Neither related to ASM (assembly) or Web ASM (wasm) in any way • An API for modifying JVM bytecode • The JVM is a stack machine • One stack that methods operate upon -
What now? • You write bytecode • Uses the ObjectWeb
ASM API • Neither related to ASM (assembly) or Web ASM (wasm) in any way • An API for modifying JVM bytecode • The JVM is a stack machine • One stack that methods operate upon • You can also read arbitrary variables from the Local Variable Array -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V return value of v1() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V return value of v1() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V return value of v1() return value of v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V return value of v1() return value of v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V v1() + v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V v1() + v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder "sum of values was " -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder "sum of values was " -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder v1() + v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder v1() + v2() -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream StringBuilder -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream String -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V stdout PrintStream String -
What does bytecode look like? fun printSimpleSum() { val sum
= v1() + v2() println("sum of values was $sum") } INVOKESTATIC myapp/RunnerKt.v1 ()I INVOKESTATIC myapp/RunnerKt.v2 ()I IADD ISTORE 1 GETSTATIC j/l/System.out : Lj/io/PrintStream; NEW j/l/StringBuilder DUP INVOKESPECIAL j/l/StringBuilder.<init> ()V LDC "sum of values was " INVOKEVIRTUAL j/l/StringBuilder.append (Lj/l/String;)Lj/l/StringBuilder; ILOAD 1 INVOKEVIRTUAL j/l/StringBuilder.append (I)Lj/l/StringBuilder; INVOKEVIRTUAL j/l/StringBuilder.toString ()Lj/l/String; INVOKEVIRTUAL j/io/PrintStream.println (Lj/l/String;)V -
@DebugLog fun prime(n: Int): Long = primeNumberSequence.take(n).last() fun prime(n: Int):
Long { println("⇢ prime(n=$n)") val startTime = System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("⇠ prime [ran in $timeToRun ms]") return result } Remember the goal -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).apply { TODO("on method entry") } }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).apply { TODO("on method exit") } } } super.visitInsn(opcode) } }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).apply { TODO("on method entry") } } override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).apply { TODO("on method exit") } } } super.visitInsn(opcode) } } -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") }1 stdout PrintStream StringBuilder StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") }1 stdout PrintStream StringBuilder "⇢ prime(" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") }1 stdout PrintStream StringBuilder "⇢ prime(" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder " n=" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder " n=" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder value of n -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder value of n -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") } }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }1 stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }1 stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }1 stdout PrintStream String -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }1 stdout PrintStream String -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply { getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }1 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).apply {L getstatic("j/l/System", "out", "Ljava/io/PrintStream;") anew("j/l/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>",
"()V") visitLdcInsn("⇢ ${function.name}(") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/StringBuilder;") function.valueParameters.forEachIndexed { i, param -> visitLdcInsn(" ${param.name}=") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") visitVarInsn(ALOAD, i + 1) invokevirtual("j/l/StringBuilder", "append", "(Lj/l/Object;)Lj/l/SB;") }R invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }1 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).applyL{L // ... method-trace-printing code // ... timestamp-storing code }W }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).apply { TODO("on method exit") } } } super.visitInsn(opcode) } }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).applyL{L // ... method-trace-printing code // ... timestamp-storing code }W }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).apply { TODO("on method exit") } } } super.visitInsn(opcode) } }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).apply { // ... method-trace-printing code // ... timestamp-storing code }W }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).applyM{MTODO("on method exit")M}M } } super.visitInsn(opcode) } }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") }M stdout PrintStream StringBuilder "⇠ prime [ran in " -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") }M stdout PrintStream StringBuilder "⇠ prime [ran in " -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") }M stdout PrintStream StringBuilder current timestamp -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) }M stdout PrintStream StringBuilder current timestamp -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) }M stdout PrintStream StringBuilder current timestamp start timestamp -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) }M stdout PrintStream StringBuilder current timestamp start timestamp -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) }M stdout PrintStream StringBuilder (current - start) time -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") }M stdout PrintStream StringBuilder (current - start) time -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") }M stdout PrintStream StringBuilder " ms]" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") }M stdout PrintStream StringBuilder " ms]" -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }M stdout PrintStream StringBuilder -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }M stdout PrintStream -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") }M stdout PrintStream String -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }M stdout PrintStream String -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }M -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt InstructionAdapter(this).applyM{M getstatic("j/l/System", "out", "Lj/io/PrintStream;") anew("java/lang/StringBuilder") dup() invokespecial("j/l/StringBuilder", "<init>", "()V")
visitLdcInsn("⇠ ${function.name} [ran in ") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/StringBuilder;") invokestatic("j/l/System", "currentTimeMillis", "()J") load(9001, LONG_TYPE) sub(LONG_TYPE) invokevirtual("j/l/StringBuilder", "append", "(J)Lj/l/StringBuilder;") visitLdcInsn(" ms]") invokevirtual("j/l/StringBuilder", "append", "(Lj/l/String;)Lj/l/SB;") invokevirtual("j/l/StringBuilder", "toString", "()Lj/l/String;") invokevirtual("j/io/PrintStream", "println", "(Lj/l/String;)V") }M -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).applyL{L // ... method-trace-printing code // ... timestamp-storing code }W }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).applyM{M //G ...Gbenchmark-printingGcode }M } } super.visitInsn(opcode) } }3 -
kotlin-plugin/src/main/kotlin/debuglog/DebugLogClassBuilder.kt return object : MethodVisitor(Opcodes.ASM5, original) { override fun visitCode()
{ super.visitCode() InstructionAdapter(this).applyL{L // ... method-trace-printing code // ... timestamp-storing code }W }4 override fun visitInsn(opcode: Int) { when (opcode) { RETURN , ARETURN, IRETURN -> { InstructionAdapter(this).applyM{M //G ...Gbenchmark-printingGcode }M } } super.visitInsn(opcode) } }3 -
Resources • https://github.com/JetBrains/kotlin/tree/master/plugins. Specifically: • noarg: One of the simplest
ones • android-extensions: Good prior art for many of the extension types • kotlin-serialization: Newest one, documented well, generates LLVM • https://github.com/JetBrains/kotlin/tree/master/libraries/tools • All look pretty similar; noarg and allopen are the simplest to grok