Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
durban committed Nov 3, 2024
1 parent d34eb54 commit 69cbfda
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ lazy val mcas = crossProject(JVMPlatform, JSPlatform)
// there is no backward compat for `choam-mcas`:
ProblemFilters.exclude[DirectMissingMethodProblem]("dev.tauri.choam.internal.mcas.Descriptor.versionCas"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("dev.tauri.choam.internal.mcas.AbstractDescriptor.hwdIterator"),
ProblemFilters.exclude[DirectMissingMethodProblem]("dev.tauri.choam.internal.mcas.LogEntry.cleanForGc"),
ProblemFilters.exclude[DirectMissingMethodProblem]("dev.tauri.choam.internal.mcas.WdLike.cleanForGc"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("dev.tauri.choam.internal.mcas.WdLike.wasFinalized"),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sealed trait WdLike[A] extends Hamt.HasKey[MemoryLocation[A]] {
def ov: A
def nv: A
val oldVersion: Long
def cleanForGc(wasSuccessful: Boolean, sentinel: A): Unit
def wasFinalized(wasSuccessful: Boolean, sentinel: A): Unit

final override def key: MemoryLocation[A] =
this.address
Expand All @@ -42,7 +42,7 @@ final class LogEntry[A] private ( // formerly called HWD

require(Version.isValid(oldVersion))

final override def cleanForGc(wasSuccessful: Boolean, sentinel: A): Unit =
final override def wasFinalized(wasSuccessful: Boolean, sentinel: A): Unit =
()

private[choam] final def cast[B]: LogEntry[B] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ private[mcas] final class EmcasDescriptor private[this] (
this.getOrInitFallback(fb)
}

// we can clean up to help the GC
// (even if we have to retry with
// the fallback, we already copied
// the array):
this.cleanWordsForGc(EmcasStatus.isSuccessful(finalResult))
this.wasFinalized(EmcasStatus.isSuccessful(finalResult))
}

private[emcas] final def fallback: EmcasDescriptor = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ final EmcasDescriptor getOrInitFallback(EmcasDescriptor candidate) {
}
}

final void cleanWordsForGc(boolean wasSuccessful) {
// We're the only ones cleaning, so
// `_words` is never `null` here:
final void wasFinalized(boolean wasSuccessful) {
// We can clean up to help the GC
// (even if we have to retry with
// the fallback, we already copied
// the array). We're the only ones
// cleaning up, so `_words` is never
// `null` here:
WdLike<?>[] words = this.getWordsO();
int len = words.length;
VarHandle.releaseFence();
Expand All @@ -124,7 +128,7 @@ final void cleanWordsForGc(boolean wasSuccessful) {
@SuppressWarnings("unchecked")
WdLike<Object> wd = (WdLike<Object>) words[idx];
WORDS_ARR.setOpaque(words, idx, (WdLike<?>) null);
wd.cleanForGc(wasSuccessful, sentinel);
wd.wasFinalized(wasSuccessful, sentinel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final A nv() {
return this.getNvP();
}

public final void cleanForGc(boolean wasSuccessful, A sentinel) {
public final void wasFinalized(boolean wasSuccessful, A sentinel) {
if (wasSuccessful) {
OV.setOpaque(this, sentinel);
} else {
Expand Down

0 comments on commit 69cbfda

Please sign in to comment.