< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




 114   #undef _GNU_SOURCE
 115 #else
 116   #include <sched.h>
 117 #endif
 118 
 119 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 120 // getrusage() is prepared to handle the associated failure.
 121 #ifndef RUSAGE_THREAD
 122   #define RUSAGE_THREAD   (1)               /* only the calling thread */
 123 #endif
 124 
 125 #define MAX_PATH    (2 * K)
 126 
 127 #define MAX_SECS 100000000
 128 
 129 // for timer info max values which include all bits
 130 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 131 
 132 enum CoredumpFilterBit {
 133   FILE_BACKED_PVT_BIT = 1 << 2,

 134   LARGEPAGES_BIT = 1 << 6,
 135   DAX_SHARED_BIT = 1 << 8
 136 };
 137 
 138 ////////////////////////////////////////////////////////////////////////////////
 139 // global variables
 140 julong os::Linux::_physical_memory = 0;
 141 
 142 address   os::Linux::_initial_thread_stack_bottom = NULL;
 143 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 144 
 145 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 146 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
 147 Mutex* os::Linux::_createThread_lock = NULL;
 148 pthread_t os::Linux::_main_thread;
 149 int os::Linux::_page_size = -1;
 150 bool os::Linux::_supports_fast_thread_cpu_time = false;
 151 uint32_t os::Linux::_os_version = 0;
 152 const char * os::Linux::_glibc_version = NULL;
 153 const char * os::Linux::_libpthread_version = NULL;


1340   // needs to remove object in file system
1341   AttachListener::abort();
1342 
1343   // flush buffered output, finish log files
1344   ostream_abort();
1345 
1346   // Check for abort hook
1347   abort_hook_t abort_hook = Arguments::abort_hook();
1348   if (abort_hook != NULL) {
1349     abort_hook();
1350   }
1351 
1352 }
1353 
1354 // Note: os::abort() might be called very early during initialization, or
1355 // called from signal handler. Before adding something to os::abort(), make
1356 // sure it is async-safe and can handle partially initialized VM.
1357 void os::abort(bool dump_core, void* siginfo, const void* context) {
1358   os::shutdown();
1359   if (dump_core) {
1360 #if INCLUDE_CDS
1361     if (UseSharedSpaces && DumpPrivateMappingsInCore) {
1362       ClassLoader::close_jrt_image();
1363     }
1364 #endif
1365 #ifndef PRODUCT
1366     fdStream out(defaultStream::output_fd());
1367     out.print_raw("Current thread is ");
1368     char buf[16];
1369     jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
1370     out.print_raw_cr(buf);
1371     out.print_raw_cr("Dumping core ...");
1372 #endif
1373     ::abort(); // dump core
1374   }
1375 
1376   ::exit(1);
1377 }
1378 
1379 // Die immediately, no exit hook, no abort hook, no cleanup.
1380 void os::die() {
1381   ::abort();


3415               && x == (long)p) {
3416             if (strstr (chars, "hugepage")) {
3417               result = true;
3418               break;
3419             }
3420           }
3421         }
3422       }
3423       fclose(fp);
3424     }
3425     munmap(p, page_size);
3426   }
3427 
3428   if (warn && !result) {
3429     warning("HugeTLBFS is not supported by the operating system.");
3430   }
3431 
3432   return result;
3433 }
3434 
3435 // Set the coredump_filter bits to include largepages in core dump (bit 6)
3436 //
3437 // From the coredump_filter documentation:
3438 //
3439 // - (bit 0) anonymous private memory
3440 // - (bit 1) anonymous shared memory
3441 // - (bit 2) file-backed private memory
3442 // - (bit 3) file-backed shared memory
3443 // - (bit 4) ELF header pages in file-backed private memory areas (it is
3444 //           effective only if the bit 2 is cleared)
3445 // - (bit 5) hugetlb private memory
3446 // - (bit 6) hugetlb shared memory
3447 // - (bit 7) dax private memory
3448 // - (bit 8) dax shared memory
3449 //
3450 static void set_coredump_filter(CoredumpFilterBit bit) {
3451   FILE *f;
3452   long cdm;
3453 
3454   if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
3455     return;
3456   }


