< prev index next >

src/os/posix/vm/os_posix.cpp

Print this page




 128   return (::unsetenv(name) == 0);
 129 }
 130 
 131 int os::get_last_error() {
 132   return errno;
 133 }
 134 
 135 bool os::is_debugger_attached() {
 136   // not implemented
 137   return false;
 138 }
 139 
 140 void os::wait_for_keypress_at_exit(void) {
 141   // don't do anything on posix platforms
 142   return;
 143 }
 144 
 145 // Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
 146 // so on posix, unmap the section at the start and at the end of the chunk that we mapped
 147 // rather than unmapping and remapping the whole chunk to get requested alignment.
 148 char* os::reserve_memory_aligned(size_t size, size_t alignment) {
 149   assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
 150       "Alignment must be a multiple of allocation granularity (page size)");
 151   assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
 152 
 153   size_t extra_size = size + alignment;
 154   assert(extra_size >= size, "overflow, size is too large to allow alignment");
 155 
 156   char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
 157 
 158   if (extra_base == NULL) {
 159     return NULL;
 160   }
 161 
 162   // Do manual alignment
 163   char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
 164 
 165   // [  |                                       |  ]
 166   // ^ extra_base
 167   //    ^ extra_base + begin_offset == aligned_base
 168   //     extra_base + begin_offset + size       ^
 169   //                       extra_base + extra_size ^
 170   // |<>| == begin_offset
 171   //                              end_offset == |<>|
 172   size_t begin_offset = aligned_base - extra_base;
 173   size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
 174 
 175   if (begin_offset > 0) {
 176       os::release_memory(extra_base, begin_offset);
 177   }
 178 
 179   if (end_offset > 0) {
 180       os::release_memory(extra_base + begin_offset + size, end_offset);
 181   }
 182 





 183   return aligned_base;
 184 }
 185 
 186 int os::log_vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
 187     return vsnprintf(buf, len, fmt, args);
 188 }
 189 
 190 int os::get_fileno(FILE* fp) {
 191   return NOT_AIX(::)fileno(fp);
 192 }
 193 
 194 void os::Posix::print_load_average(outputStream* st) {
 195   st->print("load average:");
 196   double loadavg[3];
 197   os::loadavg(loadavg, 3);
 198   st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
 199   st->cr();
 200 }
 201 
 202 void os::Posix::print_rlimit_info(outputStream* st) {




 128   return (::unsetenv(name) == 0);
 129 }
 130 
 131 int os::get_last_error() {
 132   return errno;
 133 }
 134 
 135 bool os::is_debugger_attached() {
 136   // not implemented
 137   return false;
 138 }
 139 
 140 void os::wait_for_keypress_at_exit(void) {
 141   // don't do anything on posix platforms
 142   return;
 143 }
 144 
 145 // Multiple threads can race in this code, and can remap over each other with MAP_FIXED,
 146 // so on posix, unmap the section at the start and at the end of the chunk that we mapped
 147 // rather than unmapping and remapping the whole chunk to get requested alignment.
 148 char* os::reserve_memory_aligned(size_t size, size_t alignment, int file_desc) {
 149   assert((alignment & (os::vm_allocation_granularity() - 1)) == 0,
 150       "Alignment must be a multiple of allocation granularity (page size)");
 151   assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned");
 152 
 153   size_t extra_size = size + alignment;
 154   assert(extra_size >= size, "overflow, size is too large to allow alignment");
 155 
 156   char* extra_base = os::reserve_memory(extra_size, NULL, alignment);
 157 
 158   if (extra_base == NULL) {
 159     return NULL;
 160   }
 161 
 162   // Do manual alignment
 163   char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment);
 164 
 165   // [  |                                       |  ]
 166   // ^ extra_base
 167   //    ^ extra_base + begin_offset == aligned_base
 168   //     extra_base + begin_offset + size       ^
 169   //                       extra_base + extra_size ^
 170   // |<>| == begin_offset
 171   //                              end_offset == |<>|
 172   size_t begin_offset = aligned_base - extra_base;
 173   size_t end_offset = (extra_base + extra_size) - (aligned_base + size);
 174 
 175   if (begin_offset > 0) {
 176       os::release_memory(extra_base, begin_offset);
 177   }
 178 
 179   if (end_offset > 0) {
 180       os::release_memory(extra_base + begin_offset + size, end_offset);
 181   }
 182 
 183   if (file_desc != -1) {
 184     if (os::map_memory_to_file(aligned_base, size, file_desc) == NULL) {
 185       vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
 186     }
 187   }
 188   return aligned_base;
 189 }
 190 
 191 int os::log_vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
 192     return vsnprintf(buf, len, fmt, args);
 193 }
 194 
 195 int os::get_fileno(FILE* fp) {
 196   return NOT_AIX(::)fileno(fp);
 197 }
 198 
 199 void os::Posix::print_load_average(outputStream* st) {
 200   st->print("load average:");
 201   double loadavg[3];
 202   os::loadavg(loadavg, 3);
 203   st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
 204   st->cr();
 205 }
 206 
 207 void os::Posix::print_rlimit_info(outputStream* st) {


< prev index next >