259 |
259 |
260 #ifdef LINUX |
260 #ifdef LINUX |
261 // mangled name of Arguments::SharedArchivePath |
261 // mangled name of Arguments::SharedArchivePath |
262 #define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE" |
262 #define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE" |
263 #define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
263 #define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
|
264 #define SHARED_BASE_ADDRESS_SYM "SharedBaseAddress" |
264 #define LIBJVM_NAME "/libjvm.so" |
265 #define LIBJVM_NAME "/libjvm.so" |
265 #endif |
266 #endif |
266 |
267 |
267 #ifdef __APPLE__ |
268 #ifdef __APPLE__ |
268 // mangled name of Arguments::SharedArchivePath |
269 // mangled name of Arguments::SharedArchivePath |
269 #define SHARED_ARCHIVE_PATH_SYM "__ZN9Arguments17SharedArchivePathE" |
270 #define SHARED_ARCHIVE_PATH_SYM "__ZN9Arguments17SharedArchivePathE" |
270 #define USE_SHARED_SPACES_SYM "_UseSharedSpaces" |
271 #define USE_SHARED_SPACES_SYM "_UseSharedSpaces" |
|
272 #define SHARED_BASE_ADDRESS_SYM "_SharedBaseAddress" |
271 #define LIBJVM_NAME "/libjvm.dylib" |
273 #define LIBJVM_NAME "/libjvm.dylib" |
272 #endif |
274 #endif |
273 |
275 |
274 bool init_classsharing_workaround(struct ps_prochandle* ph) { |
276 bool init_classsharing_workaround(struct ps_prochandle* ph) { |
275 lib_info* lib = ph->libs; |
277 lib_info* lib = ph->libs; |
279 const char *jvm_name = 0; |
281 const char *jvm_name = 0; |
280 if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { |
282 if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { |
281 char classes_jsa[PATH_MAX]; |
283 char classes_jsa[PATH_MAX]; |
282 CDSFileMapHeaderBase header; |
284 CDSFileMapHeaderBase header; |
283 int fd = -1; |
285 int fd = -1; |
284 uintptr_t base = 0, useSharedSpacesAddr = 0; |
286 uintptr_t useSharedSpacesAddr = 0; |
|
287 uintptr_t sharedBaseAddressAddr = 0, sharedBaseAddress = 0; |
285 uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0; |
288 uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0; |
286 jboolean useSharedSpaces = 0; |
289 jboolean useSharedSpaces = 0; |
287 int m; |
290 int m; |
288 size_t n; |
291 size_t n; |
289 |
292 |
304 } |
307 } |
305 |
308 |
306 if ((int)useSharedSpaces == 0) { |
309 if ((int)useSharedSpaces == 0) { |
307 print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
310 print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
308 return true; |
311 return true; |
|
312 } |
|
313 |
|
314 sharedBaseAddressAddr = lookup_symbol(ph, jvm_name, SHARED_BASE_ADDRESS_SYM); |
|
315 if (sharedBaseAddressAddr == 0) { |
|
316 print_debug("can't lookup 'SharedBaseAddress' flag\n"); |
|
317 return false; |
|
318 } |
|
319 |
|
320 if (read_pointer(ph, sharedBaseAddressAddr, &sharedBaseAddress) != true) { |
|
321 print_debug("can't read the value of 'SharedBaseAddress' flag\n"); |
|
322 return false; |
309 } |
323 } |
310 |
324 |
311 sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM); |
325 sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM); |
312 if (sharedArchivePathAddrAddr == 0) { |
326 if (sharedArchivePathAddrAddr == 0) { |
313 print_debug("can't lookup shared archive path symbol\n"); |
327 print_debug("can't lookup shared archive path symbol\n"); |
361 } |
375 } |
362 |
376 |
363 ph->core->classes_jsa_fd = fd; |
377 ph->core->classes_jsa_fd = fd; |
364 // add read-only maps from classes.jsa to the list of maps |
378 // add read-only maps from classes.jsa to the list of maps |
365 for (m = 0; m < NUM_CDS_REGIONS; m++) { |
379 for (m = 0; m < NUM_CDS_REGIONS; m++) { |
366 if (header._space[m]._read_only) { |
380 if (header._space[m]._read_only && |
|
381 !header._space[m]._is_heap_region && |
|
382 !header._space[m]._is_bitmap_region) { |
367 // With *some* linux versions, the core file doesn't include read-only mmap'ed |
383 // With *some* linux versions, the core file doesn't include read-only mmap'ed |
368 // files regions, so let's add them here. This is harmless if the core file also |
384 // files regions, so let's add them here. This is harmless if the core file also |
369 // include these regions. |
385 // include these regions. |
370 base = (uintptr_t) header._space[m]._addr._base; |
386 uintptr_t base = sharedBaseAddress + (uintptr_t) header._space[m]._mapping_offset; |
|
387 size_t size = header._space[m]._used; |
371 // no need to worry about the fractional pages at-the-end. |
388 // no need to worry about the fractional pages at-the-end. |
372 // possible fractional pages are handled by core_read_data. |
389 // possible fractional pages are handled by core_read_data. |
373 add_class_share_map_info(ph, (off_t) header._space[m]._file_offset, |
390 add_class_share_map_info(ph, (off_t) header._space[m]._file_offset, |
374 base, (size_t) header._space[m]._used); |
391 base, size); |
375 print_debug("added a share archive map at 0x%lx\n", base); |
392 print_debug("added a share archive map [%d] at 0x%lx (size 0x%lx bytes)\n", m, base, size); |
376 } |
393 } |
377 } |
394 } |
378 return true; |
395 return true; |
379 } |
396 } |
380 lib = lib->next; |
397 lib = lib->next; |