Skip to content

Commit 3b7fc80

Browse files
committed
8294411: SA should provide more useful info when it fails to start up due to "failed to workaround classshareing"
Reviewed-by: kevinw, sspitsyn
1 parent 4fb424b commit 3b7fc80

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/jdk.hotspot.agent/share/native/libsaproc/ps_core_common.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -123,7 +123,7 @@ void core_release(struct ps_prochandle* ph) {
123123
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz, uint32_t flags) {
124124
map_info* map;
125125
if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
126-
print_debug("can't allocate memory for map_info\n");
126+
print_error("can't allocate memory for map_info\n");
127127
return NULL;
128128
}
129129

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

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

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

320320
sharedBaseAddressAddr = lookup_symbol(ph, jvm_name, SHARED_BASE_ADDRESS_SYM);
321321
if (sharedBaseAddressAddr == 0) {
322-
print_debug("can't lookup 'SharedBaseAddress' flag\n");
322+
print_error("can't lookup 'SharedBaseAddress' flag\n");
323323
return false;
324324
}
325325

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

331331
sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM);
332332
if (sharedArchivePathAddrAddr == 0) {
333-
print_debug("can't lookup shared archive path symbol\n");
333+
print_error("can't lookup shared archive path symbol\n");
334334
return false;
335335
}
336336

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

342+
classes_jsa[0] = 0;
342343
if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
343-
print_debug("can't read shared archive path value\n");
344+
print_error("can't read shared archive path value (%p) (%p)\n",
345+
(void*)sharedArchivePathAddrAddr, (void*)sharedArchivePathAddr);
344346
return false;
345347
}
346348

347349
print_debug("looking for %s\n", classes_jsa);
348350
// open the class sharing archive file
349351
fd = pathmap_open(classes_jsa);
350352
if (fd < 0) {
351-
print_debug("can't open %s!\n", classes_jsa);
353+
print_error("can't open %s!\n", classes_jsa);
352354
ph->core->classes_jsa_fd = -1;
353355
return false;
354356
} else {
@@ -360,22 +362,22 @@ bool init_classsharing_workaround(struct ps_prochandle* ph) {
360362
memset(&header, 0, header_size);
361363
if ((n = read(fd, &header, header_size))
362364
!= header_size) {
363-
print_debug("can't read shared archive file map header from %s\n", classes_jsa);
365+
print_error("can't read shared archive file map header from %s\n", classes_jsa);
364366
close(fd);
365367
return false;
366368
}
367369

368370
// check file magic
369371
if (header._generic_header._magic != CDS_ARCHIVE_MAGIC) {
370-
print_debug("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n",
372+
print_error("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n",
371373
classes_jsa, header._generic_header._magic, CDS_ARCHIVE_MAGIC);
372374
close(fd);
373375
return false;
374376
}
375377

376378
// check version
377379
if (header._generic_header._version != CURRENT_CDS_ARCHIVE_VERSION) {
378-
print_debug("%s has wrong shared archive file version %d, expecting %d\n",
380+
print_error("%s has wrong shared archive file version %d, expecting %d\n",
379381
classes_jsa, header._generic_header._version, CURRENT_CDS_ARCHIVE_VERSION);
380382
close(fd);
381383
return false;

0 commit comments

Comments
 (0)