src/os/posix/vm/os_posix.cpp

Print this page


   1 /*
   2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
   3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 *
   5 * This code is free software; you can redistribute it and/or modify it
   6 * under the terms of the GNU General Public License version 2 only, as
   7 * published by the Free Software Foundation.
   8 *
   9 * This code is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 * version 2 for more details (a copy is included in the LICENSE file that
  13 * accompanied this code).
  14 *
  15 * You should have received a copy of the GNU General Public License version
  16 * 2 along with this work; if not, write to the Free Software Foundation,
  17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 *
  19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 *


 241       julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
 242       temp_limit = align_size_down_(temp_limit, min_allocation_size);
 243       if (is_allocatable(temp_limit)) {
 244         lower_limit = temp_limit;
 245       } else {
 246         upper_limit = temp_limit;
 247       }
 248     }
 249     *limit = lower_limit;
 250   }
 251   return true;
 252 #endif
 253 }
 254 
 255 const char* os::get_current_directory(char *buf, size_t buflen) {
 256   return getcwd(buf, buflen);
 257 }
 258 
 259 FILE* os::open(int fd, const char* mode) {
 260   return ::fdopen(fd, mode);

















































 261 }
 262 
 263 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
 264   assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
 265 }
 266 
 267 /*
 268  * See the caveats for this class in os_posix.hpp
 269  * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
 270  * method and returns false. If none of the signals are raised, returns true.
 271  * The callback is supposed to provide the method that should be protected.
 272  */
 273 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
 274   assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
 275   assert(!WatcherThread::watcher_thread()->has_crash_protection(),
 276       "crash_protection already set?");
 277 
 278   if (sigsetjmp(_jmpbuf, 1) == 0) {
 279     // make sure we can see in the signal handler that we have crash protection
 280     // installed


   1 /*
   2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
   3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 *
   5 * This code is free software; you can redistribute it and/or modify it
   6 * under the terms of the GNU General Public License version 2 only, as
   7 * published by the Free Software Foundation.
   8 *
   9 * This code is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 * version 2 for more details (a copy is included in the LICENSE file that
  13 * accompanied this code).
  14 *
  15 * You should have received a copy of the GNU General Public License version
  16 * 2 along with this work; if not, write to the Free Software Foundation,
  17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 *
  19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 *


 241       julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
 242       temp_limit = align_size_down_(temp_limit, min_allocation_size);
 243       if (is_allocatable(temp_limit)) {
 244         lower_limit = temp_limit;
 245       } else {
 246         upper_limit = temp_limit;
 247       }
 248     }
 249     *limit = lower_limit;
 250   }
 251   return true;
 252 #endif
 253 }
 254 
 255 const char* os::get_current_directory(char *buf, size_t buflen) {
 256   return getcwd(buf, buflen);
 257 }
 258 
 259 FILE* os::open(int fd, const char* mode) {
 260   return ::fdopen(fd, mode);
 261 }
 262 
 263 void* os::get_default_process_handle() {
 264   return (void*)::dlopen(NULL, RTLD_LAZY);
 265 }
 266 
 267 // Builds a platform dependent Agent_OnLoad_<lib_name> function name
 268 // which is used to find statically linked in agents. 
 269 // Parameters:
 270 //            sym_name: Symbol in library we are looking for
 271 //            lib_name: Name of library to look in, NULL for shared libs.
 272 //            is_absolute_path == true if lib_name is absolute path to agent
 273 //                                     such as "/a/b/libL.so"
 274 //            == false if only the base name of the library is passed in
 275 //               such as "L"
 276 char* os::build_agent_function_name(const char *symName, const char *lib_name,
 277                                     bool is_absolute_path) {
 278   char *agent_entry_name;
 279   size_t len;
 280   size_t name_len;
 281   size_t prefix_len = strlen(JNI_LIB_PREFIX);
 282   size_t suffix_len = strlen(JNI_LIB_SUFFIX);
 283   const char *start;
 284 
 285   if (lib_name != NULL) {
 286     len = name_len = strlen(lib_name);
 287     if (is_absolute_path) {
 288       // Need to strip path, prefix and suffix
 289       if ((start = strrchr(lib_name, *os::file_separator())) != NULL) {
 290         lib_name = ++start;
 291       }
 292       if (len <= (prefix_len + suffix_len)) {
 293         return NULL;
 294       }
 295       lib_name += prefix_len;
 296       name_len = strlen(lib_name) - suffix_len;
 297     }
 298   }
 299   len = (lib_name != NULL ? name_len : 0) + strlen(symName) + 2;
 300   agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread);
 301   if (agent_entry_name == NULL) {
 302     return NULL;
 303   }
 304   strcpy(agent_entry_name, symName);
 305   if (lib_name != NULL) {
 306     strcat(agent_entry_name, "_");
 307     strncat(agent_entry_name, lib_name, name_len);
 308   }
 309   return agent_entry_name;
 310 }
 311 
 312 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
 313   assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
 314 }
 315 
 316 /*
 317  * See the caveats for this class in os_posix.hpp
 318  * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
 319  * method and returns false. If none of the signals are raised, returns true.
 320  * The callback is supposed to provide the method that should be protected.
 321  */
 322 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
 323   assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
 324   assert(!WatcherThread::watcher_thread()->has_crash_protection(),
 325       "crash_protection already set?");
 326 
 327   if (sigsetjmp(_jmpbuf, 1) == 0) {
 328     // make sure we can see in the signal handler that we have crash protection
 329     // installed