@@ -107,41 +107,60 @@ size_t os::_os_min_stack_allowed = PTHREAD_STACK_MIN;
107107
108108// Check core dump limit and report possible place where core can be found
109109void os::check_core_dump_prerequisites (char * buffer, size_t bufferSize, bool check_only) {
110+ stringStream buf (buffer, bufferSize);
110111 if (!FLAG_IS_DEFAULT (CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) {
111- jio_snprintf (buffer, bufferSize, " CreateCoredumpOnCrash is disabled from command line" );
112- VMError::record_coredump_status (buffer , false );
112+ buf. print ( " CreateCoredumpOnCrash is disabled from command line" );
113+ VMError::record_coredump_status (buf. freeze () , false );
113114 } else {
114115 struct rlimit rlim;
115116 bool success = true ;
116117 bool warn = true ;
117118 char core_path[PATH_MAX];
118119 if (get_core_path (core_path, PATH_MAX) <= 0 ) {
119- jio_snprintf (buffer, bufferSize, " core.%d (may not exist)" , current_process_id ());
120+ // In the warning message, let the user know.
121+ if (check_only) {
122+ buf.print (" the core path couldn't be determined. It commonly defaults to " );
123+ }
124+ buf.print (" core.%d%s" , current_process_id (), check_only ? " " : " (may not exist)" );
120125#ifdef LINUX
121126 } else if (core_path[0 ] == ' "' ) { // redirect to user process
122- jio_snprintf (buffer, bufferSize, " Core dumps may be processed with %s" , core_path);
127+ if (check_only) {
128+ buf.print (" core dumps may be further processed by the following: " );
129+ } else {
130+ buf.print (" Determined by the following: " );
131+ }
132+ buf.print (" %s" , core_path);
123133#endif
124134 } else if (getrlimit (RLIMIT_CORE, &rlim) != 0 ) {
125- jio_snprintf (buffer, bufferSize, " %s (may not exist)" , core_path);
135+ if (check_only) {
136+ buf.print (" the rlimit couldn't be determined. If resource limits permit, the core dump will be located at " );
137+ }
138+ buf.print (" %s%s" , core_path, check_only ? " " : " (may not exist)" );
126139 } else {
127140 switch (rlim.rlim_cur ) {
128141 case RLIM_INFINITY:
129- jio_snprintf (buffer, bufferSize, " %s" , core_path);
142+ buf. print ( " %s" , core_path);
130143 warn = false ;
131144 break ;
132145 case 0 :
133- jio_snprintf (buffer, bufferSize, " Core dumps have been disabled. To enable core dumping, try \" ulimit -c unlimited\" before starting Java again" );
146+ buf. print ( " %s dumps have been disabled. To enable core dumping, try \" ulimit -c unlimited\" before starting Java again" , check_only ? " core " : " Core " );
134147 success = false ;
135148 break ;
136149 default :
137- jio_snprintf (buffer, bufferSize, " %s (max size " UINT64_FORMAT " k). To ensure a full core dump, try \" ulimit -c unlimited\" before starting Java again" , core_path, uint64_t (rlim.rlim_cur ) / K);
150+ if (check_only) {
151+ buf.print (" core dumps are constrained " );
152+ } else {
153+ buf.print ( " %s " , core_path);
154+ }
155+ buf.print ( " (max size " UINT64_FORMAT " k). To ensure a full core dump, try \" ulimit -c unlimited\" before starting Java again" , uint64_t (rlim.rlim_cur ) / K);
138156 break ;
139157 }
140158 }
159+ const char * result = buf.freeze ();
141160 if (!check_only) {
142- VMError::record_coredump_status (buffer , success);
161+ VMError::record_coredump_status (result , success);
143162 } else if (warn) {
144- warning (" CreateCoredumpOnCrash specified, but %s" , buffer );
163+ warning (" CreateCoredumpOnCrash specified, but %s" , result );
145164 }
146165 }
147166}
0 commit comments