Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate scala-stm benchmarks from Scala 2.12 to Scala 3 #445

Merged
merged 3 commits into from
Jul 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.renaissance.BenchmarkResult.Validators
import org.renaissance.License

@Name("philosophers")
@Group("scala")
@Group("scala-stm")
@Group("scala") // With Scala 3, the primary group goes last.
@Summary("Solves a variant of the dining philosophers problem using ScalaSTM.")
@Licenses(Array(License.BSD3))
@Repetitions(30)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.renaissance.BenchmarkResult.Validators
import org.renaissance.License

@Name("scala-stm-bench7")
@Group("scala")
@Group("scala-stm")
@Group("scala") // With Scala 3, the primary group goes last.
@Summary("Runs the stmbench7 benchmark using ScalaSTM.")
@Licenses(Array(License.BSD3, License.GPL2))
@Repetitions(60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

package stmbench7.scalastm

import scala.collection.JavaConversions
import scala.jdk.CollectionConverters.IteratorHasAsJava

import stmbench7.backend.ImmutableCollection

class ImmutableSeqImpl[A](contents: Seq[A]) extends ImmutableCollection[A] {
override def clone: ImmutableCollection[A] = this
override def contains(element: A): Boolean = contents.contains(element)
override def size: Int = contents.size

override def iterator: java.util.Iterator[A] =
JavaConversions.asJavaIterator(contents.iterator)
override def iterator: java.util.Iterator[A] = contents.iterator.asJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package stmbench7.scalastm

import scala.collection.JavaConversions
import scala.jdk.CollectionConverters.IteratorHasAsJava

import scala.concurrent.stm.TSet

Expand All @@ -17,7 +17,5 @@ class ImmutableSetImpl[A](contents: TSet.View[A], shared: Boolean = true)

override def contains(element: A): Boolean = contents.contains(element)
override def size: Int = contents.size

override def iterator: java.util.Iterator[A] =
JavaConversions.asJavaIterator(contents.iterator)
override def iterator: java.util.Iterator[A] = contents.iterator.asJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

package stmbench7.scalastm

import scala.collection.JavaConversions
import scala.collection.immutable.TreeMap
import scala.jdk.CollectionConverters.SetHasAsJava
import scala.jdk.CollectionConverters.IteratorHasAsJava

import scala.concurrent.stm.Ref

Expand Down Expand Up @@ -34,8 +35,7 @@ object IndexImpl {

override def iterator: java.util.Iterator[V] = makeValuesIterator(underlying())

override def getKeys: java.lang.Iterable[K] =
JavaConversions.setAsJavaSet(underlying().keySet)
override def getKeys: java.lang.Iterable[K] = underlying().keySet.asJava

override def getRange(minKey: K, maxKey: K): java.lang.Iterable[V] =
new java.lang.Iterable[V] {
Expand All @@ -44,7 +44,7 @@ object IndexImpl {
}

private def makeValuesIterator(m: TreeMap[K, V]) = {
JavaConversions.asJavaIterator(m.values.iterator)
m.values.iterator.asJava
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package stmbench7.scalastm

import scala.collection.JavaConversions
import scala.jdk.CollectionConverters.IteratorHasAsJava

import scala.concurrent.stm.TMap

Expand All @@ -15,7 +15,5 @@ class LargeSetImpl[A <: Comparable[A]] extends LargeSet[A] {
override def remove(e: A): Boolean = underlying.remove(e).isDefined
override def contains(e: A): Boolean = underlying.contains(e)
override def size: Int = underlying.size

override def iterator: java.util.Iterator[A] =
JavaConversions.asJavaIterator(underlying.keysIterator)
override def iterator: java.util.Iterator[A] = underlying.keysIterator.asJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package stmbench7.scalastm

import scala.annotation.unused

import scala.concurrent.stm.atomic
import scala.concurrent.stm.Ref

Expand All @@ -23,6 +25,7 @@ import stmbench7.core.Module
import stmbench7.core.Operation
import stmbench7.impl.core.ConnectionImpl

@unused("Referenced via string name")
class ScalaSTMInitializer extends SynchMethodInitializer {

def createOperationExecutorFactory(): OperationExecutorFactory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ else if(currentArg.equals("--")) {
else if(currentArg.equals("-w")) workload = optionValue;
else if(currentArg.equals("-g")) synchType = optionValue;
else if(currentArg.equals("-s")) stmInitializerClassName = optionValue;
else if(currentArg.equals("-c")) countOfOperations = Integer.parseInt(optionValue);
else if(currentArg.equals("-c")) countOfOperations = Integer.parseInt(optionValue);
else throw new BenchmarkParametersException("Invalid option: " + currentArg);
}
}
Expand Down Expand Up @@ -201,8 +201,8 @@ else throw new BenchmarkParametersException("STM initializer class name not give
break;
}
try {
synchMethodInitializer =
synchMethodInitializerClass.newInstance();
synchMethodInitializer =
synchMethodInitializerClass.getDeclaredConstructor().newInstance();
}
catch(Exception e) {
throw new BenchmarkParametersException("Error instantiating STM initializer class", e);
Expand Down
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,13 @@ lazy val scalaStdlibBenchmarks = (project in file("benchmarks/scala-stdlib"))
lazy val scalaStmBenchmarks = (project in file("benchmarks/scala-stm"))
.settings(
name := "scala-stm",
commonSettingsScala212,
commonSettingsScala3,
libraryDependencies := Seq(
"org.scala-stm" %% "scala-stm" % "0.11.1"
),
dependencyOverrides ++= Seq(
// Force common version of Scala 3 library.
"org.scala-lang" %% "scala3-library" % scalaVersion3
)
)
.dependsOn(
Expand Down