Skip to content

Commit 36864a2

Browse files
committed
8351491: Add info from release file to hserr file
Reviewed-by: dholmes, lucy
1 parent 273a9a6 commit 36864a2

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

src/hotspot/share/runtime/os.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,56 @@ bool os::set_boot_path(char fileSep, char pathSep) {
15341534
return false;
15351535
}
15361536

1537+
static char* _image_release_file_content = nullptr;
1538+
1539+
void os::read_image_release_file() {
1540+
assert(_image_release_file_content == nullptr, "release file content must not be already set");
1541+
const char* home = Arguments::get_java_home();
1542+
stringStream ss;
1543+
ss.print("%s/release", home);
1544+
1545+
FILE* file = fopen(ss.base(), "rb");
1546+
if (file == nullptr) {
1547+
return;
1548+
}
1549+
fseek(file, 0, SEEK_END);
1550+
long sz = ftell(file);
1551+
if (sz == -1) {
1552+
return;
1553+
}
1554+
fseek(file, 0, SEEK_SET);
1555+
1556+
char* tmp = (char*) os::malloc(sz + 1, mtInternal);
1557+
if (tmp == nullptr) {
1558+
fclose(file);
1559+
return;
1560+
}
1561+
1562+
size_t elements_read = fread(tmp, 1, sz, file);
1563+
if (elements_read < (size_t)sz) {
1564+
tmp[elements_read] = '\0';
1565+
} else {
1566+
tmp[sz] = '\0';
1567+
}
1568+
// issues with \r in line endings on Windows, so better replace those
1569+
for (size_t i = 0; i < elements_read; i++) {
1570+
if (tmp[i] == '\r') {
1571+
tmp[i] = ' ';
1572+
}
1573+
}
1574+
Atomic::release_store(&_image_release_file_content, tmp);
1575+
fclose(file);
1576+
}
1577+
1578+
void os::print_image_release_file(outputStream* st) {
1579+
char* ifrc = Atomic::load_acquire(&_image_release_file_content);
1580+
if (ifrc != nullptr) {
1581+
st->print_cr("%s", ifrc);
1582+
} else {
1583+
st->print_cr("<release file has not been read>");
1584+
}
1585+
}
1586+
15371587
bool os::file_exists(const char* filename) {
15381588
struct stat statbuf;
15391589
if (filename == nullptr || strlen(filename) == 0) {

src/hotspot/share/runtime/os.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,11 @@ class os: AllStatic {
670670
static FILE* fopen(const char* path, const char* mode);
671671
static jlong lseek(int fd, jlong offset, int whence);
672672
static bool file_exists(const char* file);
673+
674+
// read/store and print the release file of the image
675+
static void read_image_release_file();
676+
static void print_image_release_file(outputStream* st);
677+
673678
// This function, on Windows, canonicalizes a given path (see os_windows.cpp for details).
674679
// On Posix, this function is a noop: it does not change anything and just returns
675680
// the input pointer.

src/hotspot/share/runtime/threads.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,19 @@ void Threads::initialize_jsr292_core_classes(TRAPS) {
425425
}
426426
}
427427

428+
// One-shot PeriodicTask subclass for reading the release file
429+
class ReadReleaseFileTask : public PeriodicTask {
430+
public:
431+
ReadReleaseFileTask() : PeriodicTask(100) {}
432+
433+
virtual void task() {
434+
os::read_image_release_file();
435+
436+
// Reclaim our storage and disenroll ourself.
437+
delete this;
438+
}
439+
};
440+
428441
jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
429442
extern void JDK_Version_init();
430443

@@ -580,6 +593,10 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
580593
return status;
581594
}
582595

596+
// Have the WatcherThread read the release file in the background.
597+
ReadReleaseFileTask* read_task = new ReadReleaseFileTask();
598+
read_task->enroll();
599+
583600
// Create WatcherThread as soon as we can since we need it in case
584601
// of hangs during error reporting.
585602
WatcherThread::start();

src/hotspot/share/utilities/vmError.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ void VMError::report(outputStream* st, bool _verbose) {
12591259
LogConfiguration::describe_current_configuration(st);
12601260
st->cr();
12611261

1262+
STEP_IF("printing release file content", _verbose)
1263+
st->print_cr("Release file:");
1264+
os::print_image_release_file(st);
1265+
12621266
STEP_IF("printing all environment variables", _verbose)
12631267
os::print_environment_variables(st, env_list);
12641268
st->cr();
@@ -1439,6 +1443,10 @@ void VMError::print_vm_info(outputStream* st) {
14391443
LogConfiguration::describe(st);
14401444
st->cr();
14411445

1446+
// STEP("printing release file content")
1447+
st->print_cr("Release file:");
1448+
os::print_image_release_file(st);
1449+
14421450
// STEP("printing all environment variables")
14431451

14441452
os::print_environment_variables(st, env_list);

0 commit comments

Comments
 (0)