src/os/linux/vm/os_linux.cpp

changeset 9858
b985cbb00e68
parent 9711
0f2fe7d37d8c
child 9877
4937bafbb2f8
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Thu Aug 01 03:44:03 2019 +0100
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Mon Aug 12 18:30:40 2019 +0300
     1.3 @@ -2146,6 +2146,41 @@
     1.4     }
     1.5  }
     1.6  
     1.7 +int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
     1.8 +  FILE *procmapsFile = NULL;
     1.9 +
    1.10 +  // Open the procfs maps file for the current process
    1.11 +  if ((procmapsFile = fopen("/proc/self/maps", "r")) != NULL) {
    1.12 +    // Allocate PATH_MAX for file name plus a reasonable size for other fields.
    1.13 +    char line[PATH_MAX + 100];
    1.14 +
    1.15 +    // Read line by line from 'file'
    1.16 +    while (fgets(line, sizeof(line), procmapsFile) != NULL) {
    1.17 +      u8 base, top, offset, inode;
    1.18 +      char permissions[5];
    1.19 +      char device[6];
    1.20 +      char name[PATH_MAX + 1];
    1.21 +
    1.22 +      // Parse fields from line
    1.23 +      sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %5s " INT64_FORMAT " %s",
    1.24 +             &base, &top, permissions, &offset, device, &inode, name);
    1.25 +
    1.26 +      // Filter by device id '00:00' so that we only get file system mapped files.
    1.27 +      if (strcmp(device, "00:00") != 0) {
    1.28 +
    1.29 +        // Call callback with the fields of interest
    1.30 +        if(callback(name, (address)base, (address)top, param)) {
    1.31 +          // Oops abort, callback aborted
    1.32 +          fclose(procmapsFile);
    1.33 +          return 1;
    1.34 +        }
    1.35 +      }
    1.36 +    }
    1.37 +    fclose(procmapsFile);
    1.38 +  }
    1.39 +  return 0;
    1.40 +}
    1.41 +
    1.42  void os::print_os_info_brief(outputStream* st) {
    1.43    os::Linux::print_distro_info(st);
    1.44  
    1.45 @@ -4030,6 +4065,10 @@
    1.46    return ::read(fd, buf, nBytes);
    1.47  }
    1.48  
    1.49 +size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
    1.50 +  return ::pread(fd, buf, nBytes, offset);
    1.51 +}
    1.52 +
    1.53  // TODO-FIXME: reconcile Solaris' os::sleep with the linux variation.
    1.54  // Solaris uses poll(), linux uses park().
    1.55  // Poll() is likely a better choice, assuming that Thread.interrupt()

mercurial