# marcogomiero/jattach architecture

> Architecture diagram of the GitHub repository marcogomiero/jattach, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marcogomiero/jattach
- Repository: https://github.com/marcogomiero/jattach

## Overview

jattach is a native command-line utility that sends Dynamic Attach commands to a running JVM, providing operations such as agent loading, diagnostics, heap dumps, and VM flag access. The POSIX entry point resolves the target process and namespaces, then dispatches to HotSpot’s socket protocol or OpenJ9’s attach protocol; Windows uses remote-thread injection and a named pipe. The excerpts show these main paths and process helpers. The README documents command capabilities, but their execution inside the JVM is outside this repository.

Main entry points: [`src/posix/jattach.c`](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach.c) (POSIX entry), [`src/posix/psutil.c`](https://github.com/marcogomiero/jattach/blob/master/src/posix/psutil.c) (Process lookup), [`src/posix/jattach_hotspot.c`](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_hotspot.c) (HotSpot attach), [`src/posix/jattach_openj9.c`](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_openj9.c) (OpenJ9 attach)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_posix["POSIX setup"]
  node_posix_entry["POSIX entry<br/>[jattach.c]"]
  node_process_info["Process lookup<br/>[psutil.c]"]
  node_process_api["Process API<br/>[psutil.h]"]
end

subgraph group_transports["JVM transports"]
  node_hotspot["HotSpot attach<br/>[jattach_hotspot.c]"]
  node_openj9["OpenJ9 attach<br/>[jattach_openj9.c]"]
end

subgraph group_windows["Windows transport"]
  node_windows_attach["Windows attach<br/>[jattach.c]"]
end

node_user(("CLI user"))
node_jvm(("Target JVM"))

node_user -->|"invokes"| node_posix_entry
node_posix_entry -->|"looks up process"| node_process_info
node_process_info -->|"defines API"| node_process_api
node_posix_entry -->|"uses helpers"| node_process_api
node_posix_entry -->|"dispatches to"| node_openj9
node_posix_entry -->|"dispatches to"| node_hotspot
node_openj9 -->|"exchanges commands"| node_jvm
node_hotspot -->|"sends commands"| node_jvm
node_user -->|"invokes"| node_windows_attach
node_windows_attach -->|"injects command"| node_jvm

click node_posix_entry "https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach.c"
click node_process_info "https://github.com/marcogomiero/jattach/blob/master/src/posix/psutil.c"
click node_process_api "https://github.com/marcogomiero/jattach/blob/master/src/posix/psutil.h"
click node_hotspot "https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_hotspot.c"
click node_openj9 "https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_openj9.c"
click node_windows_attach "https://github.com/marcogomiero/jattach/blob/master/src/windows/jattach.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_posix_entry,node_process_info,node_process_api,node_user toneBlue
class node_hotspot,node_openj9 toneAmber
class node_windows_attach toneMint
class node_jvm toneIndigo
```

## Components

### POSIX setup

- [POSIX entry](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach.c): `src/posix/jattach.c`
- [Process lookup](https://github.com/marcogomiero/jattach/blob/master/src/posix/psutil.c): `src/posix/psutil.c`
- [Process API](https://github.com/marcogomiero/jattach/blob/master/src/posix/psutil.h): `src/posix/psutil.h`

### JVM transports

- [HotSpot attach](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_hotspot.c): `src/posix/jattach_hotspot.c`
- [OpenJ9 attach](https://github.com/marcogomiero/jattach/blob/master/src/posix/jattach_openj9.c): `src/posix/jattach_openj9.c`

### Windows transport

- [Windows attach](https://github.com/marcogomiero/jattach/blob/master/src/windows/jattach.c): `src/windows/jattach.c`

### Other components

- **CLI user**
- **Target JVM**

## Connections

- CLI user → POSIX entry: invokes (evidence: `src/posix/jattach.c`)
- POSIX entry → Process lookup: looks up process (evidence: `src/posix/jattach.c`)
- Process lookup → Process API: defines API (evidence: `src/posix/psutil.c`)
- POSIX entry → Process API: uses helpers (evidence: `src/posix/jattach.c`)
- POSIX entry → OpenJ9 attach: dispatches to (evidence: `src/posix/jattach.c`)
- POSIX entry → HotSpot attach: dispatches to (evidence: `src/posix/jattach.c`)
- OpenJ9 attach → Target JVM: exchanges commands (evidence: `src/posix/jattach_openj9.c`)
- HotSpot attach → Target JVM: sends commands (evidence: `src/posix/jattach_hotspot.c`)
- CLI user → Windows attach: invokes (evidence: `src/windows/jattach.c`)
- Windows attach → Target JVM: injects command (evidence: `src/windows/jattach.c`)
