Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

[WIP] Support for Scala 2.12 #438

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions core/src/main/scala-2.12.0-M4
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package scala.pickling.binary

import sun.misc.Unsafe

object UnsafeMemory {
import sun.misc.Unsafe
private[pickling] val unsafe: Unsafe =
scala.concurrent.util.Unsafe.instance
private[pickling] val unsafe: Unsafe = {
val fields = classOf[Unsafe].getDeclaredFields()
val unsafes = for (field <- fields; if field.getType == classOf[Unsafe]) yield {
field.setAccessible(true)
field.get(null).asInstanceOf[Unsafe]
}
unsafes.headOption.getOrElse(
throw new IllegalStateException("Can't find instance of sun.misc.Unsafe"))
}
private[pickling] val byteArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Byte]])
private[pickling] val shortArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Short]])
private[pickling] val intArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Int]])
Expand All @@ -13,9 +21,9 @@ object UnsafeMemory {
private[pickling] val charArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Char]])
private[pickling] val booleanArrayOffset: Long = unsafe.arrayBaseOffset(classOf[Array[Boolean]])
def putInt(arr: Array[Byte], i: Int, value: Int): Unit = {
unsafe.putInt(arr, byteArrayOffset + i, value)
unsafe.putInt(arr, byteArrayOffset + i, value)
}
def getInt(arr: Array[Byte], i: Int): Int = {
unsafe.getInt(arr, byteArrayOffset + i)
unsafe.getInt(arr, byteArrayOffset + i)
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/scala/pickling/generator/sourcegen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro

def genAllocateInstance(x: AllocateInstance): c.Tree = {
val tpe = x.tpe.tpe[c.universe.type](c.universe)
q"""_root_.scala.concurrent.util.Unsafe.instance.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]"""
q"""_root_.scala.pickling.binary.UnsafeMemory.unsafe.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]"""
}

def generateUnpickleImplFromAst(unpicklerAst: UnpicklerAst): c.Tree = {
Expand Down Expand Up @@ -484,7 +484,7 @@ private[pickling] trait SourceGenerator extends Macro with tags.FastTypeTagMacro
val objectOutTpe = typeOf[scala.pickling.util.GenObjectOutput]
val fieldName = "$ext"
q"""
val $target = _root_.scala.concurrent.util.Unsafe.instance.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]
val $target = _root_.scala.pickling.binary.UnsafeMemory.unsafe.allocateInstance(classOf[$tpe]).asInstanceOf[$tpe]
val $readerName = reader.readField($fieldName)
val out = {
val up = _root_.scala.Predef.implicitly[_root_.scala.pickling.Unpickler[$objectOutTpe]]
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/scala/pickling/runtime/Runtime.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runtime

import scala.pickling.PicklingErrors.BasePicklingException
import scala.pickling.internal._
import binary.UnsafeMemory

import scala.reflect.runtime.universe.Mirror
import ir._
Expand Down Expand Up @@ -233,7 +234,7 @@ class InterpretedUnpicklerRuntime(val mirror: Mirror, typeTag: String)(implicit

// TODO: need to support modules and other special guys here
// TODO: in principle, we could invoke a constructor here
val inst = scala.concurrent.util.Unsafe.instance.allocateInstance(clazz)
val inst = UnsafeMemory.unsafe.allocateInstance(clazz)
if (shouldBotherAboutSharing(tpe)) registerUnpicklee(inst, preregisterUnpicklee())
val im = mirror.reflect(inst)

Expand Down Expand Up @@ -332,7 +333,7 @@ class ShareNothingInterpretedUnpicklerRuntime(val mirror: Mirror, typeTag: Strin

// TODO: need to support modules and other special guys here
// TODO: in principle, we could invoke a constructor here
val inst = scala.concurrent.util.Unsafe.instance.allocateInstance(clazz)
val inst = UnsafeMemory.unsafe.allocateInstance(clazz)
val im = mirror.reflect(inst)

//debug(s"pendingFields: ${pendingFields.size}")
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt._
import Keys._

object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.0-M15"
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.0-RC2"
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.11.6"
lazy val parserCombinators = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2"
lazy val macroParadise = "org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full
Expand Down
2 changes: 1 addition & 1 deletion project/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Keys._

object Util {
val buildScalaVersion = System.getProperty("scala.version", "2.11.7")
val buildScalaVersions = Seq("2.11.7", "2.10.4")
val buildScalaVersions = Seq("2.11.7", "2.10.4", "2.12.0-M4")
val javaVersion = System.getProperty("java.version")

def loadCredentials(): List[Credentials] = {
Expand Down