Kotlin-decompiled - (Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Overview

Kotlin: Decompiled

(Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Find my explanation of this below in video form!

Idea

The point of this repository is to see quickly how Kotlin language features that seem to have no clear equivalent in Java are compiled to run on the JVM in the end. The Kotlin core developers came up with some interesting ways to overcome this. Some are more straight forward, some less so. In any case, they used to major methodologies: Resolve and enforce the language feature at hand in the front-end of the Kotlin compiler or do the conversion to bytecode solely in the back-end to "emulate" the feature. Of course, for most features, a combination of both is used although at the same time, most features either rely more on front-end or back-end functionality respectively.

Structure

I created one example for each of the below language features, compiled that to JVM bytecode and then decompiled that again with CFR to Java code (and cleaned it up a bit). You will find a directory in both, the kotlin and the java directories for each feature that corresponds to each other. For instance: src/main/kotlin/toplevelfunction compiles to src/main/java/toplevelfunction. Sometimes, there are multiple files necessary to bring across the example, in which case you will find all of them in both again. Note that the output is sometimes not 100% representative of how the bytecode looked but in most examples (mainly apart from suspendkeyword), the output is pretty clear.

Language Features

In the following table, you'll find all the analyzed lanuage features:

Feature
Companion object
const keyword
Data class
Default argument
Delegation
Destructuring declaration
Elvis operator (?:)
Extension function
Extension property
if expression
infix keyword
init block
in keyword
inline keyword
Iterate over range
Lambda labeling
this labeling
lateinit keyword
Local function
Named argument
Nullability ignore operator (!!)
Nullability operator (?.)
Singleton object
Value object
Operator overloading
Read-only collection
reified keyword
Sealed interface
Secondary constructor
String interpolation
suspend keyword
synchronized keyword
Top-level function
tailrec keyword
Try-Catch expression
typealias keyword
Safe typecasting
Unsafe typecasting
Value class

Most interesting examples

In a video on my channel, I looked at the most interesting of the above features to discuss how they were achieved in compiled code:

  • Top-level function
  • inline keyword
  • Local function
  • Operator overloading
  • Named argument
  • Iterate over range
  • Sealed interface
  • reified keyword

Over here, you'll find the video.

You might also like...

JVM Profiler Sending Metrics to Kafka, Console Output or Custom Reporter

Uber JVM Profiler Uber JVM Profiler provides a Java Agent to collect various metrics and stacktraces for Hadoop/Spark JVM processes in a distributed w

Dec 22, 2022

Sends stacktrace-level performance data from a JVM process to Riemann.

Sends stacktrace-level performance data from a JVM process to Riemann.

Riemann JVM Profiler riemann-jvm-profiler is a JVM agent that you can inject into any JVM process--one written in Clojure, Java, Scala, Groovy, etc.--

Sep 21, 2022

A driver to allow deep interaction with the JVM without any restrictions

A driver to allow deep interaction with the JVM without any restrictions

ToolFactory JVM Driver A driver to allow deep interaction with the JVM without any restrictions. To include ToolFactory JVM Driver in your projects si

Oct 8, 2022

Jazzer is a coverage-guided, in-process fuzzer for the JVM platform developed by Code Intelligence

Jazzer is a coverage-guided, in-process fuzzer for the JVM platform developed by Code Intelligence

Jazzer is a coverage-guided, in-process fuzzer for the JVM platform developed by Code Intelligence. It is based on libFuzzer and brings many of its instrumentation-powered mutation features to the JVM.

Jan 5, 2023

chardetng for the JVM

chardetng_j This is chardetng compiled for the JVM using asmble. Licensing Please see the file named COPYRIGHT. TL;DR: Apache-2.0 OR MIT Disclaimer Th

Oct 18, 2021

One file java script for visualizing JDK flight recorder execution logs as flamegraphs without any dependencies except Java and a browser.

Flamegraph from JFR logs Simple one file Java script to generate flamegraphs from Java flight recordings without installing Perl and the Brendan Gregg

Oct 2, 2022

Sampling CPU and HEAP profiler for Java featuring AsyncGetCallTrace + perf_events

Sampling CPU and HEAP profiler for Java featuring AsyncGetCallTrace + perf_events

async-profiler This project is a low overhead sampling profiler for Java that does not suffer from Safepoint bias problem. It features HotSpot-specifi

Jan 3, 2023

Get Method Sampling from Java Flight Recorder Dump and convert to FlameGraph compatible format.

Note: Travis has removed the support for Oracle JDK 8. Therefore the build status is removed temporarily. Converting JFR Method Profiling Samples to F

Dec 16, 2022

Best-of-breed OpenTracing utilities, instrumentations and extensions

OpenTracing Toolbox OpenTracing Toolbox is a collection of libraries that build on top of OpenTracing and provide extensions and plugins to existing i

Oct 15, 2022
Owner
The Self-Taught Software Engineer
The GitHub organization for collecting all source code used within the videos of the YouTube channel
The Self-Taught Software Engineer
A Java agent that rewrites bytecode to instrument allocation sites

The Allocation Instrumenter is a Java agent written using the java.lang.instrument API and ASM. Each allocation in your Java program is instrumented;

Google 438 Dec 19, 2022
Assembler/disassembler for java bytecode

Raung raung - yet another assembler/disassembler for java bytecode. Similar to Krakatau and Smali, based on ASM library. ❗ Warning: this project at a

null 20 Oct 2, 2022
JVM Explorer is a Java desktop application for browsing loaded class files inside locally running Java Virtual Machines.

JVM Explorer JVM Explorer is a Java desktop application for browsing loaded class files inside locally running Java Virtual Machines. Features Browse

null 109 Nov 30, 2022
Simple JVM Profiler Using StatsD and Other Metrics Backends

statsd-jvm-profiler statsd-jvm-profiler is a JVM agent profiler that sends profiling data to StatsD. Inspired by riemann-jvm-profiler, it was primaril

Etsy, Inc. 330 Oct 30, 2022
Small set of tools for JVM troublshooting, monitoring and profiling.

Swiss Java Knife (SJK) SJK is a command line tool for JVM diagnostic, troubleshooting and profiling. SJK exploits standard diagnostic interfaces of JV

Alexey Ragozin 3.2k Jan 3, 2023
Dynamic loading and compiling project based on JVM

camphor 基于jvm的弹性加载及编译中间件(Elastic loading and compiling middleware based on JVM) camphor_0.0.1 项目简介 该项目定位为弹性中间件,能够使系统在不重启的情况下完成增量代码文件的动态编译和加载 模块介绍 camp

palading 1 Jan 22, 2022
JavaOTTF - Official OTTF parser and composer for JVM languages

JavaOTTF Official OTTF parser and composer for JVM languages. Documentation Please refer to the Wiki Section. Installation Maven Add repository into p

Open Timetable 2 Nov 21, 2022
💥 Crasher - open source dump/crash server for different programming languages (used for crash analysis in various applications)

Crashser Crasher - open source dump/crash server for different programming languages (used for crash analysis in various applications). Supported lang

Balun Vladimir 14 Oct 6, 2022
Tools for tracking down memory / JVM problems & generating predictable-as-possible VM behaviour

Hawkshaw Tools for tracking down memory / JVM problems & generating predictable-as-possible VM behaviour You can Use Hawkshaw to mimic application obj

Martijn Verburg 40 Jan 9, 2021
production heap profiling for the JVM. compatible with google-perftools.

Heapster Heapster provides an agent library to do heap profiling for JVM processes with output compatible with Google perftools. The goal of Heapster

marius a. eriksen 392 Dec 27, 2022