Skip to content

Add support for Native multithreaded execution #4201

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

Merged
merged 116 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from 115 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
caaac9b
Got the ball rolling on SN 0.5
djspiewak Nov 26, 2024
cc600ac
Fixed more weird 0.4 -> 0.5 things
djspiewak Dec 8, 2024
d7306c7
Got WSTP-related stuffs compiling on native
djspiewak Dec 8, 2024
426776b
Reimplemented pats of `AtomicIntegerFieldUpdater`; now it's all linking
djspiewak Dec 8, 2024
489fbb9
Use SleepSystem by default on native
durban Dec 15, 2024
62b8141
Reënable EpollSystem, implement interrupt for it, mark epoll_wait as …
durban Dec 20, 2024
7f0a559
More helpful TestTimeoutException
durban Dec 20, 2024
8ebf321
Merge branch 'series/3.x' into wip/multithreaded-wstp
djspiewak Dec 26, 2024
afba12f
Adjusted DWARF version to avoid issues with 0.5.6 on macOS
djspiewak Dec 27, 2024
3a88218
Started noodling with kqueue interrupts
djspiewak Dec 27, 2024
e01f25b
Rewrote most of the kqueue stuff to be simpler
djspiewak Dec 28, 2024
06b0a65
Forgot to bump the base version
djspiewak Dec 28, 2024
ca7c89d
Enabled concurrent `Ref` on native
djspiewak Dec 28, 2024
081bc56
Make kqueue compatible with parallel GC on SN
djspiewak Dec 28, 2024
b0caa11
Enabled higher iterations from `ContSpec` on native
djspiewak Dec 28, 2024
6e75e13
Made `Deferred` parallelism specs common across JVM and native
djspiewak Dec 28, 2024
65fd3e2
Shifted JVM `IO` functionality to share with native
djspiewak Dec 28, 2024
e818c50
Made `Dispatcher` functionality common across JVM and native
djspiewak Dec 28, 2024
dfc9a17
Enabled higher parallelism on native queue specs
djspiewak Dec 28, 2024
eab5150
Skip `Dispatcher` interruption spec for the time being
djspiewak Dec 28, 2024
22110b6
Generalized high precision native `nowMicros`
djspiewak Dec 28, 2024
f86ed07
Restored syscall-reducing optimization in kqueue implementation
djspiewak Dec 28, 2024
4ec0a9a
Swapped out LongMap for TrieMap for callbacks in kqueue
djspiewak Dec 28, 2024
47befdd
prePR
djspiewak Dec 28, 2024
5804694
Shifted JVM-specific `MapRef` support to share with native
djspiewak Dec 28, 2024
72c7098
A bit of yak shaving for scala 3 and unused warnings
djspiewak Dec 28, 2024
bb84b42
Factored non-JVM-specific highly concurrent `IO` specs out to be shar…
djspiewak Dec 28, 2024
010a820
Factored `kevent64` out into blocking and non-blocking variants (also…
djspiewak Dec 28, 2024
0b545af
Merge branch 'series/3.x' into wip/multithreaded-wstp
djspiewak Dec 28, 2024
f4bc66a
EpollSystem: fix stackallocs; use TrieMap
durban Dec 31, 2024
ca750c9
Fix `nativeRunner` setting
armanbilge Jan 2, 2025
affc37c
Formatting
armanbilge Jan 2, 2025
77379c2
Use `sizeof` with `stackalloc`
armanbilge Jan 2, 2025
48d92dd
mulithreadify `IOApp`
armanbilge Jan 2, 2025
4dcb142
Delete single-thread native runtimes
armanbilge Jan 2, 2025
d5568bd
Regenerate workflow
armanbilge Jan 2, 2025
76e2df6
organize imports
armanbilge Jan 2, 2025
7859974
Share `SleepSystem`
armanbilge Jan 2, 2025
833ce4a
Fix bincompat
armanbilge Jan 2, 2025
cefddb2
Fix Scala 3 compile
armanbilge Jan 2, 2025
767c465
`EpollSystem` fixups
armanbilge Jan 2, 2025
b0e4ccf
use constant val defns in `LocalQueueConstants`
armanbilge Jan 2, 2025
4856714
Restore native+macos+JDK21 jobs to matrix
armanbilge Jan 2, 2025
651be36
Tweak filter
armanbilge Jan 2, 2025
53abc4d
`stackalloc` considered harmful
djspiewak Jan 3, 2025
22271cc
Split `epoll_wait` into blocking and non-blocking variants
djspiewak Jan 3, 2025
81ace6e
Restore `encodeKevent`
armanbilge Jan 3, 2025
024fe66
Restore kqueue event buffering
armanbilge Jan 5, 2025
c723bbc
Avoid `stackalloc` and `sizeof`
armanbilge Jan 5, 2025
09bc339
Formatting
armanbilge Jan 5, 2025
704c914
Fix `epoll_wait` invocation
armanbilge Jan 5, 2025
2eee55d
Fix more `stackalloc`s / `sizeof`s
armanbilge Jan 5, 2025
8f32402
Merge remote-tracking branch 'upstream/series/3.x' into wip/multithre…
armanbilge Mar 6, 2025
7e90b62
Update headers
armanbilge Mar 6, 2025
0bb46bb
Made thread interruption test JVM-only
djspiewak Mar 6, 2025
7709802
Fun fact: you can get weird publication issues on this field!
djspiewak Mar 6, 2025
8c11f61
Increased timeout for stack safety test
djspiewak Mar 6, 2025
ee2200b
Merge remote-tracking branch 'arman/fix/cached-threads-transfer-queue…
djspiewak Mar 7, 2025
f51de08
Revert "Fun fact: you can get weird publication issues on this field!"
djspiewak Mar 7, 2025
0fa5c21
Merge branch 'series/3.x' into wip/multithreaded-wstp
djspiewak Mar 7, 2025
23590c1
Declare constants properly
armanbilge Mar 7, 2025
d997aa8
Formatting
armanbilge Mar 7, 2025
9617486
Bump to SN 0.5.7
armanbilge Mar 7, 2025
dc09477
Fix return type
armanbilge Mar 7, 2025
580a169
Fix compile
armanbilge Mar 7, 2025
e1296ad
Add Cirrus high-core-count jobs for Native
armanbilge Mar 7, 2025
a8b8f7a
Reverted back to 0.5.6
djspiewak Mar 14, 2025
112ac9b
Adjusted all test timeouts for SN
djspiewak Mar 16, 2025
82127c2
Fixed numeric widening
djspiewak Mar 16, 2025
e472665
Merge branch 'series/3.x' into wip/multithreaded-wstp
djspiewak Mar 16, 2025
f3303d1
Wow that's a weird divergence between the branches…
djspiewak Mar 16, 2025
31c1b35
Configure JMM final field semantics for `TimerHeap.Node`
armanbilge Mar 20, 2025
d944d47
Set `GC_MAXIMUM_HEAP_SIZE`
armanbilge Mar 20, 2025
5e9ec78
No parallel execution in CI
armanbilge Mar 20, 2025
d776666
More heap
armanbilge Mar 20, 2025
7e52334
Disable fiber monitoring
armanbilge Mar 20, 2025
62dedd3
Split fiber monitoring for native and disable entirely
djspiewak Mar 20, 2025
7075331
Revert "Split fiber monitoring for native and disable entirely"
djspiewak Mar 20, 2025
1cfb736
Try again to disable fiber monitoring
armanbilge Mar 20, 2025
2a234fc
Bump `tlVersionIntroduced`
armanbilge Mar 20, 2025
e97762c
Fix `test-native.sh`
armanbilge Mar 20, 2025
17bff81
Split JS and Native example apps
djspiewak Mar 23, 2025
1237a37
Merge pull request #4311 from typelevel/release/3.6.0-minor
djspiewak Mar 23, 2025
bad071e
Merge branch 'release/3.6.0-major' into wip/multithreaded-wstp
djspiewak Mar 23, 2025
55c465c
Ignore mima issues with package-private stuff touched by the fiber mo…
djspiewak Mar 23, 2025
9a83de2
Restore GraalVM Native Image test in CI
armanbilge Mar 24, 2025
315feb7
Merge pull request #4315 from armanbilge/restore-native-image-ci
djspiewak Mar 24, 2025
a13bcee
Use `ConcurrentHashMap` for tracing
armanbilge Mar 26, 2025
7dab7b8
Use epoll_eventTag instead of sizeof
durban Mar 28, 2025
817236f
Properly close interruptFd even in case of init error
durban Mar 29, 2025
88530ce
CUnsignedInt is not, in fact, 64 bits
durban Mar 29, 2025
946d771
Be very careful when installing signal handlers
durban Mar 29, 2025
11f276e
Let's try something silly
durban Mar 29, 2025
2fafd1d
Rewrote Signal.installHandler in C
durban Mar 30, 2025
985b2ec
Fix 2.12 compile
durban Mar 30, 2025
70490aa
Increased SN heap size as a temporary workaround
djspiewak Mar 30, 2025
52710ff
Fixed some copy/paste leftbehinds in `IOApp`
djspiewak Mar 30, 2025
a356c28
Fixed silly compilation error
djspiewak Mar 30, 2025
9e65eb4
Compare Float with Float
durban Mar 30, 2025
af857e5
Disambiguated file names in native sources
djspiewak Mar 30, 2025
8f2b497
Lengthened blocking starvation timeout on native
djspiewak Mar 30, 2025
62a8445
Move WSTP metrics to jvm-native
iRevive Apr 2, 2025
b3c08f5
Also interrupt pollers when shutting down the WSTP
durban Apr 2, 2025
8dcc7dd
Revert "Also interrupt pollers when shutting down the WSTP"
durban Apr 3, 2025
8e00c91
Also interrupt pollers when shutting down the WSTP
durban Apr 3, 2025
a2dae56
Add test
durban Apr 3, 2025
1868e91
scalafmt
durban Apr 3, 2025
caf1451
Much simpler test
durban Apr 3, 2025
99e6787
Merge branch 'series/3.x' into fixWstpShutdownInterrupt
djspiewak Apr 3, 2025
d6b5021
Fixed broken formatting merge
djspiewak Apr 4, 2025
4972921
Merge branch 'fixWstpShutdownInterrupt' into wip/multithreaded-wstp
djspiewak Apr 4, 2025
b5b0db9
Namespace and conditionally compile `signal_helper.c`
armanbilge Apr 4, 2025
24afb1d
Fix some docstrings
durban Apr 4, 2025
948d68c
Fix more docstrings
durban Apr 4, 2025
9ce1dfa
Prefer System.exit
durban Apr 4, 2025
c33d887
Clarify difference between exit and halt, add TODO comment
durban Apr 4, 2025
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
13 changes: 13 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ jvm_highcore_task:
script: sbt '++ 2.13' testsJVM/test ioAppTestsJVM/test
- name: JVM high-core-count 3
script: sbt '++ 3' testsJVM/test ioAppTestsJVM/test

native_highcore_task:
only_if: $CIRRUS_TAG != '' || $CIRRUS_PR != ''
required_pr_labels: Cirrus Native
container:
dockerfile: .cirrus/Dockerfile
cpu: 8
memory: 16G
matrix:
- name: Native high-core-count 2.13
script: sbt '++ 2.13' testsNative/test ioAppTestsNative/test
- name: Native high-core-count 3
script: sbt '++ 3' testsNative/test ioAppTestsNative/test
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ jobs:
java: temurin@11
- scala: 3.3.5
java: temurin@21
- scala: 3.3.5
java: graalvm@21
- scala: 2.12.20
java: temurin@11
- scala: 2.12.20
Expand Down Expand Up @@ -325,6 +323,11 @@ jobs:
shell: bash
run: example/test-native.sh ${{ matrix.scala }}

- name: Test GraalVM Native Image
if: (matrix.scala == '2.13.16' || matrix.scala == '3.3.5') && matrix.java == 'graalvm@21' && matrix.os == 'ubuntu-latest'
shell: bash
run: sbt '++ ${{ matrix.scala }}' graalVMExample/nativeImage graalVMExample/nativeImageRun

- name: Scalafix tests
if: matrix.scala == '2.13.16' && matrix.ci == 'ciJVM' && matrix.os == 'ubuntu-latest'
shell: bash
Expand Down Expand Up @@ -667,5 +670,5 @@ jobs:
- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: cats-effect-benchmarks_3 cats-effect-benchmarks_2.12 cats-effect-benchmarks_2.13 cats-effect_3 cats-effect_2.12 cats-effect_2.13 cats-effect-example_sjs1_3 cats-effect-example_sjs1_2.12 cats-effect-example_sjs1_2.13 rootjs_3 rootjs_2.12 rootjs_2.13 ioapptestsnative_3 ioapptestsnative_2.12 ioapptestsnative_2.13 cats-effect-graalvm-example_3 cats-effect-graalvm-example_2.12 cats-effect-graalvm-example_2.13 cats-effect-tests_sjs1_3 cats-effect-tests_sjs1_2.12 cats-effect-tests_sjs1_2.13 rootjvm_3 rootjvm_2.12 rootjvm_2.13 rootnative_3 rootnative_2.12 rootnative_2.13 cats-effect-example_native0.4_3 cats-effect-example_native0.4_2.12 cats-effect-example_native0.4_2.13 cats-effect-example_3 cats-effect-example_2.12 cats-effect-example_2.13 cats-effect-tests_3 cats-effect-tests_2.12 cats-effect-tests_2.13 ioapptestsjvm_3 ioapptestsjvm_2.12 ioapptestsjvm_2.13 ioapptestsjs_3 ioapptestsjs_2.12 ioapptestsjs_2.13 cats-effect-tests_native0.4_3 cats-effect-tests_native0.4_2.12 cats-effect-tests_native0.4_2.13
modules-ignore: cats-effect-benchmarks_3 cats-effect-benchmarks_2.12 cats-effect-benchmarks_2.13 cats-effect_3 cats-effect_2.12 cats-effect_2.13 cats-effect-example_sjs1_3 cats-effect-example_sjs1_2.12 cats-effect-example_sjs1_2.13 rootjs_3 rootjs_2.12 rootjs_2.13 ioapptestsnative_3 ioapptestsnative_2.12 ioapptestsnative_2.13 cats-effect-graalvm-example_3 cats-effect-graalvm-example_2.12 cats-effect-graalvm-example_2.13 cats-effect-tests_sjs1_3 cats-effect-tests_sjs1_2.12 cats-effect-tests_sjs1_2.13 rootjvm_3 rootjvm_2.12 rootjvm_2.13 rootnative_3 rootnative_2.12 rootnative_2.13 cats-effect-example_native0.5_3 cats-effect-example_native0.5_2.12 cats-effect-example_native0.5_2.13 cats-effect-example_3 cats-effect-example_2.12 cats-effect-example_2.13 cats-effect-tests_3 cats-effect-tests_2.12 cats-effect-tests_2.13 ioapptestsjvm_3 ioapptestsjvm_2.12 ioapptestsjvm_2.13 ioapptestsjs_3 ioapptestsjs_2.12 ioapptestsjs_2.13 cats-effect-tests_native0.5_3 cats-effect-tests_native0.5_2.12 cats-effect-tests_native0.5_2.13
configs-ignore: test scala-tool scala-doc-tool test-internal
55 changes: 41 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxProfile}
import org.scalajs.jsenv.nodejs.NodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv
import sbtcrossproject.CrossProject
import scala.scalanative.build._

