1982
1983 // The dump file defaults to java_pid<pid>.hprof in the current working
1984 // directory. HeapDumpPath=<file> can be used to specify an alternative
1985 // dump file name or a directory where dump file is created.
1986 if (dump_file_seq == 0) { // first time in, we initialize base_path
1987 // Calculate potentially longest base path and check if we have enough
1988 // allocated statically.
1989 const size_t total_length =
1990 (HeapDumpPath == NULL ? 0 : strlen(HeapDumpPath)) +
1991 strlen(os::file_separator()) + max_digit_chars +
1992 strlen(dump_file_name) + strlen(dump_file_ext) + 1;
1993 if (total_length > sizeof(base_path)) {
1994 warning("Cannot create heap dump file. HeapDumpPath is too long.");
1995 return;
1996 }
1997
1998 bool use_default_filename = true;
1999 if (HeapDumpPath == NULL || HeapDumpPath[0] == '\0') {
2000 // HeapDumpPath=<file> not specified
2001 } else {
2002 strncpy(base_path, HeapDumpPath, sizeof(base_path));
2003 // check if the path is a directory (must exist)
2004 DIR* dir = os::opendir(base_path);
2005 if (dir == NULL) {
2006 use_default_filename = false;
2007 } else {
2008 // HeapDumpPath specified a directory. We append a file separator
2009 // (if needed).
2010 os::closedir(dir);
2011 size_t fs_len = strlen(os::file_separator());
2012 if (strlen(base_path) >= fs_len) {
2013 char* end = base_path;
2014 end += (strlen(base_path) - fs_len);
2015 if (strcmp(end, os::file_separator()) != 0) {
2016 strcat(base_path, os::file_separator());
2017 }
2018 }
2019 }
2020 }
2021 // If HeapDumpPath wasn't a file name then we append the default name
2022 if (use_default_filename) {
|
1982
1983 // The dump file defaults to java_pid<pid>.hprof in the current working
1984 // directory. HeapDumpPath=<file> can be used to specify an alternative
1985 // dump file name or a directory where dump file is created.
1986 if (dump_file_seq == 0) { // first time in, we initialize base_path
1987 // Calculate potentially longest base path and check if we have enough
1988 // allocated statically.
1989 const size_t total_length =
1990 (HeapDumpPath == NULL ? 0 : strlen(HeapDumpPath)) +
1991 strlen(os::file_separator()) + max_digit_chars +
1992 strlen(dump_file_name) + strlen(dump_file_ext) + 1;
1993 if (total_length > sizeof(base_path)) {
1994 warning("Cannot create heap dump file. HeapDumpPath is too long.");
1995 return;
1996 }
1997
1998 bool use_default_filename = true;
1999 if (HeapDumpPath == NULL || HeapDumpPath[0] == '\0') {
2000 // HeapDumpPath=<file> not specified
2001 } else {
2002 strcpy(base_path, HeapDumpPath);
2003 // check if the path is a directory (must exist)
2004 DIR* dir = os::opendir(base_path);
2005 if (dir == NULL) {
2006 use_default_filename = false;
2007 } else {
2008 // HeapDumpPath specified a directory. We append a file separator
2009 // (if needed).
2010 os::closedir(dir);
2011 size_t fs_len = strlen(os::file_separator());
2012 if (strlen(base_path) >= fs_len) {
2013 char* end = base_path;
2014 end += (strlen(base_path) - fs_len);
2015 if (strcmp(end, os::file_separator()) != 0) {
2016 strcat(base_path, os::file_separator());
2017 }
2018 }
2019 }
2020 }
2021 // If HeapDumpPath wasn't a file name then we append the default name
2022 if (use_default_filename) {
|