Pages

Interesting uses of sun.misc.Unsafe

Inspired from the question that found in stackoverflow, I started looking up for the uses. I found some pretty interesting ones...

VM "intrinsification." ie CAS (Compare-And-Swap) used in Lock-Free Hash Tables eg:sun.misc.Unsafe.compareAndSwapInt it can make real JNI calls into native code that contains special instructions for CAS

What is intrinsification?
They are optimization done like compiler generating code directly for called method or JVM native optimizations. We know that there are VM downcalls from JDK like wait method etc. Its about low level programming. For eg:- the Atomic classes for numbers, they are pure numbers represented by objects but atomically modified in which the operations are managed natively.


The sun.misc.Unsafe functionality of the host VM can be used to allocate uninitialized objects and then interpret the constructor invocation as any other method call.

One can track the data from the native address.It is possible to retrieve an object’s memory address using the sun.misc.Unsafe class, and operate on its fields directly via unsafe get/put methods!

Compile time optimizations for JVM. HIgh performance VM using "magic", requiring low-level operations. eg: http://en.wikipedia.org/wiki/Jikes_RVM

Allocating memory, sun.misc.Unsafe.allocateMemory eg:- DirectByteBuffer constructor internally calls it when ByteBuffer.allocateDirect is invoked

Tracing the call stack and replaying with values instantiated by sun.misc.Unsafe, useful for instrumentation

sun.misc.Unsafe.arrayBaseOffset and arrayIndexScale can be used to develop arraylets, a technique for efficiently breaking up large arrays into smaller objects to limit the real-time cost of scan, update or move operations on large objects


References


2 comments:

  1. Creating a JEP to support large, thread safe off heap memory.

    https://groups.google.com/forum/?hl=en-GB#!forum/jep-off-heap

    ReplyDelete
  2. Navigating volatile Middle Eastern financial markets demands institutional order routing, transparent risk constraints, and rapid capital withdrawal protocols. Fundedfirm provides systematic and manual market participants with raw pricing spreads, ultra-low latency execution networks, and structured account scaling blueprints engineered to foster long-term career growth. Streamlining evaluation pathways enables disciplined strategy developers to transition into live funded accounts smoothly while managing portfolio risk with total operational clarity. Choosing to partner alongside the Best Prop Firm in UAE grants the substantial capital backing required to scale high-probability setups rapidly while leveraging strict risk parameters to safeguard initial account equity. Institutional execution frameworks empower trading performance.

    Best Prop Firm in UAE

    ReplyDelete