提交 9dfeb5f2 编写于 作者: A anoll

8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp

Summary: Added calling of the destructor of CompileLog so that files are closed. Added/moved memory allocation/deallocation of the string that contains the name of the log file to class CompileLog.
Reviewed-by: kvn, roland
上级 7613d334
......@@ -1642,42 +1642,37 @@ void CompileBroker::compiler_thread_loop() {
// Set up state required by +LogCompilation.
void CompileBroker::init_compiler_thread_log() {
CompilerThread* thread = CompilerThread::current();
char fileBuf[4*K];
char file_name[4*K];
FILE* fp = NULL;
char* file = NULL;
intx thread_id = os::current_thread_id();
for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) {
const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL);
if (dir == NULL) {
jio_snprintf(fileBuf, sizeof(fileBuf), "hs_c" UINTX_FORMAT "_pid%u.log",
jio_snprintf(file_name, sizeof(file_name), "hs_c" UINTX_FORMAT "_pid%u.log",
thread_id, os::current_process_id());
} else {
jio_snprintf(fileBuf, sizeof(fileBuf),
jio_snprintf(file_name, sizeof(file_name),
"%s%shs_c" UINTX_FORMAT "_pid%u.log", dir,
os::file_separator(), thread_id, os::current_process_id());
}
fp = fopen(fileBuf, "at");
if (fp != NULL) {
file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1, mtCompiler);
strcpy(file, fileBuf);
break;
}
}
if (fp == NULL) {
warning("Cannot open log file: %s", fileBuf);
} else {
if (LogCompilation && Verbose)
tty->print_cr("Opening compilation log %s", file);
CompileLog* log = new(ResourceObj::C_HEAP, mtCompiler) CompileLog(file, fp, thread_id);
thread->init_log(log);
if (xtty != NULL) {
ttyLocker ttyl;
fp = fopen(file_name, "at");
if (fp != NULL) {
if (LogCompilation && Verbose) {
tty->print_cr("Opening compilation log %s", file_name);
}
CompileLog* log = new(ResourceObj::C_HEAP, mtCompiler) CompileLog(file_name, fp, thread_id);
thread->init_log(log);
// Record any per thread log files
xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file);
if (xtty != NULL) {
ttyLocker ttyl;
// Record any per thread log files
xtty->elem("thread_logfile thread='%d' filename='%s'", thread_id, file_name);
}
return;
}
}
warning("Cannot open log file: %s", file_name);
}
// ------------------------------------------------------------------
......
......@@ -34,17 +34,18 @@ CompileLog* CompileLog::_first = NULL;
// ------------------------------------------------------------------
// CompileLog::CompileLog
CompileLog::CompileLog(const char* file, FILE* fp, intx thread_id)
CompileLog::CompileLog(const char* file_name, FILE* fp, intx thread_id)
: _context(_context_buffer, sizeof(_context_buffer))
{
initialize(new(ResourceObj::C_HEAP, mtCompiler) fileStream(fp));
_file = file;
initialize(new(ResourceObj::C_HEAP, mtCompiler) fileStream(fp, true));
_file_end = 0;
_thread_id = thread_id;
_identities_limit = 0;
_identities_capacity = 400;
_identities = NEW_C_HEAP_ARRAY(char, _identities_capacity, mtCompiler);
_file = NEW_C_HEAP_ARRAY(char, strlen(file_name)+1, mtCompiler);
strcpy((char*)_file, file_name);
// link into the global list
{ MutexLocker locker(CompileTaskAlloc_lock);
......@@ -57,6 +58,7 @@ CompileLog::~CompileLog() {
delete _out;
_out = NULL;
FREE_C_HEAP_ARRAY(char, _identities, mtCompiler);
FREE_C_HEAP_ARRAY(char, _file, mtCompiler);
}
......@@ -188,7 +190,8 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
if (called_exit) return;
called_exit = true;
for (CompileLog* log = _first; log != NULL; log = log->_next) {
CompileLog* log = _first;
while (log != NULL) {
log->flush();
const char* partial_file = log->file();
int partial_fd = open(partial_file, O_RDONLY);
......@@ -267,7 +270,11 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
close(partial_fd);
unlink(partial_file);
}
CompileLog* next_log = log->_next;
delete log;
log = next_log;
}
_first = NULL;
}
// ------------------------------------------------------------------
......
......@@ -57,7 +57,7 @@ class CompileLog : public xmlStream {
void va_tag(bool push, const char* format, va_list ap);
public:
CompileLog(const char* file, FILE* fp, intx thread_id);
CompileLog(const char* file_name, FILE* fp, intx thread_id);
~CompileLog();
intx thread_id() { return _thread_id; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册