Skip to content

Commit

Permalink
Struggling to call kotlin from jcstress maven project
Browse files Browse the repository at this point in the history
  • Loading branch information
DLochmelis33 committed Oct 10, 2023
1 parent 049feee commit 1b2645c
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 4 deletions.
1 change: 1 addition & 0 deletions jcstress/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
libs/
28 changes: 28 additions & 0 deletions jcstress/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ THE POSSIBILITY OF SUCH DAMAGE.
<artifactId>jcstress-core</artifactId>
<version>${jcstress.version}</version>
</dependency>
<dependency>
<groupId>komem.litmus</groupId>
<artifactId>litmuskt</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<properties>
Expand Down Expand Up @@ -115,6 +120,29 @@ THE POSSIBILITY OF SUCH DAMAGE.
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<groupId>komem.litmus</groupId>
<artifactId>litmuskt</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}/libs/litmus-jvm-1.0-SNAPSHOT.jar</file>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
15 changes: 15 additions & 0 deletions jcstress/src/main/java/org/sample/AbaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sample;

import komem.litmus.LitmusTest;

public class AbaTest<S> {

private List<Function1<S, Unit>> fs;
private Function1<S, Object> arbiter;

public AbaTest(LitmusTest<?> test) {
fs = test.getThreadFunctions();
arbiter = test.getOutcomeFinalizer();
}

}
4 changes: 3 additions & 1 deletion jcstress/src/main/java/org/sample/ConcurrencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.II_Result;

import komem.litmus.AffinityMap;

// See jcstress-samples or existing tests for API introduction and testing guidelines

@JCStressTest
Expand All @@ -43,7 +45,7 @@ public class ConcurrencyTest {

@Actor
public void actor1(II_Result r) {
// Put the code for first thread here

}

@Actor
Expand Down
9 changes: 9 additions & 0 deletions litmus/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.incremental.createDirectory
plugins {
kotlin("multiplatform")
id("com.google.devtools.ksp") version "1.9.10-1.0.13"
`java-library`
}

group = "komem.litmus"
Expand Down Expand Up @@ -34,6 +35,8 @@ kotlin {
mainRun {
mainClass.set("JvmMainKt")
}
withSourcesJar()
withJava()
}

val affinitySupported = hostOs == "Linux"
Expand Down Expand Up @@ -153,3 +156,9 @@ tasks.whenTaskAdded {
tasks.matching { it.name.startsWith("compileKotlin") }.forEach { it.dependsOn(kspTask) }
}
}

tasks.register<Copy>("copyLibToJCStress") {
dependsOn("jvmJar")
from(buildDir.resolve("libs/litmus-jvm-$version.jar"))
into(projectDir.resolve("../jcstress/libs/"))
}
4 changes: 2 additions & 2 deletions litmus/src/commonMain/kotlin/komem/litmus/LitmusTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package komem.litmus

data class LitmusTest<S>(
val stateProducer: () -> S,
val threadFunctions: List<S.() -> Any?>,
val threadFunctions: List<S.() -> Unit>,
val outcomeFinalizer: (S.() -> LitmusOutcome),
val outcomeSpec: LitmusOutcomeSpec
) {
Expand All @@ -12,7 +12,7 @@ data class LitmusTest<S>(
class LitmusTestScope<S>(
private val stateProducer: () -> S
) {
private val threadFunctions = mutableListOf<S.() -> Any?>()
private val threadFunctions = mutableListOf<S.() -> Unit>()
private lateinit var outcomeFinalizer: S.() -> LitmusOutcome
private lateinit var outcomeSpec: LitmusOutcomeSpecScope

Expand Down
31 changes: 31 additions & 0 deletions litmus/src/jvmMain/java/AbaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import komem.litmus.LitmusTest;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;

import java.util.List;

public class AbaTest<S> {

private static List<Function1<S, Unit>> fs;
private static Function1<S, Object> arbiter;

public AbaTest(LitmusTest<?> test) {
fs = test.getThreadFunctions();
arbiter = test.getOutcomeFinalizer();
}

}


/*
class LitmusJcsState<S> {
private static (!!!) List<Function1<...>> tfs = test.getThreadFunctions();
private S state = stateProducer();
public void actor0() {
tfs[0].invoke(state);
}
}
*/
2 changes: 1 addition & 1 deletion litmus/src/nativeTest/kotlin/komem/litmus/NativeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class NativeTest {
val test = ATOM
val runner = WorkerRunner
val params = LitmusRunParams(1_000_000, 100, null, ::CinteropSpinBarrier)
runner.runTest(params, test).prettyPrint()
runner.runTest(params, test)
}
}

0 comments on commit 1b2645c

Please sign in to comment.