void *jvmti_open(void) { int pad_cnt; char dump_path[PATH_MAX]; struct jitheader header; int fd; FILE *fp; /* * check if clockid is supported */ if (!perf_get_timestamp()) warnx("jvmti: kernel does not support %d clock id", perf_clk_id); memset(&header, 0, sizeof(header)); debug_cache_init(); /* * jitdump file name */ snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); if (fd == -1) return NULL; /* * create perf.data maker for the jitdump file */ if (perf_open_marker_file(fd)) { warnx("jvmti: failed to create marker file"); return NULL; } fp = fdopen(fd, "w+"); if (!fp) { warn("jvmti: cannot create %s", dump_path); close(fd); goto error; } warnx("jvmti: jitdump in %s", dump_path); if (get_e_machine(&header)) { warn("get_e_machine failed\n"); goto error; } header.magic = JITHEADER_MAGIC; header.version = JITHEADER_VERSION; header.total_size = sizeof(header); header.pid = getpid(); /* calculate amount of padding '\0' */ pad_cnt = PADDING_8ALIGNED(header.total_size); header.total_size += pad_cnt; header.timestamp = perf_get_timestamp(); if (!fwrite(&header, sizeof(header), 1, fp)) { warn("jvmti: cannot write dumpfile header"); goto error; } /* write padding '\0' if necessary */ if (pad_cnt && !fwrite(pad_bytes, pad_cnt, 1, fp)) { warn("jvmti: cannot write dumpfile header padding"); goto error; } return fp; error: fclose(fp); return NULL; }
void *jvmti_open(void) { char dump_path[PATH_MAX]; struct jitheader header; int fd; FILE *fp; init_arch_timestamp(); /* * 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)); debug_cache_init(); /* * jitdump file name */ snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); if (fd == -1) return NULL; /* * create perf.data maker for the jitdump file */ if (perf_open_marker_file(fd)) { warnx("jvmti: failed to create marker file"); return NULL; } fp = fdopen(fd, "w+"); if (!fp) { warn("jvmti: cannot create %s", dump_path); close(fd); goto error; } warnx("jvmti: jitdump in %s", dump_path); if (get_e_machine(&header)) { warn("get_e_machine failed\n"); goto error; } header.magic = JITHEADER_MAGIC; header.version = JITHEADER_VERSION; header.total_size = sizeof(header); header.pid = getpid(); header.timestamp = perf_get_timestamp(); if (use_arch_timestamp) header.flags |= JITDUMP_FLAGS_ARCH_TIMESTAMP; if (!fwrite(&header, sizeof(header), 1, fp)) { warn("jvmti: cannot write dumpfile header"); goto error; } return fp; error: fclose(fp); return NULL; }