惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
Y
Y Combinator Blog
博客园_首页
有赞技术团队
有赞技术团队
博客园 - Franky
腾讯CDC
G
Google Developers Blog
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
D
Docker
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
V
V2EX
U
Unit 42
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stop Guessing Your Cache Locality: Verify JEP 401 Value C...
Machine coding Master · 2026-06-22 · via DEV Community

Machine coding Master

Stop Guessing Your Cache Locality: Verify JEP 401 Value Class Flattening with JFR

JEP 401 value classes are a massive win for memory density, but too many developers are cargo-culting them and assuming the JVM automatically flattens their data. If you aren't actively verifying your memory layouts with JFR and JOL, you are likely still paying the tax of pointer indirection and GC pressure.

Why Most Developers Get This Wrong

  • Assuming value class equals flat layout: Declaring a class as a value class is only a hint; if it is nullable or too large, the JVM silently falls back to standard heap buffering.
  • Relying solely on microbenchmarks: JMH benchmarks can deceive you in isolated, warm-up environments where the compiler optimizes away allocations that actually occur in production.
  • Ignoring null-restriction: Skipping the explicit null-restricted type operator (!) means the JVM must allow for null, completely destroying any chance of array flattening.

The Right Way

You must combine static layout validation via JOL with dynamic allocation profiling using JDK Flight Recorder (JFR) to guarantee zero-allocation execution paths.

  • Assert layouts in tests: Use Java Object Layout (JOL) in your unit tests to programmatically assert the exact byte offset and verify the absence of object headers for nested fields.
  • Profile with JFR events: Monitor jdk.ObjectAllocationInNewTLAB and jdk.ObjectAllocationOutsideTLAB events on your hot paths to ensure your value types show zero allocations.
  • Enforce null-restriction: Always use the ! operator (e.g., Point!) on fields and arrays to explicitly opt-out of nullability and force the JVM to flatten the memory footprint.

Shameless plug: javalld.com has full LLD implementations with step-by-step execution traces — free to use while prepping.

Show Me The Code

// JEP 401 Value Class definition
public value class Point {
    int x;
    int y;
}

public class PathTracker {
    // The '!' operator forces null-restriction, enabling array flattening
    private Point![] coordinates = new Point![1000]; 

    public void updatePath(int index, int x, int y) {
        // Flat array write: compiles to direct memory writes, zero JFR allocation events
        coordinates[index] = new Point(x, y); 
    }
}

Key Takeaways

  • No exclamation, no flattening: Without the ! null-restriction operator, your value classes are just typical heap-allocated objects with a fancy keyword.
  • Automate verification: Put JOL assertions directly into your CI pipeline to catch accidental layout bloating before it hits main.
  • Trust JFR, not assumptions: Use JFR in your staging environment to verify that your critical execution loops are completely free of object allocation samples.