8267930: Refine code for loading hsdis library

Reviewed-by: whuang, neliasso, ysuenaga
This commit is contained in:
Hamlin Li 2021-06-11 01:20:47 +00:00
parent 2e900da5f7
commit df65237b9a
2 changed files with 17 additions and 30 deletions
src/hotspot/share/compiler

@ -755,6 +755,17 @@ address decode_env::decode_instructions(address start, address end, address orig
// Each method will create a decode_env before decoding.
// You can call the decode_env methods directly if you already have one.
void* Disassembler::dll_load(char* buf, int buflen, int offset, char* ebuf, int ebuflen, outputStream* st) {
int sz = buflen - offset;
int written = jio_snprintf(&buf[offset], sz, "%s%s", hsdis_library_name, os::dll_file_extension());
if (written < sz) { // written successfully, not truncated.
if (Verbose) st->print_cr("Trying to load: %s", buf);
return os::dll_load(buf, ebuf, ebuflen);
} else if (Verbose) {
st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
}
return NULL;
}
bool Disassembler::load_library(outputStream* st) {
// Do not try to load multiple times. Failed once -> fails always.
@ -804,24 +815,10 @@ bool Disassembler::load_library(outputStream* st) {
// 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
if (jvm_offset >= 0) {
// 1. <home>/lib/<vm>/libhsdis-<arch>.so
if (jvm_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
strcpy(&buf[jvm_offset], hsdis_library_name);
strcat(&buf[jvm_offset], os::dll_file_extension());
if (Verbose) st->print_cr("Trying to load: %s", buf);
_library = os::dll_load(buf, ebuf, sizeof ebuf);
} else {
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
}
_library = dll_load(buf, sizeof buf, jvm_offset, ebuf, sizeof ebuf, st);
if (_library == NULL && lib_offset >= 0) {
// 2. <home>/lib/<vm>/hsdis-<arch>.so
if (lib_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
strcpy(&buf[lib_offset], hsdis_library_name);
strcat(&buf[lib_offset], os::dll_file_extension());
if (Verbose) st->print_cr("Trying to load: %s", buf);
_library = os::dll_load(buf, ebuf, sizeof ebuf);
} else {
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
}
_library = dll_load(buf, sizeof buf, lib_offset, ebuf, sizeof ebuf, st);
}
if (_library == NULL && lib_offset > 0) {
// 3. <home>/lib/hsdis-<arch>.so
@ -829,23 +826,12 @@ bool Disassembler::load_library(outputStream* st) {
const char* p = strrchr(buf, *os::file_separator());
if (p != NULL) {
lib_offset = p - buf + 1;
if (lib_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
strcpy(&buf[lib_offset], hsdis_library_name);
strcat(&buf[lib_offset], os::dll_file_extension());
if (Verbose) st->print_cr("Trying to load: %s", buf);
_library = os::dll_load(buf, ebuf, sizeof ebuf);
} else {
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
}
_library = dll_load(buf, sizeof buf, lib_offset, ebuf, sizeof ebuf, st);
}
}
}
if (_library == NULL) {
// 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
strcpy(&buf[0], hsdis_library_name);
strcat(&buf[0], os::dll_file_extension());
if (Verbose) st->print_cr("Trying to load: %s via LD_LIBRARY_PATH or equivalent", buf);
_library = os::dll_load(buf, ebuf, sizeof ebuf);
_library = dll_load(buf, sizeof buf, 0, ebuf, sizeof ebuf, st);
}
// load the decoder function to use.

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,6 +65,7 @@ class Disassembler : public AbstractDisassembler {
// No output at all if stream is NULL. Can be overridden
// with -Verbose flag, in which case output goes to tty.
static bool load_library(outputStream* st = NULL);
static void* dll_load(char* buf, int buflen, int offset, char* ebuf, int ebuflen, outputStream* st);
// Check if the two addresses are on the same page.
static bool is_same_page(address a1, address a2) {