mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
This commit is contained in:
parent
8e42425c92
commit
a39b17624a
315 changed files with 7245 additions and 1477 deletions
|
@ -126,7 +126,7 @@ static void save_memory_to_file(char* addr, size_t size) {
|
|||
}
|
||||
}
|
||||
}
|
||||
FREE_C_HEAP_ARRAY(char, destfile);
|
||||
FREE_C_HEAP_ARRAY(char, destfile, mtInternal);
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,7 +153,7 @@ static char* get_user_tmp_dir(const char* user) {
|
|||
const char* tmpdir = os::get_temp_directory();
|
||||
const char* perfdir = PERFDATA_NAME;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 3;
|
||||
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
|
||||
|
||||
// construct the path name to user specific tmp directory
|
||||
snprintf(dirname, nbytes, "%s/%s_%s", tmpdir, perfdir, user);
|
||||
|
@ -246,7 +246,7 @@ static char* get_user_name(uid_t uid) {
|
|||
if (bufsize == -1)
|
||||
bufsize = 1024;
|
||||
|
||||
char* pwbuf = NEW_C_HEAP_ARRAY(char, bufsize);
|
||||
char* pwbuf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
|
||||
|
||||
// POSIX interface to getpwuid_r is used on LINUX
|
||||
struct passwd* p;
|
||||
|
@ -278,14 +278,14 @@ static char* get_user_name(uid_t uid) {
|
|||
"pw_name zero length");
|
||||
}
|
||||
}
|
||||
FREE_C_HEAP_ARRAY(char, pwbuf);
|
||||
FREE_C_HEAP_ARRAY(char, pwbuf, mtInternal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* user_name = NEW_C_HEAP_ARRAY(char, strlen(p->pw_name) + 1);
|
||||
char* user_name = NEW_C_HEAP_ARRAY(char, strlen(p->pw_name) + 1, mtInternal);
|
||||
strcpy(user_name, p->pw_name);
|
||||
|
||||
FREE_C_HEAP_ARRAY(char, pwbuf);
|
||||
FREE_C_HEAP_ARRAY(char, pwbuf, mtInternal);
|
||||
return user_name;
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
// to determine the user name for the process id.
|
||||
//
|
||||
struct dirent* dentry;
|
||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname));
|
||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
||||
errno = 0;
|
||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
||||
|
||||
|
@ -338,7 +338,7 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
}
|
||||
|
||||
char* usrdir_name = NEW_C_HEAP_ARRAY(char,
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 2);
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 2, mtInternal);
|
||||
strcpy(usrdir_name, tmpdirname);
|
||||
strcat(usrdir_name, "/");
|
||||
strcat(usrdir_name, dentry->d_name);
|
||||
|
@ -346,7 +346,7 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
DIR* subdirp = os::opendir(usrdir_name);
|
||||
|
||||
if (subdirp == NULL) {
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -357,13 +357,13 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
// symlink can be exploited.
|
||||
//
|
||||
if (!is_directory_secure(usrdir_name)) {
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
|
||||
os::closedir(subdirp);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct dirent* udentry;
|
||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name));
|
||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
||||
errno = 0;
|
||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
||||
|
||||
|
@ -372,7 +372,7 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
int result;
|
||||
|
||||
char* filename = NEW_C_HEAP_ARRAY(char,
|
||||
strlen(usrdir_name) + strlen(udentry->d_name) + 2);
|
||||
strlen(usrdir_name) + strlen(udentry->d_name) + 2, mtInternal);
|
||||
|
||||
strcpy(filename, usrdir_name);
|
||||
strcat(filename, "/");
|
||||
|
@ -381,13 +381,13 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
// don't follow symbolic links for the file
|
||||
RESTARTABLE(::lstat(filename, &statbuf), result);
|
||||
if (result == OS_ERR) {
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
continue;
|
||||
}
|
||||
|
||||
// skip over files that are not regular files.
|
||||
if (!S_ISREG(statbuf.st_mode)) {
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -397,23 +397,23 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
|||
if (statbuf.st_ctime > oldest_ctime) {
|
||||
char* user = strchr(dentry->d_name, '_') + 1;
|
||||
|
||||
if (oldest_user != NULL) FREE_C_HEAP_ARRAY(char, oldest_user);
|
||||
oldest_user = NEW_C_HEAP_ARRAY(char, strlen(user)+1);
|
||||
if (oldest_user != NULL) FREE_C_HEAP_ARRAY(char, oldest_user, mtInternal);
|
||||
oldest_user = NEW_C_HEAP_ARRAY(char, strlen(user)+1, mtInternal);
|
||||
|
||||
strcpy(oldest_user, user);
|
||||
oldest_ctime = statbuf.st_ctime;
|
||||
}
|
||||
}
|
||||
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
}
|
||||
}
|
||||
os::closedir(subdirp);
|
||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
|
||||
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
|
||||
}
|
||||
os::closedir(tmpdirp);
|
||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
||||
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
|
||||
|
||||
return(oldest_user);
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ static char* get_sharedmem_filename(const char* dirname, int vmid) {
|
|||
// add 2 for the file separator and a null terminator.
|
||||
size_t nbytes = strlen(dirname) + UINT_CHARS + 2;
|
||||
|
||||
char* name = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
char* name = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
|
||||
snprintf(name, nbytes, "%s/%d", dirname, vmid);
|
||||
|
||||
return name;
|
||||
|
@ -472,7 +472,7 @@ static void remove_file(const char* path) {
|
|||
static void remove_file(const char* dirname, const char* filename) {
|
||||
|
||||
size_t nbytes = strlen(dirname) + strlen(filename) + 2;
|
||||
char* path = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
char* path = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
|
||||
|
||||
strcpy(path, dirname);
|
||||
strcat(path, "/");
|
||||
|
@ -480,7 +480,7 @@ static void remove_file(const char* dirname, const char* filename) {
|
|||
|
||||
remove_file(path);
|
||||
|
||||
FREE_C_HEAP_ARRAY(char, path);
|
||||
FREE_C_HEAP_ARRAY(char, path, mtInternal);
|
||||
}
|
||||
|
||||
|
||||
|
@ -517,7 +517,7 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
|||
// opendir/readdir.
|
||||
//
|
||||
struct dirent* entry;
|
||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname));
|
||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
||||
errno = 0;
|
||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
||||
|
||||
|
@ -556,7 +556,7 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
|||
errno = 0;
|
||||
}
|
||||
os::closedir(dirp);
|
||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
||||
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
|
||||
}
|
||||
|
||||
// make the user specific temporary directory. Returns true if
|
||||
|
@ -723,11 +723,11 @@ static char* mmap_create_shared(size_t size) {
|
|||
|
||||
fd = create_sharedmem_resources(dirname, filename, size);
|
||||
|
||||
FREE_C_HEAP_ARRAY(char, user_name);
|
||||
FREE_C_HEAP_ARRAY(char, dirname);
|
||||
FREE_C_HEAP_ARRAY(char, user_name, mtInternal);
|
||||
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
|
||||
|
||||
if (fd == -1) {
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -743,7 +743,7 @@ static char* mmap_create_shared(size_t size) {
|
|||
warning("mmap failed - %s\n", strerror(errno));
|
||||
}
|
||||
remove_file(filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -869,7 +869,7 @@ static void mmap_attach_shared(const char* user, int vmid, PerfMemory::PerfMemor
|
|||
// store file, we don't follow them when attaching either.
|
||||
//
|
||||
if (!is_directory_secure(dirname)) {
|
||||
FREE_C_HEAP_ARRAY(char, dirname);
|
||||
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
|
||||
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
|
||||
"Process not found");
|
||||
}
|
||||
|
@ -884,9 +884,9 @@ static void mmap_attach_shared(const char* user, int vmid, PerfMemory::PerfMemor
|
|||
strcpy(rfilename, filename);
|
||||
|
||||
// free the c heap resources that are no longer needed
|
||||
if (luser != user) FREE_C_HEAP_ARRAY(char, luser);
|
||||
FREE_C_HEAP_ARRAY(char, dirname);
|
||||
FREE_C_HEAP_ARRAY(char, filename);
|
||||
if (luser != user) FREE_C_HEAP_ARRAY(char, luser, mtInternal);
|
||||
FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
|
||||
FREE_C_HEAP_ARRAY(char, filename, mtInternal);
|
||||
|
||||
// open the shared memory file for the give vmid
|
||||
fd = open_sharedmem_file(rfilename, file_flags, CHECK);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue