Skip to content

Commit

Permalink
8294411: SA should provide more useful info when it fails to start up…
Browse files Browse the repository at this point in the history
… due to "failed to workaround classshareing"

Reviewed-by: kevinw, sspitsyn
  • Loading branch information
plummercj committed Sep 28, 2022
1 parent 4fb424b commit 3b7fc80
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/jdk.hotspot.agent/share/native/libsaproc/ps_core_common.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
Expand Down Expand Up @@ -123,7 +123,7 @@ void core_release(struct ps_prochandle* ph) {
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz, uint32_t flags) {
map_info* map;
if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
print_debug("can't allocate memory for map_info\n");
print_error("can't allocate memory for map_info\n");
return NULL;
}

Expand Down Expand Up @@ -300,15 +300,15 @@ bool init_classsharing_workaround(struct ps_prochandle* ph) {
jvm_name = lib->name;
useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM);
if (useSharedSpacesAddr == 0) {
print_debug("can't lookup 'UseSharedSpaces' symbol\n");
print_error("can't lookup 'UseSharedSpaces' symbol\n");
return false;
}

// Hotspot vm types are not exported to build this library. So
// using equivalent type jboolean to read the value of
// UseSharedSpaces which is same as hotspot type "bool".
if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
print_debug("can't read the value of 'UseSharedSpaces' symbol\n");
print_error("can't read the value of 'UseSharedSpaces' symbol\n");
return false;
}

Expand All @@ -319,36 +319,38 @@ bool init_classsharing_workaround(struct ps_prochandle* ph) {

sharedBaseAddressAddr = lookup_symbol(ph, jvm_name, SHARED_BASE_ADDRESS_SYM);
if (sharedBaseAddressAddr == 0) {
print_debug("can't lookup 'SharedBaseAddress' flag\n");
print_error("can't lookup 'SharedBaseAddress' flag\n");
return false;
}

if (read_pointer(ph, sharedBaseAddressAddr, &sharedBaseAddress) != true) {
print_debug("can't read the value of 'SharedBaseAddress' flag\n");
print_error("can't read the value of 'SharedBaseAddress' flag\n");
return false;
}

sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM);
if (sharedArchivePathAddrAddr == 0) {
print_debug("can't lookup shared archive path symbol\n");
print_error("can't lookup shared archive path symbol\n");
return false;
}

if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) {
print_debug("can't read shared archive path pointer\n");
print_error("can't read shared archive path pointer (%p)\n", sharedArchivePathAddrAddr);
return false;
}

classes_jsa[0] = 0;
if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
print_debug("can't read shared archive path value\n");
print_error("can't read shared archive path value (%p) (%p)\n",
(void*)sharedArchivePathAddrAddr, (void*)sharedArchivePathAddr);
return false;
}

print_debug("looking for %s\n", classes_jsa);
// open the class sharing archive file
fd = pathmap_open(classes_jsa);
if (fd < 0) {
print_debug("can't open %s!\n", classes_jsa);
print_error("can't open %s!\n", classes_jsa);
ph->core->classes_jsa_fd = -1;
return false;
} else {
Expand All @@ -360,22 +362,22 @@ bool init_classsharing_workaround(struct ps_prochandle* ph) {
memset(&header, 0, header_size);
if ((n = read(fd, &header, header_size))
!= header_size) {
print_debug("can't read shared archive file map header from %s\n", classes_jsa);
print_error("can't read shared archive file map header from %s\n", classes_jsa);
close(fd);
return false;
}

// check file magic
if (header._generic_header._magic != CDS_ARCHIVE_MAGIC) {
print_debug("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n",
print_error("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n",
classes_jsa, header._generic_header._magic, CDS_ARCHIVE_MAGIC);
close(fd);
return false;
}

// check version
if (header._generic_header._version != CURRENT_CDS_ARCHIVE_VERSION) {
print_debug("%s has wrong shared archive file version %d, expecting %d\n",
print_error("%s has wrong shared archive file version %d, expecting %d\n",
classes_jsa, header._generic_header._version, CURRENT_CDS_ARCHIVE_VERSION);
close(fd);
return false;
Expand Down

1 comment on commit 3b7fc80

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.