Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

hello-ebpf

> 编程语言
Open source

Hello eBPF world! Hello Java world! Let's discover eBPF together and write Java user-land library along the way.

187 stars0 likes0 views
WebsiteGitHub

About

Hello eBPF world! Hello Java world! Let's discover eBPF together and write Java user-land library along the way.

Hello eBPF

There are user land libraries for eBPF that allow you to write eBPF applications in C++, Rust, Go, Python and even Lua. But there are none for Java, which is a pity. So... I decided to write my own, which allows you to write eBPF programs directly in Java.

This is still in the early stages, but you can already use it for developing small tools and more coming in the future.

Based on the overview from ebpf.io, duke image from OpenJDK.

Let's discover eBPF together. Join me on the journey and learn a lot about eBPF and Java along the way.

Example

Consider for a brief moment that you want to test how your server application behaves when every third incoming network packet is dropped. We can write a simple eBPF program to do this:

…

You can find this example as XDPDropEveryThirdPacket.java.

Features

Hooks

  • XDP — attach to network interfaces for high-speed packet filtering and forwarding. docs/xdp.md
  • TC (Traffic Control) — classify and manipulate packets at the TC layer for both ingress and egress. docs/tc.md
  • Kprobes / Kretprobes / Fentry / Fexit — instrument kernel functions dynamically, with multi-attach (kprobe.multi) support. docs/kprobes.md
  • Uprobes / Uretprobes — instrument user-space functions in any process or library. docs/uprobes.md
  • Tracepoints — attach to stable kernel tracepoints and raw tracepoints. docs/tracepoints.md
  • LSM & cgroup hooks — enforce security policies and resource controls directly from Java. docs/lsm.md
  • @StructOps — implement kernel struct_ops in Java: write a sched-ext CPU scheduler, TCP congestion controller, qdisc, or HID BPF driver as a plain Java interface. docs/struct-ops.md
  • sched_ext schedulers — full CPU scheduler framework built on @StructOps, including a userspace-scheduler bridge. docs/sched-ext/

Data & Communication

  • BPF maps — hash, array, LRU, per-CPU, ring buffer, perf event buffer, and more, all declared as typed Java fields. docs/maps.md
  • Map-of-maps — HASH_OF_MAPS and ARRAY_OF_MAPS for dynamic inner-map selection. docs/map-of-maps.md
  • Shared maps — share maps across multiple @BPF programs with @SharedFrom. docs/shared-maps.md
  • Global variables — read/write kernel-side globals from Java user-space without a map round-trip. docs/global-variables.md
  • BPF arenas — allocate shared kernel/user memory with @InArena pointers for zero-copy data exchange. docs/arenas.md
  • BPF timers — schedule periodic or deferred kernel-side callbacks with @BPFTimer. docs/timers.md

Program Structure

  • Tail-call tables — declare an enum, mark methods with @TailCallSlot, and slots auto-register at load; hot-swap included. docs/tail-calls.md
  • Attach cookies and multi-attach — per-attachment u64 cookies and kprobe.multi / uprobe.multi. docs/attach-cookies-multi.md
  • Pure-Java BPF programs — write the kernel-side logic entirely in Java; the annotation processor compiles it to BPF bytecode via Clang. docs/getting-started/how-it-works.md

Goals

Provide a library (and documentation) for Java developers to explore eBPF and write their own eBPF programs, like firewalls, directly in Java, using the libbpf under the hood.

The goal is neither to replace existing eBPF libraries nor to provide a higher abstractions.

Prerequisites

These might change in the future, but for now, you need the following:

Either a Linux machine with the following:

  • Linux kernel 6.17 or later (BPF arenas + __BPF_FEATURE_ADDR_SPACE_CAST floor)
  • Java 22 or later
  • libbpf and bpf-tool
    • e.g. apt install libbpf-dev linux-tools-common linux-tools-$(uname -r) on Ubuntu
  • root privileges (for executing the eBPF programs)

To verify your setup is complete, run ./scripts/doctor.sh from the repo root — it walks every prerequisite and prints the apt line to install anything missing. (On macOS it short-circuits with a pointer to SYNC_WORKFLOW.md for the split-host workflow.)

  • On Mac OS, you can use the Lima VM (or use the hello-ebpf.yaml file as a guide to install the prerequisites):
bash
limactl start hello-ebpf.yaml --mount-writable
limactl shell hello-ebpf sudo bin/install.sh
limactl shell hello-ebpf

# You'll need to be root for most of the examples
sudo -s PATH=$PATH

The scheduler examples require a 6.14+ kernel (Ubuntu 25.04 has it, install on older Ubuntus via the mainline tool).

Blog Posts

Posts covering the development of this project:

  • Dec 01, 2023: Finding all used Classes, Methods, and Functions of a Python Module
  • Dec 11, 2023: From C to Java Code using Panama
  • Jan 01, 2024: Hello eBPF: Developing eBPF Apps in Java (1)
  • Jan 12, 2024: Hello eBPF: Recording data in basic eBPF maps (2)
  • Jan 29, 2024: Hello eBPF: Recording data in perf event buffers (3)
  • Feb 12, 2024: Hello eBPF: Tail calls and your first eBPF application (4)
  • Feb 26, 2024: Hello eBPF: First steps with libbpf (5)
  • Mar 12, 2024: Hello eBPF: Ring buffers in libbpf (6)
  • Mar 22, 2024: Hello eBPF: Auto Layouting Structs (7)
  • Apr 09, 2024: Hello eBPF: Generating C Code (8)
  • Apr 22, 2024: Hello eBPF: XDP-based Packet Filter (9)
  • May 21, 2024: Hello eBPF: Global Variables (10)
  • Jul 02, 2024: Hello eBPF: BPF Type Format and 13 Thousand Generated Java Classes (11)
  • Jul 30, 2024: Hello eBPF: Write your eBPF application in Pure Java (12)
  • Aug 13, 2024: Hello eBPF: A Packet Logger in Pure Java using TC and XDP Hooks (13)
  • Aug 27, 2024: Hello eBPF: Building a Lightning Fast Firewall with Java & eBPF (14)
  • Sep 10, 2024: Hello eBPF: Collection of Resources for eBPF (14.5)
  • Sep 10, 2024: Hello eBPF: Writing a Linux scheduler in Java with eBPF (15)
  • Dec 03, 2024: Hello eBPF: Control task scheduling with a custom scheduler written in Java (16)

Examples

I wrote a few samples that showcase the usage of the library in the bpf-samples module, you can use them as a starting point for your own eBPF programs.

Inspiration Name and Java Class Description
HelloWorld A simple hello world example
LogOpenAt2Call Logs all openat2 calls
Ansil H RingSample Record openat2 calls in a ring buffer
HashMapSample Record openat2 calls in a hash map
XDPDropEveryThirdPacket Use XDP to block every third incoming packet
sematext XDPPacketFilter Use XDP to block incoming packages from specific URLs in Java
sematext XDPPacketFilter2 The previous example but with the eBPF program as C code
TCDropEveryThirdOutgoingPacket Implement a Traffic Control to block every third outgoing packet at random
PacketLogger TC and XDP based packet logger, capturing incoming and outgoing packets
nfil.dev CGroupBlockHTTPEgress Block all outgoing HTTP packets using cgroups
demo.ForbiddenFile Block access to a specific file via openat2
Firewall A simple firewall that blocks all incoming packets
FirewallSpring A spring boot based web front-end for the Firewall
MinimalScheduler A minimal Linux scheduler

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaebpfjavapanama

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言