Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ sudo: false
scala:
- 2.10.5
- 2.11.7
- 2.12.0-M4
jdk:
- openjdk6
- oraclejdk7
- oraclejdk8
script: ./sbt ++$TRAVIS_SCALA_VERSION clean test doc
matrix:
exclude:
- scala: 2.12.0-M4
jdk: openjdk6
- scala: 2.12.0-M4
jdk: oraclejdk7
script: ./sbt "+++$TRAVIS_SCALA_VERSION clean" "+++$TRAVIS_SCALA_VERSION test" "+++$TRAVIS_SCALA_VERSION doc"

15 changes: 10 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
import scala.collection.JavaConverters._
import scalariform.formatter.preferences._

val kryoVersion = "3.0.3"
val kryoVersion = "3.1.0-SNAPSHOT"
val bijectionVersion = "0.9.0"
val algebirdVersion = "0.12.0"

Expand All @@ -17,7 +17,7 @@ def isScala210x(scalaVersion: String) = scalaVersion match {
val sharedSettings = Project.defaultSettings ++ mimaDefaultSettings ++ scalariformSettings ++ Seq(
organization := "com.twitter",
scalaVersion := "2.10.5",
crossScalaVersions := Seq("2.10.5", "2.11.7"),
crossScalaVersions := Seq("2.10.5", "2.11.7", "2.12.0-M4"),
scalacOptions ++= Seq("-unchecked", "-deprecation"),
ScalariformKeys.preferences := formattingPreferences,

Expand All @@ -30,8 +30,8 @@ val sharedSettings = Project.defaultSettings ++ mimaDefaultSettings ++ scalarifo
Opts.resolver.sonatypeReleases
),
libraryDependencies ++= Seq(
"org.scalacheck" %% "scalacheck" % "1.11.5" % "test",
"org.scalatest" %% "scalatest" % "2.2.2" % "test",
"org.scalacheck" %% "scalacheck" % "1.11.6" % "test",
"org.scalatest" %% "scalatest" % "2.2.6" % "test",
"com.esotericsoftware" % "kryo-shaded" % kryoVersion
),

Expand Down Expand Up @@ -86,7 +86,7 @@ lazy val chillAll = Project(
id = "chill-all",
base = file("."),
settings = sharedSettings
).settings(
).enablePlugins(CrossPerProjectPlugin).settings(
test := { },
publish := { },
publishLocal := { }
Expand Down Expand Up @@ -152,13 +152,15 @@ lazy val chill = Project(

lazy val chillAkka = module("akka").settings(
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
crossScalaVersions := crossScalaVersions.value.filterNot(_.startsWith("2.12")),
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.2.1",
"com.typesafe.akka" %% "akka-actor" % "2.3.6" % "provided"
)
).dependsOn(chill % "test->test;compile->compile")

lazy val chillBijection = module("bijection").settings(
crossScalaVersions := crossScalaVersions.value.filterNot(_.startsWith("2.12")),
libraryDependencies ++= Seq(
"com.twitter" %% "bijection-core" % bijectionVersion
)
Expand Down Expand Up @@ -202,6 +204,7 @@ lazy val chillThrift = module("thrift").settings(
)

lazy val chillScrooge = module("scrooge").settings(
crossScalaVersions := crossScalaVersions.value.filterNot(_.startsWith("2.12")),
libraryDependencies ++= Seq(
"org.apache.thrift" % "libthrift" % "0.6.1" exclude("junit", "junit"),
"com.twitter" %% "scrooge-serializer" % "3.20.0"
Expand All @@ -218,13 +221,15 @@ lazy val chillProtobuf = module("protobuf").settings(
).dependsOn(chillJava)

lazy val chillAvro = module("avro").settings(
crossScalaVersions := crossScalaVersions.value.filterNot(_.startsWith("2.12")),
libraryDependencies ++= Seq(
"com.twitter" %% "bijection-avro" % bijectionVersion,
"junit" % "junit" % "4.5" % "test"
)
).dependsOn(chill,chillJava, chillBijection)

lazy val chillAlgebird = module("algebird").settings(
crossScalaVersions := crossScalaVersions.value.filterNot(_.startsWith("2.12")),
libraryDependencies ++= Seq(
"com.twitter" %% "algebird-core" % algebirdVersion
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.scalatest._
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import com.esotericsoftware.kryo.serializers.ClosureSerializer

import org.objenesis.strategy.StdInstantiatorStrategy

Expand All @@ -40,6 +41,13 @@ class PriorityQueueSpec extends WordSpec with Matchers {
val kryo = new Kryo()
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy)
PriorityQueueSerializer.registrar()(kryo)
// Enable Java 8 lambda serialization only if we are running on a Java 8 JRE:
try {
Class.forName("java.lang.invoke.SerializedLambda")
kryo.register(classOf[ClosureSerializer.Closure], new ClosureSerializer())
} catch {
case e: ClassNotFoundException => // not running on Java 8
}
val ord = Ordering.fromLessThan[(Int, Int)] { (l, r) => l._1 < r._1 }
val q = new java.util.PriorityQueue[(Int, Int)](3, ord)
q.add((2, 3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ object ClosureCleaner {
.asInstanceOf[AnyRef]
}

class FieldAccessFinder(output: MMap[Class[_], MSet[String]]) extends ClassVisitor(ASM4) {
class FieldAccessFinder(output: MMap[Class[_], MSet[String]]) extends ClassVisitor(ASM5) {
override def visitMethod(access: Int, name: String, desc: String,
sig: String, exceptions: Array[String]): MethodVisitor = {
return new MethodVisitor(ASM4) {
return new MethodVisitor(ASM5) {
override def visitFieldInsn(op: Int, owner: String, name: String,
desc: String) {
if (op == GETFIELD)
Expand All @@ -228,7 +228,7 @@ class FieldAccessFinder(output: MMap[Class[_], MSet[String]]) extends ClassVisit
}

override def visitMethodInsn(op: Int, owner: String, name: String,
desc: String) {
desc: String, itf: Boolean) {
// Check for calls a getter method for a variable in an interpreter wrapper object.
// This means that the corresponding field will be accessed, so we should save it.
if (op == INVOKEVIRTUAL && owner.endsWith("$iwC") && !name.endsWith("$outer"))
Expand All @@ -239,7 +239,7 @@ class FieldAccessFinder(output: MMap[Class[_], MSet[String]]) extends ClassVisit
}
}

class InnerClosureFinder(output: MSet[Class[_]]) extends ClassVisitor(ASM4) {
class InnerClosureFinder(output: MSet[Class[_]]) extends ClassVisitor(ASM5) {
var myName: String = null

override def visit(version: Int, access: Int, name: String, sig: String,
Expand All @@ -249,9 +249,9 @@ class InnerClosureFinder(output: MSet[Class[_]]) extends ClassVisitor(ASM4) {

override def visitMethod(access: Int, name: String, desc: String,
sig: String, exceptions: Array[String]): MethodVisitor = {
return new MethodVisitor(ASM4) {
return new MethodVisitor(ASM5) {
override def visitMethodInsn(op: Int, owner: String, name: String,
desc: String) {
desc: String, itf: Boolean) {
val argTypes = Type.getArgumentTypes(desc)
if (op == INVOKESPECIAL && name == "<init>" && argTypes.length > 0
&& argTypes(0).toString.startsWith("L") // is it an object?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import scala.collection.mutable.{

import scala.util.matching.Regex

import com.esotericsoftware.kryo.serializers.ClosureSerializer
import com.twitter.chill.java.PackageRegistrar
import _root_.java.io.Serializable

Expand Down Expand Up @@ -198,8 +199,16 @@ class AllScalaRegistrar extends IKryoRegistrar {
.forSubclass[scala.Enumeration#Value](new EnumerationSerializer)

// use the singleton serializer for boxed Unit
val boxedUnit = scala.Unit.box(())
val boxedUnit = scala.runtime.BoxedUnit.UNIT
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't be necessary in M5, fixed in scala/scala#5100

k.register(boxedUnit.getClass, new SingletonSerializer(boxedUnit))
PackageRegistrar.all()(k)

// Enable Java 8 lambda serialization only if we are running on a Java 8 JRE:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: what's the best place to register this? And what happens if it already happens to have been registered by some other means?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make a Java8ClosureRegistrar that is an IKryoRegistrar: https://github.com/twitter/chill/blob/develop/chill-java/src/main/java/com/twitter/chill/IKryoRegistrar.java and it should be a no-op when we are not on java8 (as you have below).

See for instance the PackageRegistrar.all() above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea; will do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, forgot about this comment until now. I've created a Java8ClosureRegistrar to abstract away this code.

try {
Class.forName("java.lang.invoke.SerializedLambda")
k.register(classOf[ClosureSerializer.Closure], new ClosureSerializer())
} catch {
case e: ClassNotFoundException => // not running on Java 8
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class KryoSpec extends WordSpec with Matchers with BaseProperties {
toList(rt(qr)) should equal(qrlist)
}
"Ranges should be fixed size" in {
val MAX_RANGE_SIZE = 188 // what seems to be needed.
val MAX_RANGE_SIZE = 447 // what seems to be needed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a bummer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😦

We could make this constant a function of Scala version if you'd like to keep using the old value for the old build matrix entries.

serialize((1 to 10000)).size should be < (MAX_RANGE_SIZE) // some fixed size
serialize((1 to 10000 by 2)).size should be < (MAX_RANGE_SIZE) // some fixed size
serialize((1 until 10000)).size should be < (MAX_RANGE_SIZE) // some fixed size
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.5.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.0")
addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5")