< prev index next >

src/hotspot/share/runtime/os.cpp

Print this page

 280 }
 281 
 282 // Frees all memory allocated on the heap for the
 283 // supplied array of arrays of chars (a), where n
 284 // is the number of elements in the array.
 285 static void free_array_of_char_arrays(char** a, size_t n) {
 286       while (n > 0) {
 287           n--;
 288           if (a[n] != NULL) {
 289             FREE_C_HEAP_ARRAY(char, a[n]);
 290           }
 291       }
 292       FREE_C_HEAP_ARRAY(char*, a);
 293 }
 294 
 295 bool os::dll_locate_lib(char *buffer, size_t buflen,
 296                         const char* pname, const char* fname) {
 297   bool retval = false;
 298 
 299   size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX);
 300   char* fullfname = (char*)NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal);
 301   if (dll_build_name(fullfname, fullfnamelen + 1, fname)) {
 302     const size_t pnamelen = pname ? strlen(pname) : 0;
 303 
 304     if (pnamelen == 0) {
 305       // If no path given, use current working directory.
 306       const char* p = get_current_directory(buffer, buflen);
 307       if (p != NULL) {
 308         const size_t plen = strlen(buffer);
 309         const char lastchar = buffer[plen - 1];
 310         retval = conc_path_file_and_check(buffer, &buffer[plen], buflen - plen,
 311                                           "", lastchar, fullfname);
 312       }
 313     } else if (strchr(pname, *os::path_separator()) != NULL) {
 314       // A list of paths. Search for the path that contains the library.
 315       size_t n;
 316       char** pelements = split_path(pname, &n, fullfnamelen);
 317       if (pelements != NULL) {
 318         for (size_t i = 0; i < n; i++) {
 319           char* path = pelements[i];
 320           // Really shouldn't be NULL, but check can't hurt.

1318 
1319 // Splits a path, based on its separator, the number of
1320 // elements is returned back in "elements".
1321 // file_name_length is used as a modifier for each path's
1322 // length when compared to JVM_MAXPATHLEN. So if you know
1323 // each returned path will have something appended when
1324 // in use, you can pass the length of that in
1325 // file_name_length, to ensure we detect if any path
1326 // exceeds the maximum path length once prepended onto
1327 // the sub-path/file name.
1328 // It is the callers responsibility to:
1329 //   a> check the value of "elements", which may be 0.
1330 //   b> ignore any empty path elements
1331 //   c> free up the data.
1332 char** os::split_path(const char* path, size_t* elements, size_t file_name_length) {
1333   *elements = (size_t)0;
1334   if (path == NULL || strlen(path) == 0 || file_name_length == (size_t)NULL) {
1335     return NULL;
1336   }
1337   const char psepchar = *os::path_separator();
1338   char* inpath = (char*)NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal);
1339   if (inpath == NULL) {
1340     return NULL;
1341   }
1342   strcpy(inpath, path);
1343   size_t count = 1;
1344   char* p = strchr(inpath, psepchar);
1345   // Get a count of elements to allocate memory
1346   while (p != NULL) {
1347     count++;
1348     p++;
1349     p = strchr(p, psepchar);
1350   }
1351   char** opath = (char**) NEW_C_HEAP_ARRAY(char*, count, mtInternal);

1352 
1353   // do the actual splitting
1354   p = inpath;
1355   for (size_t i = 0 ; i < count ; i++) {
1356     size_t len = strcspn(p, os::path_separator());
1357     if (len + file_name_length > JVM_MAXPATHLEN) {
1358       // release allocated storage before exiting the vm
1359       free_array_of_char_arrays(opath, i++);
1360       vm_exit_during_initialization("The VM tried to use a path that exceeds the maximum path length for "
1361                                     "this system. Review path-containing parameters and properties, such as "
1362                                     "sun.boot.library.path, to identify potential sources for this path.");
1363     }
1364     // allocate the string and add terminator storage
1365     char* s  = (char*)NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal);

1366     if (s == NULL) {
1367       // release allocated storage before returning null
1368       free_array_of_char_arrays(opath, i++);
1369       return NULL;
1370     }
1371     strncpy(s, p, len);
1372     s[len] = '\0';
1373     opath[i] = s;
1374     p += len + 1;
1375   }
1376   FREE_C_HEAP_ARRAY(char, inpath);
1377   *elements = count;
1378   return opath;
1379 }
1380 
1381 // Returns true if the current stack pointer is above the stack shadow
1382 // pages, false otherwise.
1383 bool os::stack_shadow_pages_available(Thread *thread, const methodHandle& method, address sp) {
1384   if (!thread->is_Java_thread()) return false;
1385   // Check if we have StackShadowPages above the yellow zone.  This parameter

 280 }
 281 
 282 // Frees all memory allocated on the heap for the
 283 // supplied array of arrays of chars (a), where n
 284 // is the number of elements in the array.
 285 static void free_array_of_char_arrays(char** a, size_t n) {
 286       while (n > 0) {
 287           n--;
 288           if (a[n] != NULL) {
 289             FREE_C_HEAP_ARRAY(char, a[n]);
 290           }
 291       }
 292       FREE_C_HEAP_ARRAY(char*, a);
 293 }
 294 
 295 bool os::dll_locate_lib(char *buffer, size_t buflen,
 296                         const char* pname, const char* fname) {
 297   bool retval = false;
 298 
 299   size_t fullfnamelen = strlen(JNI_LIB_PREFIX) + strlen(fname) + strlen(JNI_LIB_SUFFIX);
 300   char* fullfname = NEW_C_HEAP_ARRAY(char, fullfnamelen + 1, mtInternal);
 301   if (dll_build_name(fullfname, fullfnamelen + 1, fname)) {
 302     const size_t pnamelen = pname ? strlen(pname) : 0;
 303 
 304     if (pnamelen == 0) {
 305       // If no path given, use current working directory.
 306       const char* p = get_current_directory(buffer, buflen);
 307       if (p != NULL) {
 308         const size_t plen = strlen(buffer);
 309         const char lastchar = buffer[plen - 1];
 310         retval = conc_path_file_and_check(buffer, &buffer[plen], buflen - plen,
 311                                           "", lastchar, fullfname);
 312       }
 313     } else if (strchr(pname, *os::path_separator()) != NULL) {
 314       // A list of paths. Search for the path that contains the library.
 315       size_t n;
 316       char** pelements = split_path(pname, &n, fullfnamelen);
 317       if (pelements != NULL) {
 318         for (size_t i = 0; i < n; i++) {
 319           char* path = pelements[i];
 320           // Really shouldn't be NULL, but check can't hurt.

1318 
1319 // Splits a path, based on its separator, the number of
1320 // elements is returned back in "elements".
1321 // file_name_length is used as a modifier for each path's
1322 // length when compared to JVM_MAXPATHLEN. So if you know
1323 // each returned path will have something appended when
1324 // in use, you can pass the length of that in
1325 // file_name_length, to ensure we detect if any path
1326 // exceeds the maximum path length once prepended onto
1327 // the sub-path/file name.
1328 // It is the callers responsibility to:
1329 //   a> check the value of "elements", which may be 0.
1330 //   b> ignore any empty path elements
1331 //   c> free up the data.
1332 char** os::split_path(const char* path, size_t* elements, size_t file_name_length) {
1333   *elements = (size_t)0;
1334   if (path == NULL || strlen(path) == 0 || file_name_length == (size_t)NULL) {
1335     return NULL;
1336   }
1337   const char psepchar = *os::path_separator();
1338   char* inpath = NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal);
1339   if (inpath == NULL) {
1340     return NULL;
1341   }
1342   strcpy(inpath, path);
1343   size_t count = 1;
1344   char* p = strchr(inpath, psepchar);
1345   // Get a count of elements to allocate memory
1346   while (p != NULL) {
1347     count++;
1348     p++;
1349     p = strchr(p, psepchar);
1350   }
1351 
1352   char** opath = NEW_C_HEAP_ARRAY(char*, count, mtInternal);
1353 
1354   // do the actual splitting
1355   p = inpath;
1356   for (size_t i = 0 ; i < count ; i++) {
1357     size_t len = strcspn(p, os::path_separator());
1358     if (len + file_name_length > JVM_MAXPATHLEN) {
1359       // release allocated storage before exiting the vm
1360       free_array_of_char_arrays(opath, i++);
1361       vm_exit_during_initialization("The VM tried to use a path that exceeds the maximum path length for "
1362                                     "this system. Review path-containing parameters and properties, such as "
1363                                     "sun.boot.library.path, to identify potential sources for this path.");
1364     }
1365     // allocate the string and add terminator storage
1366     char* s  = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal);
1367 
1368     if (s == NULL) {
1369       // release allocated storage before returning null
1370       free_array_of_char_arrays(opath, i++);
1371       return NULL;
1372     }
1373     strncpy(s, p, len);
1374     s[len] = '\0';
1375     opath[i] = s;
1376     p += len + 1;
1377   }
1378   FREE_C_HEAP_ARRAY(char, inpath);
1379   *elements = count;
1380   return opath;
1381 }
1382 
1383 // Returns true if the current stack pointer is above the stack shadow
1384 // pages, false otherwise.
1385 bool os::stack_shadow_pages_available(Thread *thread, const methodHandle& method, address sp) {
1386   if (!thread->is_Java_thread()) return false;
1387   // Check if we have StackShadowPages above the yellow zone.  This parameter
< prev index next >