Skip to content

Latest commit

 

History

History
105 lines (98 loc) · 6.65 KB

DRAFT_IDEAS.md

File metadata and controls

105 lines (98 loc) · 6.65 KB

A few code and design ideas, that may or may not be implemented

  • Jayo loves Kotlin !
    • Support Kotlin specific types like Sequence<T>, kotlin.time.DurationUnit, and maybe some coroutine's stuff like Flow<T> must only be implemented as extension functions (= Java will not see it).
    • If any Kotlin specific dependency has to be supported ( kotlinx.coroutines ?), it must be declared as compileOnly in gradle build.
    • Expose Type-safe Builders for Kotlin to configure client and server options
  • For server modules : a platform Thread can be used to Accept incoming connections, and virtual thread will handle all the rest.
  • Servers will have a close method (from AutoClosable) that will refuse new incoming connections and requests, but will wait until current responses are returned. A closeImmediatly could be provided also, that aggressively closes immediately.
  • Shenandoah and ZGC new garbage collectors are available now, and improvements have been added to the other garbage collectors like G1. We could provide a guideline to GC configuration for Jayo users.

Nice Java features Jayo will or could use

  • Java 1.8
  • Java 9
    • Project Jigsaw JPMS modules
    • Compact Strings : The new String class store characters encoded either as ISO-8859-1/Latin-1 (one byte per character), or as UTF-16 (two bytes per character).
  • Java 11
    • Adds TLSv1.3 support
  • Java 13
  • Java 14
  • Java 15
  • Java 16
  • Java 18
  • Java 19
  • Java 20
    • Scoped Values (incubator)
  • Java 21
    • Project Loom virtual threads are promoted as stable
    • Warning -> preview : Structured Concurrency treats multiple tasks running in different threads as a single unit of work, thereby streamlining error handling and cancellation, improving reliability, and enhancing observability.
    • Warning -> preview : Scoped Values enable the sharing of immutable data within and across threads. They are preferred to thread-local variables, especially when using large numbers of virtual threads.
    • Sequenced Collections This feature injects new interfaces into the existing Java collections hierarchy, offering a seamless mechanism to access the first and last elements of a collection using built-in default methods. Moreover, it provides support to obtain a reversed view of the collection.
  • Java 22
    • Foreign memory is promoted as stable. Sophisticated clients deserve an API that can allocate, manipulate, and share off-heap memory with the same fluidity and safety as on-heap memory. Such an API should balance the need for predictable deallocation with the need to prevent untimely deallocation that can lead to JVM crashes or, worse, to silent memory corruption.

Race condition

Avoiding race conditions is an art, to avoid them when mutating a Segment (= a write, transfer or remove operation), we must follow a few steps in this exact order :

  1. switch the Segment state to the desired state
  2. modify pos or limit
  3. increase or decrease the byte size of the SegmentQueue
  4. atomically compareAndSet the TAIL or the HEAD
  5. (optional) atomically update the NEXT segment
  6. end the operation by resetting the Segment state to AVAILABLE, or recycle it in the segment pool if this segment was fully read

We must battle test these potential race conditions with a lot of tests and benchmarks, sometimes with some Random involved to create all sorts of weird use cases !

Some inspirations