5114     // only register atexit functions if PerfAllowAtExitRegistration is set.
5115     // atexit functions can be delayed until process exit time, which
5116     // can be problematic for embedded VM situations. Embedded VMs should
5117     // call DestroyJavaVM() to assure that VM resources are released.
5118 
5119     // note: perfMemory_exit_helper atexit function may be removed in
5120     // the future if the appropriate cleanup code can be added to the
5121     // VM_Exit VMOperation's doit method.
5122     if (atexit(perfMemory_exit_helper) != 0) {
5123       warning("os::init_2 atexit(perfMemory_exit_helper) failed");
5124     }
5125   }
5126 
5127   // initialize thread priority policy
5128   prio_init();
5129 
5130   if (!FLAG_IS_DEFAULT(AllocateHeapAt) || !FLAG_IS_DEFAULT(AllocateOldGenAt)) {
5131     set_coredump_filter(DAX_SHARED_BIT);
5132   }
5133 
5134 #if INCLUDE_CDS
5135   if (UseSharedSpaces && DumpPrivateMappingsInCore) {
5136     set_coredump_filter(FILE_BACKED_PVT_BIT);
5137   }
5138 #endif



5139 
5140   return JNI_OK;
5141 }
5142 
5143 // Mark the polling page as unreadable
5144 void os::make_polling_page_unreadable(void) {
5145   if (!guard_memory((char*)_polling_page, Linux::page_size())) {
5146     fatal("Could not disable polling page");
5147   }
5148 }
5149 
5150 // Mark the polling page as readable
5151 void os::make_polling_page_readable(void) {
5152   if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
5153     fatal("Could not enable polling page");
5154   }
5155 }
5156 
5157 // older glibc versions don't have this macro (which expands to
5158 // an optimized bit-counting function) so we have to roll our own




 114   #undef _GNU_SOURCE
 115 #else
 116   #include <sched.h>
 117 #endif
 118 
 119 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 120 // getrusage() is prepared to handle the associated failure.
 121 #ifndef RUSAGE_THREAD
 122   #define RUSAGE_THREAD   (1)               /* only the calling thread */
 123 #endif
 124 
 125 #define MAX_PATH    (2 * K)
 126 
 127 #define MAX_SECS 100000000
 128 
 129 // for timer info max values which include all bits
 130 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 131 
 132 enum CoredumpFilterBit {
 133   FILE_BACKED_PVT_BIT = 1 << 2,
 134   FILE_BACKED_SHARED_BIT = 1 << 3,
 135   LARGEPAGES_BIT = 1 << 6,
 136   DAX_SHARED_BIT = 1 << 8
 137 };
 138 
 139 ////////////////////////////////////////////////////////////////////////////////
 140 // global variables
 141 julong os::Linux::_physical_memory = 0;
 142 
 143 address   os::Linux::_initial_thread_stack_bottom = NULL;
 144 uintptr_t os::Linux::_initial_thread_stack_size   = 0;
 145 
 146 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 147 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
 148 Mutex* os::Linux::_createThread_lock = NULL;
 149 pthread_t os::Linux::_main_thread;
 150 int os::Linux::_page_size = -1;
 151 bool os::Linux::_supports_fast_thread_cpu_time = false;
 152 uint32_t os::Linux::_os_version = 0;
 153 const char * os::Linux::_glibc_version = NULL;
 154 const char * os::Linux::_libpthread_version = NULL;


