Java.lang.NoClassDefFoundError: kotlin/jvm/internal/Reflection

Hello,

I just wrote the Kotlin version for this benchmark: https://github.com/kostya/benchmarks/tree/master/base64. When I run the program with Kotlin 0.11.569 I get this error:

Exception in thread “main” java.lang.NoClassDefFoundError: kotlin/jvm/internal/Reflection
  at _DefaultPackage.<clinit>(Base64.kt)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:259)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Reflection

Don’t understand what I’m doing wrong/what is happening. Any hints? Strange thing is that using println does not compile: Error:(33, 5) Kotlin: Unresolved reference: println. So I changed to System.out.println which works.

Thanks, Oliver

Kotlin code:

import java.lang

fun main(args: Array<String>) {

  val enc = sun.misc.BASE64Encoder()
  val dec = sun.misc.BASE64Decoder()

  val STR_SIZE = 10000000
  val TRIES = 100

  val buffer = StringBuffer()
  for (i in 0…STR_SIZE - 1) {
  buffer.append(“a”)
  }
  val str = lang.String(buffer.toString())
  var str2 = “”
  var t = System.nanoTime()
  var s = 0

  for (i in 1…TRIES) {
  str2 = enc.encode(str.getBytes())
  s += str2.length()
  }

  System.out.println(“encode: " + s + ”, " + (System.nanoTime() - t) / 1e9)

  s = 0
  for (i in 1…TRIES) {
  val str3 = dec.decodeBuffer(str2)
  s += str3.size()
  }

  System.out.println(“decode: " + s + ”, " + (System.nanoTime() - t) / 1e9)

}

This means you don't have the Kotlin runtime library (kotlin-runtime.jar) in the classpath. Please check if your module depends on the library and add the dependency if not.

Okay, managed to get it fixed. Thanks. Here are the measurements for my machine (Core i7-4600M, 2.90 GHz, quad-core, Windows 7):

Kotlin (JDK8):

encode: 1368421200, 28.725779572
decode: 1000000000, 54.272592502

Java (JDK8):

encode: 1368421200, 31.008432298
decode: 1000000000, 58.633304231

Scala (JDK8):

encode: 1368421200, 13.783206397
decode: 1000000000, 26.121356501

Go 1.4.1:

encode: 1333333600, 3.4110
decode: 1000000000, 15.3430

So Kotlin is slightly faster than Java8, which is good :-). Interesting that Scala is even better.

Regards, Oliver

The Scala result is surprising, indeed. I'd suggest to use JMH for microbenchmarking, then the results are at least more or less reliable.

Now I equipped Kotlin and Java with more memory (VM options "-server -Xss15500k") and all of a sudden things look quite different:

Kotlin:

encode: 1368421200, 12.969774034
decode: 1000000000, 29.252869838

Java:

encode: 1368421200, 15.610144874
decode: 1000000000, 31.842187534

Scala (JDK8):

encode: 1368421200, 13.783206397
decode: 1000000000, 26.121356501

So it looks like the for loop in Scala creates less garbage …