/* * jvmti_agent.c: JVMTI agent interface * * Adapted from the Oprofile code in opagent.c: * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright 2007 OProfile authors * Jens Wilke * Daniel Hansel * Copyright IBM Corporation 2007
*/ #include <sys/types.h> #include <sys/stat.h> /* for mkdir() */ #include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <limits.h> #include <fcntl.h> #include <unistd.h> #include <time.h> #include <sys/mman.h> #include <syscall.h> /* for gettid() */ #include <err.h> #include <linux/kernel.h>
ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base); if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jit cache dir because %s/.debug/" " 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", 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;
}
staticint
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;
}
staticvoid
perf_close_marker_file(void)
{ long pgsz;
if (!marker_addr) return;
pgsz = sysconf(_SC_PAGESIZE); if (pgsz == -1) return;
/* * check if clockid is supported
*/ if (!perf_get_timestamp()) { if (use_arch_timestamp)
warnx("jvmti: arch timestamp not supported"); else
warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
}
memset(&header, 0, sizeof(header));
/* * jitdump file dir
*/ if (create_jit_cache_dir() < 0) return NULL;
/* * jitdump file name
*/
ret = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); if (ret >= PATH_MAX) {
warnx("jvmti: cannot generate jitdump file full path because" " %s/jit-%i.dump is too long, please check the cwd," " JITDUMPDIR, and HOME variables", jit_path, getpid()); return NULL;
}
/* * on disk source line info layout: * uint64_t : addr * int : line number * int : column discriminator * file[] : source file name
*/
size += nr_lines * sizeof(struct debug_entry);
size += flen;
rec.p.total_size = size;
/* * If JVM is multi-threaded, multiple concurrent calls to agent * may be possible, so protect file writes
*/
flockfile(fp);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.