tools/perf/jvmti/jvmti_agent.c
Source file repositories/reference/linux-study-clean/tools/perf/jvmti/jvmti_agent.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/jvmti/jvmti_agent.c- Extension
.c- Size
- 10361 bytes
- Lines
- 497
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/types.hsys/stat.hstdio.herrno.hstring.hstdlib.hstdint.hlimits.hfcntl.hunistd.htime.hsys/mman.hsyscall.herr.hlinux/kernel.hjvmti_agent.h../util/jitdump.h
Detected Declarations
function gettidfunction get_e_machinefunction get_arch_timestampfunction timespec_to_nsfunction perf_get_timestampfunction create_jit_cache_dirfunction perf_open_marker_filefunction perf_close_marker_filefunction init_arch_timestampfunction jvmti_closefunction jvmti_write_codefunction jvmti_write_debug_info
Annotated Snippet
if (errno != EEXIST) {
warn("jvmti: cannot create jit cache dir %s", jit_path);
return -1;
}
}
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit", base);
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because"
" %s/.debug/jit is too long, please check the cwd,"
" JITDUMPDIR, and HOME variables", base);
return -1;
}
ret = mkdir(jit_path, 0755);
if (ret == -1) {
if (errno != EEXIST) {
warn("jvmti: cannot create jit cache dir %s", jit_path);
return -1;
}
}
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str);
if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because"
" %s/.debug/jit/%s.XXXXXXXX is too long, please check"
" the cwd, JITDUMPDIR, and HOME variables",
base, str);
return -1;
}
p = mkdtemp(jit_path);
if (p != jit_path) {
warn("jvmti: cannot create jit cache dir %s", jit_path);
return -1;
}
return 0;
}
static int
perf_open_marker_file(int fd)
{
long pgsz;
pgsz = sysconf(_SC_PAGESIZE);
if (pgsz == -1)
return -1;
/*
* we mmap the jitdump to create an MMAP RECORD in perf.data file.
* The mmap is captured either live (perf record running when we mmap)
* or in deferred mode, via /proc/PID/maps
* the MMAP record is used as a marker of a jitdump file for more meta
* data info about the jitted code. Perf report/annotate detect this
* special filename and process the jitdump file.
*
* mapping must be PROT_EXEC to ensure it is captured by perf record
* even when not using -d option
*/
marker_addr = mmap(NULL, pgsz, PROT_READ|PROT_EXEC, MAP_PRIVATE, fd, 0);
return (marker_addr == MAP_FAILED) ? -1 : 0;
}
static void
perf_close_marker_file(void)
{
long pgsz;
if (!marker_addr)
return;
pgsz = sysconf(_SC_PAGESIZE);
if (pgsz == -1)
return;
munmap(marker_addr, pgsz);
}
static void
init_arch_timestamp(void)
{
char *str = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
if (!str || !*str || !strcmp(str, "0"))
return;
use_arch_timestamp = 1;
}
void *jvmti_open(void)
{
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `stdio.h`, `errno.h`, `string.h`, `stdlib.h`, `stdint.h`, `limits.h`.
- Detected declarations: `function gettid`, `function get_e_machine`, `function get_arch_timestamp`, `function timespec_to_ns`, `function perf_get_timestamp`, `function create_jit_cache_dir`, `function perf_open_marker_file`, `function perf_close_marker_file`, `function init_arch_timestamp`, `function jvmti_close`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.