1341   // needs to remove object in file system
1342   AttachListener::abort();
1343 
1344   // flush buffered output, finish log files
1345   ostream_abort();
1346 
1347   // Check for abort hook
1348   abort_hook_t abort_hook = Arguments::abort_hook();
1349   if (abort_hook != NULL) {
1350     abort_hook();
1351   }
1352 
1353 }
1354 
1355 // Note: os::abort() might be called very early during initialization, or
1356 // called from signal handler. Before adding something to os::abort(), make
1357 // sure it is async-safe and can handle partially initialized VM.
1358 void os::abort(bool dump_core, void* siginfo, const void* context) {
1359   os::shutdown();
1360   if (dump_core) {
1361 #ifndef ZERO
1362     if (DumpPrivateMappingsInCore) {
1363       ClassLoader::close_jrt_image();
1364     }
1365 #endif
1366 #ifndef PRODUCT
1367     fdStream out(defaultStream::output_fd());
1368     out.print_raw("Current thread is ");
1369     char buf[16];
1370     jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
1371     out.print_raw_cr(buf);
1372     out.print_raw_cr("Dumping core ...");
1373 #endif
1374     ::abort(); // dump core
1375   }
1376 
1377   ::exit(1);
1378 }
1379 
1380 // Die immediately, no exit hook, no abort hook, no cleanup.
1381 void os::die() {
1382   ::abort();


3416               && x == (long)p) {
3417             if (strstr (chars, "hugepage")) {
3418               result = true;
3419               break;
3420             }
3421           }
3422         }
3423       }
3424       fclose(fp);
3425     }
3426     munmap(p, page_size);
3427   }
3428 
3429   if (warn && !result) {
3430     warning("HugeTLBFS is not supported by the operating system.");
3431   }
3432 
3433   return result;
3434 }
3435 


3436 // From the coredump_filter documentation:
3437 //
3438 // - (bit 0) anonymous private memory
3439 // - (bit 1) anonymous shared memory
3440 // - (bit 2) file-backed private memory
3441 // - (bit 3) file-backed shared memory
3442 // - (bit 4) ELF header pages in file-backed private memory areas (it is
3443 //           effective only if the bit 2 is cleared)
3444 // - (bit 5) hugetlb private memory
3445 // - (bit 6) hugetlb shared memory
3446 // - (bit 7) dax private memory
3447 // - (bit 8) dax shared memory
3448 //
3449 static void set_coredump_filter(CoredumpFilterBit bit) {
3450   FILE *f;
3451   long cdm;
3452 
3453   if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
3454     return;
3455   }


5113     // only register atexit functions if PerfAllowAtExitRegistration is set.
5114     // atexit functions can be delayed until process exit time, which
5115     // can be problematic for embedded VM situations. Embedded VMs should
5116     // call DestroyJavaVM() to assure that VM resources are released.
5117 
5118     // note: perfMemory_exit_helper atexit function may be removed in
5119     // the future if the appropriate cleanup code can be added to the
5120     // VM_Exit VMOperation's doit method.
5121     if (atexit(perfMemory_exit_helper) != 0) {
5122       warning("os::init_2 atexit(perfMemory_exit_helper) failed");
5123     }
5124   }
5125 
5126   // initialize thread priority policy
5127   prio_init();
5128 
5129   if (!FLAG_IS_DEFAULT(AllocateHeapAt) || !FLAG_IS_DEFAULT(AllocateOldGenAt)) {
5130     set_coredump_filter(DAX_SHARED_BIT);
5131   }
5132 
5133   if (DumpPrivateMappingsInCore) {

5134     set_coredump_filter(FILE_BACKED_PVT_BIT);
5135   }
5136 
5137   if (DumpSharedMappingsInCore) {
5138     set_coredump_filter(FILE_BACKED_SHARED_BIT);
5139   }
5140 
5141   return JNI_OK;
5142 }
5143 
5144 // Mark the polling page as unreadable
5145 void os::make_polling_page_unreadable(void) {
5146   if (!guard_memory((char*)_polling_page, Linux::page_size())) {
5147     fatal("Could not disable polling page");
5148   }
5149 }
5150 
5151 // Mark the polling page as readable
5152 void os::make_polling_page_readable(void) {
5153   if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
5154     fatal("Could not enable polling page");
5155   }
5156 }
5157 
5158 // older glibc versions don't have this macro (which expands to
5159 // an optimized bit-counting function) so we have to roll our own


< prev index next >