import JSEnv._

lazy val inCI = Option(System.getenv("CI")).contains("true")

// sbt-git workarounds
ThisBuild / useConsoleForROGit := !Option(System.getenv("CI")).contains("true")
ThisBuild / useConsoleForROGit := !inCI

ThisBuild / git.gitUncommittedChanges := {
if ((ThisBuild / githubIsWorkflowBuild).value) {
Expand All @@ -40,7 +43,7 @@ ThisBuild / git.gitUncommittedChanges := {
}
}

ThisBuild / tlBaseVersion := "3.6"
ThisBuild / tlBaseVersion := "3.7"
ThisBuild / tlUntaggedAreSnapshots := false

ThisBuild / organization := "org.typelevel"
Expand Down Expand Up @@ -201,6 +204,12 @@ ThisBuild / githubWorkflowBuild := Seq("JVM", "JS", "Native").map { platform =>
name = Some("Test Example Native App Using Binary"),
cond = Some(s"matrix.ci == 'ciNative' && matrix.os == '$PrimaryOS'")
),
WorkflowStep.Sbt(
List("graalVMExample/nativeImage", "graalVMExample/nativeImageRun"),
name = Some("Test GraalVM Native Image"),
cond = Some(
s"(matrix.scala == '$Scala213' || matrix.scala == '$Scala3') && matrix.java == '${GraalVM.render}' && matrix.os == '$PrimaryOS'")
),
WorkflowStep.Run(
List("cd scalafix", "sbt test"),
name = Some("Scalafix tests"),
Expand All @@ -224,7 +233,7 @@ ThisBuild / githubWorkflowBuildMatrixExclusions := {
val scalaJavaFilters = for {
scala <- (ThisBuild / githubWorkflowScalaVersions).value.filterNot(Set(Scala213))
java <- (ThisBuild / githubWorkflowJavaVersions).value.filterNot(Set(OldGuardJava))
if !(scala == Scala3 && java == LatestJava)
if !(scala == Scala3 && (java == LatestJava || java == GraalVM))
} yield MatrixExclude(Map("scala" -> scala, "java" -> java.render))

val armFilters =
Expand Down Expand Up @@ -316,13 +325,13 @@ ThisBuild / autoAPIMappings := true

ThisBuild / Test / testOptions += Tests.Argument("+l")

val CatsVersion = "2.11.0"
val CatsMtlVersion = "1.3.1"
val ScalaCheckVersion = "1.17.1"
val CoopVersion = "1.2.0"
val MUnitVersion = "1.0.0-M11"
val MUnitScalaCheckVersion = "1.0.0-M11"
val DisciplineMUnitVersion = "2.0.0-M3"
val CatsVersion = "2.12.0"
val CatsMtlVersion = "1.5.0"
val ScalaCheckVersion = "1.18.1"
val CoopVersion = "1.3.0"
val MUnitVersion = "1.1.0"
val MUnitScalaCheckVersion = "1.1.0"
val DisciplineMUnitVersion = "2.0.0"

val MacrotaskExecutorVersion = "1.1.1"

Expand Down Expand Up @@ -352,6 +361,17 @@ Global / tlCommandAliases ++= Map(
)
)

lazy val nativeTestSettings = Seq(
nativeConfig ~= { c => // TODO: remove this when it seems to work
c.withSourceLevelDebuggingConfig(_.enableAll) // enable generation of debug information
.withOptimize(false) // disable Scala Native optimizer
.withMode(Mode.debug) // compile using LLVM without optimizations
.withCompileOptions(c.compileOptions ++ Seq("-gdwarf-4"))
},
envVars ++= { if (inCI) Map("GC_MAXIMUM_HEAP_SIZE" -> "8g") else Map.empty[String, String] },
parallelExecution := !inCI
)

val jsProjects: Seq[ProjectReference] =
Seq(
kernel.js,
Expand Down Expand Up @@ -435,7 +455,7 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform, NativePlatform)
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % MacrotaskExecutorVersion % Test
)
.nativeSettings(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.5.0"
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.6.0"
)

/**
Expand Down Expand Up @@ -881,7 +901,12 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
ProblemFilters.exclude[MissingClassProblem](
"cats.effect.metrics.JsCpuStarvationMetrics"),
ProblemFilters.exclude[MissingClassProblem](
"cats.effect.metrics.JsCpuStarvationMetrics$")
"cats.effect.metrics.JsCpuStarvationMetrics$"),
// all package-private classes; introduced when we made Native multithreaded
ProblemFilters.exclude[MissingClassProblem]("cats.effect.unsafe.FiberExecutor"),
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"cats.effect.unsafe.FiberMonitorImpl.this"),
ProblemFilters.exclude[MissingClassProblem]("cats.effect.unsafe.FiberMonitorPlatform")
)
},
mimaBinaryIssueFilters ++= {
Expand Down Expand Up @@ -938,6 +963,7 @@ lazy val testkit = crossProject(JSPlatform, JVMPlatform, NativePlatform)
"org.scalacheck" %%% "scalacheck" % ScalaCheckVersion
)
)
.nativeSettings(nativeTestSettings)

/**
* Unit tests for the core project, utilizing the support provided by testkit.
Expand Down Expand Up @@ -969,7 +995,8 @@ lazy val tests: CrossProject = crossProject(JSPlatform, JVMPlatform, NativePlatf
Test / javaOptions += "-Dcats.effect.trackFiberContext=true"
)
.nativeSettings(
Compile / mainClass := Some("catseffect.examples.NativeRunner")
Compile / mainClass := Some("catseffect.examples.NativeRunner"),
nativeTestSettings
)

def configureIOAppTests(p: Project): Project =
Expand All @@ -980,7 +1007,7 @@ def configureIOAppTests(p: Project): Project =
buildInfoPackage := "cats.effect",
buildInfoKeys ++= Seq(
"jsRunner" -> (tests.js / Compile / fastOptJS / artifactPath).value,
"nativeRunner" -> (tests.native / Compile / nativeLink / artifactPath).value
"nativeRunner" -> (tests.native / Compile / crossTarget).value / (tests.native / Compile / moduleName).value
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ import scala.scalajs.{js, LinkingInfo}
private[effect] final class BatchingMacrotaskExecutor(
batchSize: Int,
reportFailure0: Throwable => Unit
) extends ExecutionContextExecutor
with FiberExecutor {
) extends ExecutionContextExecutor {

private[this] val queueMicrotask: js.Function1[js.Function0[Any], Any] =
if (js.typeOf(js.Dynamic.global.queueMicrotask) == "function")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package cats.effect
package unsafe

import scala.concurrent.ExecutionContext
import scala.scalajs.{js, LinkingInfo}

private[effect] sealed abstract class FiberMonitor extends FiberMonitorShared {

/**
Expand All @@ -41,8 +44,8 @@ private[effect] sealed abstract class FiberMonitor extends FiberMonitorShared {

private final class FiberMonitorImpl(
// A reference to the compute pool of the `IORuntime` in which this suspended fiber bag
// operates. `null` if the compute pool of the `IORuntime` is not a `FiberExecutor`.
private[this] val compute: FiberExecutor
// operates. `null` if the compute pool of the `IORuntime` is not a `BatchingMacrotaskExecutor`.
private[this] val compute: BatchingMacrotaskExecutor
) extends FiberMonitor {
private[this] val bag = new WeakBag[IOFiber[?]]()

Expand Down Expand Up @@ -92,4 +95,26 @@ private final class NoOpFiberMonitor extends FiberMonitor {
def liveFiberSnapshot(print: String => Unit): Unit = ()
}

private[effect] object FiberMonitor extends FiberMonitorPlatform
private[effect] object FiberMonitor {
def apply(compute: ExecutionContext): FiberMonitor = {
if (LinkingInfo.developmentMode && weakRefsAvailable) {
if (compute.isInstanceOf[BatchingMacrotaskExecutor]) {
val bmec = compute.asInstanceOf[BatchingMacrotaskExecutor]
new FiberMonitorImpl(bmec)
} else {
new FiberMonitorImpl(null)
}
} else {
new NoOpFiberMonitor()
}
}

private[this] final val Undefined = "undefined"

/**
* Feature-tests for all the required, well, features :)
*/
private[unsafe] def weakRefsAvailable: Boolean =
js.typeOf(js.Dynamic.global.WeakRef) != Undefined &&
js.typeOf(js.Dynamic.global.FinalizationRegistry) != Undefined
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ private[effect] final class NoOpFiberMonitor extends FiberMonitor(null) {
}

private[effect] object FiberMonitor {
def apply(compute: ExecutionContext): FiberMonitor = {
def apply(compute: ExecutionContext): FiberMonitor = if (Platform.isJvm) {
if (TracingConstants.isStackTracing && compute.isInstanceOf[WorkStealingThreadPool[?]]) {
val wstp = compute.asInstanceOf[WorkStealingThreadPool[?]]
new FiberMonitor(wstp)
} else {
new FiberMonitor(null)
}
}
} else new NoOpFiberMonitor
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import java.time.temporal.ChronoField
import java.util.concurrent.{Executors, ScheduledExecutorService}

private[unsafe] abstract class SchedulerCompanionPlatform { this: Scheduler.type =>
def createDefaultScheduler(): (Scheduler, () => Unit) = {

def createDefaultScheduler(): (Scheduler, () => Unit) =
createDefaultScheduler("io-scheduler")

def createDefaultScheduler(threadPrefix: String): (Scheduler, () => Unit) = {
val scheduler = Executors.newSingleThreadScheduledExecutor { r =>
val t = new Thread(r)
t.setName("io-scheduler")
t.setName(threadPrefix)
t.setDaemon(true)
t.setPriority(Thread.MAX_PRIORITY)
t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import scala.annotation.tailrec
import java.util.Arrays
import java.util.concurrent.atomic.AtomicInteger

import Platform.safePublish

/**
* A specialized heap that serves as a priority queue for timers i.e. callbacks with trigger
* times.
Expand Down Expand Up @@ -486,6 +488,7 @@ private final class TimerHeap extends AtomicInteger {

override def toString() = if (size > 0) "TimerHeap(...)" else "TimerHeap()"

@safePublish
private final class Node(
val triggerTime: Long,
private[this] var callback: Right[Nothing, Unit] => Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import scala.collection.mutable
import scala.concurrent.ExecutionContextExecutor
import scala.concurrent.duration.{Duration, FiniteDuration}

import java.time.Instant
import java.time.temporal.ChronoField
import java.util.concurrent.{LinkedTransferQueue, ThreadLocalRandom}
import java.util.concurrent.atomic.{
AtomicBoolean,
Expand Down Expand Up @@ -77,7 +75,8 @@ private[effect] final class WorkStealingThreadPool[P <: AnyRef](
private[unsafe] val uncaughtExceptionHandler: Thread.UncaughtExceptionHandler
) extends ExecutionContextExecutor
with Scheduler
with UnsealedPollingContext[P] {
with UnsealedPollingContext[P]
with WorkStealingThreadPoolPlatform[P] {

import TracingConstants._
import WorkStealingThreadPoolConstants._
Expand Down Expand Up @@ -629,11 +628,6 @@ private[effect] final class WorkStealingThreadPool[P <: AnyRef](

override def nowMillis(): Long = System.currentTimeMillis()

override def nowMicros(): Long = {
val now = Instant.now()
now.getEpochSecond() * 1000000 + now.getLong(ChronoField.MICRO_OF_SECOND)
}

/**
* Tries to call the current worker's `sleep`, but falls back to `sleepExternal` if needed.
*/
Expand Down Expand Up @@ -710,6 +704,7 @@ private[effect] final class WorkStealingThreadPool[P <: AnyRef](
while (i < threadCount) {
val workerThread = workerThreads.get(i)
if (workerThread ne currentThread) {
system.interrupt(workerThread, pollers(i))
workerThread.interrupt()
}
i += 1
Expand Down
10 changes: 9 additions & 1 deletion core/jvm/src/main/scala/cats/effect/IOApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ trait IOApp {
*/
protected def runtimeConfig: unsafe.IORuntimeConfig = unsafe.IORuntimeConfig()

/**
* The [[unsafe.PollingSystem]] used by the [[runtime]] which will evaluate the [[IO]]
* produced by `run`. It is very unlikely that users will need to override this method.
*
* [[unsafe.PollingSystem]] implementors may provide their own flavors of [[IOApp]] that
* override this method.
*/
protected def pollingSystem: unsafe.PollingSystem =
unsafe.IORuntime.createDefaultPollingSystem()

Expand All @@ -182,7 +189,8 @@ trait IOApp {
* beyond a few percentage points, and the default value is optimal (or close to optimal) in
* ''most'' common scenarios.
*
* '''This setting is JVM-specific and will not compile on JavaScript.'''
* '''This setting is specific to the JVM and Scala Native, and will not compile on
* JavaScript.'''
*
* For more details on Cats Effect's runtime threading model please see
* [[https://typelevel.org/cats-effect/docs/thread-model]].
Expand Down
Loading
Loading