< prev index next >

src/os/linux/vm/perfMemory_linux.cpp

Print this page
rev 11747 : 8162869: Small fixes for AIX perf memory and attach listener


 874   if (result != -1) {
 875     return fd;
 876   } else {
 877     ::close(fd);
 878     return -1;
 879   }
 880 }
 881 
 882 // open the shared memory file for the given user and vmid. returns
 883 // the file descriptor for the open file or -1 if the file could not
 884 // be opened.
 885 //
 886 static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
 887 
 888   // open the file
 889   int result;
 890   RESTARTABLE(::open(filename, oflags), result);
 891   if (result == OS_ERR) {
 892     if (errno == ENOENT) {
 893       THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 894                   "Process not found", OS_ERR);
 895     }
 896     else if (errno == EACCES) {
 897       THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 898                   "Permission denied", OS_ERR);
 899     }
 900     else {
 901       THROW_MSG_(vmSymbols::java_io_IOException(), os::strerror(errno), OS_ERR);

 902     }
 903   }
 904   int fd = result;
 905 
 906   // check to see if the file is secure
 907   if (!is_file_secure(fd, filename)) {
 908     ::close(fd);
 909     return -1;
 910   }
 911 
 912   return fd;
 913 }
 914 
 915 // create a named shared memory region. returns the address of the
 916 // memory region on success or NULL on failure. A return value of
 917 // NULL will ultimately disable the shared memory feature.
 918 //
 919 // On Solaris and Linux, the name space for shared memory objects
 920 // is the file system name space.
 921 //
 922 // A monitoring application attaching to a JVM does not need to know
 923 // the file system name of the shared memory object. However, it may
 924 // be convenient for applications to discover the existence of newly
 925 // created and terminating JVMs by watching the file system name space
 926 // for files being created or removed.
 927 //
 928 static char* mmap_create_shared(size_t size) {
 929 
 930   int result;
 931   int fd;
 932   char* mapAddress;
 933 
 934   int vmid = os::current_process_id();
 935 
 936   char* user_name = get_user_name(geteuid());
 937 
 938   if (user_name == NULL)
 939     return NULL;
 940 
 941   char* dirname = get_user_tmp_dir(user_name);
 942   char* filename = get_sharedmem_filename(dirname, vmid);

 943   // get the short filename
 944   char* short_filename = strrchr(filename, '/');
 945   if (short_filename == NULL) {
 946     short_filename = filename;
 947   } else {
 948     short_filename++;
 949   }
 950 
 951   // cleanup any stale shared memory files
 952   cleanup_sharedmem_resources(dirname);
 953 
 954   assert(((size > 0) && (size % os::vm_page_size() == 0)),
 955          "unexpected PerfMemory region size");
 956 
 957   fd = create_sharedmem_resources(dirname, short_filename, size);
 958 
 959   FREE_C_HEAP_ARRAY(char, user_name);
 960   FREE_C_HEAP_ARRAY(char, dirname);
 961 
 962   if (fd == -1) {




 874   if (result != -1) {
 875     return fd;
 876   } else {
 877     ::close(fd);
 878     return -1;
 879   }
 880 }
 881 
 882 // open the shared memory file for the given user and vmid. returns
 883 // the file descriptor for the open file or -1 if the file could not
 884 // be opened.
 885 //
 886 static int open_sharedmem_file(const char* filename, int oflags, TRAPS) {
 887 
 888   // open the file
 889   int result;
 890   RESTARTABLE(::open(filename, oflags), result);
 891   if (result == OS_ERR) {
 892     if (errno == ENOENT) {
 893       THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 894                  "Process not found", OS_ERR);
 895     }
 896     else if (errno == EACCES) {
 897       THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
 898                  "Permission denied", OS_ERR);
 899     }
 900     else {
 901       THROW_MSG_(vmSymbols::java_io_IOException(),
 902                  os::strerror(errno), OS_ERR);
 903     }
 904   }
 905   int fd = result;
 906 
 907   // check to see if the file is secure
 908   if (!is_file_secure(fd, filename)) {
 909     ::close(fd);
 910     return -1;
 911   }
 912 
 913   return fd;
 914 }
 915 
 916 // create a named shared memory region. returns the address of the
 917 // memory region on success or NULL on failure. A return value of
 918 // NULL will ultimately disable the shared memory feature.
 919 //
 920 // On Linux, the name space for shared memory objects
 921 // is the file system name space.
 922 //
 923 // A monitoring application attaching to a JVM does not need to know
 924 // the file system name of the shared memory object. However, it may
 925 // be convenient for applications to discover the existence of newly
 926 // created and terminating JVMs by watching the file system name space
 927 // for files being created or removed.
 928 //
 929 static char* mmap_create_shared(size_t size) {
 930 
 931   int result;
 932   int fd;
 933   char* mapAddress;
 934 
 935   int vmid = os::current_process_id();
 936 
 937   char* user_name = get_user_name(geteuid());
 938 
 939   if (user_name == NULL)
 940     return NULL;
 941 
 942   char* dirname = get_user_tmp_dir(user_name);
 943   char* filename = get_sharedmem_filename(dirname, vmid);
 944 
 945   // get the short filename
 946   char* short_filename = strrchr(filename, '/');
 947   if (short_filename == NULL) {
 948     short_filename = filename;
 949   } else {
 950     short_filename++;
 951   }
 952 
 953   // cleanup any stale shared memory files
 954   cleanup_sharedmem_resources(dirname);
 955 
 956   assert(((size > 0) && (size % os::vm_page_size() == 0)),
 957          "unexpected PerfMemory region size");
 958 
 959   fd = create_sharedmem_resources(dirname, short_filename, size);
 960 
 961   FREE_C_HEAP_ARRAY(char, user_name);
 962   FREE_C_HEAP_ARRAY(char, dirname);
 963 
 964   if (fd == -1) {


< prev index next >