Class UnsafeMemoryAccessDeprecationExamples
java.lang.Object
net.jrodolfo.java_evolution.java23.unsafe_memory_access_deprecation.UnsafeMemoryAccessDeprecationExamples
Demonstrates Java 23's migration pressure away from
sun.misc.Unsafe
memory-access methods.
The main project source deliberately does not import sun.misc.Unsafe.
Instead, this example writes a tiny child source file, compiles it with
javac -Xlint:removal, and captures the deprecation-for-removal
diagnostics. It also runs the child class with
--sun-misc-unsafe-memory-access=deny to show the runtime boundary.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCaptures a child process result. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncompileUnsafeMemoryAccessProbe(Path workDirectory) Compiles the generated child source and captures compiler diagnostics.createUnsafeMemoryAccessProbe(Path sourceDirectory) Writes the generated child source used only for migration-boundary testing.Explains whysun.misc.Unsafeappears only in generated child source.Explains the migration lesson.runUnsafeProbeWithDeny(Path workDirectory) Runs the generated child class with unsafe memory access denied.intupdateWithVarHandle(int replacementValue) Demonstrates the supported replacement direction for ordinary variable access.
-
Constructor Details
-
UnsafeMemoryAccessDeprecationExamples
public UnsafeMemoryAccessDeprecationExamples()
-
-
Method Details
-
createUnsafeMemoryAccessProbe
Writes the generated child source used only for migration-boundary testing.- Parameters:
sourceDirectory- directory where the probe source should be written- Returns:
- path to the generated source file
- Throws:
IOException- when the source file cannot be written
-
compileUnsafeMemoryAccessProbe
public UnsafeMemoryAccessDeprecationExamples.ProcessResult compileUnsafeMemoryAccessProbe(Path workDirectory) throws IOException, InterruptedException Compiles the generated child source and captures compiler diagnostics.- Parameters:
workDirectory- directory where source and class files should be created- Returns:
- the child process result
- Throws:
IOException- when files cannot be written orjavaccannot be startedInterruptedException- when interrupted while waiting forjavac
-
runUnsafeProbeWithDeny
public UnsafeMemoryAccessDeprecationExamples.ProcessResult runUnsafeProbeWithDeny(Path workDirectory) throws IOException, InterruptedException Runs the generated child class with unsafe memory access denied.- Parameters:
workDirectory- directory where source and class files should be created- Returns:
- the child process result
- Throws:
IOException- when files cannot be written or the child JVM cannot be startedInterruptedException- when interrupted while waiting for the child JVM
-
updateWithVarHandle
Demonstrates the supported replacement direction for ordinary variable access.- Parameters:
replacementValue- value to store through aVarHandle- Returns:
- the value read back through the same supported API
- Throws:
ReflectiveOperationException- when the field handle cannot be created
-
exampleBoundary
Explains whysun.misc.Unsafeappears only in generated child source.- Returns:
- a short boundary explanation
-
migrationLesson
-