< prev index next >

src/hotspot/share/runtime/os.cpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47289 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp


  37 #include "logging/logStream.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #ifdef ASSERT
  40 #include "memory/guardedMemory.hpp"
  41 #endif
  42 #include "memory/resourceArea.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "prims/jvm.h"
  45 #include "prims/jvm_misc.hpp"
  46 #include "prims/privilegedStack.hpp"
  47 #include "runtime/arguments.hpp"
  48 #include "runtime/atomic.hpp"
  49 #include "runtime/frame.inline.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/mutexLocker.hpp"
  54 #include "runtime/os.inline.hpp"
  55 #include "runtime/stubRoutines.hpp"
  56 #include "runtime/thread.inline.hpp"

  57 #include "runtime/vm_version.hpp"
  58 #include "services/attachListener.hpp"
  59 #include "services/mallocTracker.hpp"
  60 #include "services/memTracker.hpp"
  61 #include "services/nmtCommon.hpp"
  62 #include "services/threadService.hpp"
  63 #include "utilities/align.hpp"
  64 #include "utilities/defaultStream.hpp"
  65 #include "utilities/events.hpp"
  66 
  67 # include <signal.h>
  68 # include <errno.h>
  69 
  70 OSThread*         os::_starting_thread    = NULL;
  71 address           os::_polling_page       = NULL;
  72 volatile int32_t* os::_mem_serialize_page = NULL;
  73 uintptr_t         os::_serialize_page_mask = 0;
  74 volatile unsigned int os::_rand_seed      = 1;
  75 int               os::_processor_count    = 0;
  76 int               os::_initial_active_processor_count = 0;


 180   const int printed = jio_snprintf(buffer, buffer_length,
 181                                    "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d",
 182                                    year,
 183                                    month,
 184                                    time_struct.tm_mday,
 185                                    time_struct.tm_hour,
 186                                    time_struct.tm_min,
 187                                    time_struct.tm_sec,
 188                                    milliseconds_after_second,
 189                                    sign_local_to_UTC,
 190                                    zone_hours,
 191                                    zone_min);
 192   if (printed == 0) {
 193     assert(false, "Failed jio_printf");
 194     return NULL;
 195   }
 196   return buffer;
 197 }
 198 
 199 OSReturn os::set_priority(Thread* thread, ThreadPriority p) {
 200 #ifdef ASSERT
 201   if (!(!thread->is_Java_thread() ||
 202          Thread::current() == thread  ||
 203          Threads_lock->owned_by_self()
 204          || thread->is_Compiler_thread()
 205         )) {
 206     assert(false, "possibility of dangling Thread pointer");
 207   }
 208 #endif
 209 
 210   if (p >= MinPriority && p <= MaxPriority) {
 211     int priority = java_to_os_priority[p];
 212     return set_native_priority(thread, priority);
 213   } else {
 214     assert(false, "Should not happen");
 215     return OS_ERR;
 216   }
 217 }
 218 
 219 // The mapping from OS priority back to Java priority may be inexact because
 220 // Java priorities can map M:1 with native priorities. If you want the definite
 221 // Java priority then use JavaThread::java_priority()
 222 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) {
 223   int p;
 224   int os_prio;
 225   OSReturn ret = get_native_priority(thread, &os_prio);
 226   if (ret != OS_OK) return ret;
 227 
 228   if (java_to_os_priority[MaxPriority] > java_to_os_priority[MinPriority]) {


1083                    "in the heap", p2i(addr));
1084       return;
1085     }
1086   }
1087   if (JNIHandles::is_global_handle((jobject) addr)) {
1088     st->print_cr(INTPTR_FORMAT " is a global jni handle", p2i(addr));
1089     return;
1090   }
1091   if (JNIHandles::is_weak_global_handle((jobject) addr)) {
1092     st->print_cr(INTPTR_FORMAT " is a weak global jni handle", p2i(addr));
1093     return;
1094   }
1095 #ifndef PRODUCT
1096   // we don't keep the block list in product mode
1097   if (JNIHandleBlock::any_contains((jobject) addr)) {
1098     st->print_cr(INTPTR_FORMAT " is a local jni handle", p2i(addr));
1099     return;
1100   }
1101 #endif
1102 
1103   for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {



1104     // Check for privilege stack
1105     if (thread->privileged_stack_top() != NULL &&
1106         thread->privileged_stack_top()->contains(addr)) {
1107       st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
1108                    "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
1109       if (verbose) thread->print_on(st);
1110       return;
1111     }
1112     // If the addr is a java thread print information about that.
1113     if (addr == (address)thread) {
1114       if (verbose) {
1115         thread->print_on(st);
1116       } else {
1117         st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
1118       }
1119       return;
1120     }
1121     // If the addr is in the stack region for this thread then report that
1122     // and print thread info
1123     if (thread->on_local_stack(addr)) {
1124       st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
1125                    INTPTR_FORMAT, p2i(addr), p2i(thread));
1126       if (verbose) thread->print_on(st);
1127       return;
1128     }
1129 
1130   }

1131 
1132   // Check if in metaspace and print types that have vptrs (only method now)
1133   if (Metaspace::contains(addr)) {
1134     if (Method::has_method_vptr((const void*)addr)) {
1135       ((Method*)addr)->print_value_on(st);
1136       st->cr();
1137     } else {
1138       // Use addr->print() from the debugger instead (not here)
1139       st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
1140     }
1141     return;
1142   }
1143 
1144   // Try an OS specific find
1145   if (os::find(addr, st)) {
1146     return;
1147   }
1148 
1149   st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1150 }


1648     if (logical_processors > 1) {
1649       const unsigned int physical_packages =
1650         os::active_processor_count() / logical_processors;
1651       if (physical_packages >= server_processors) {
1652         result = true;
1653       }
1654     } else {
1655       result = true;
1656     }
1657   }
1658   return result;
1659 }
1660 
1661 void os::initialize_initial_active_processor_count() {
1662   assert(_initial_active_processor_count == 0, "Initial active processor count already set.");
1663   _initial_active_processor_count = active_processor_count();
1664   log_debug(os)("Initial active processor count set to %d" , _initial_active_processor_count);
1665 }
1666 
1667 void os::SuspendedThreadTask::run() {
1668   assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this");
1669   internal_do_task();
1670   _done = true;
1671 }
1672 
1673 bool os::create_stack_guard_pages(char* addr, size_t bytes) {
1674   return os::pd_create_stack_guard_pages(addr, bytes);
1675 }
1676 
1677 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) {
1678   char* result = pd_reserve_memory(bytes, addr, alignment_hint);
1679   if (result != NULL) {
1680     MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
1681   }
1682 
1683   return result;
1684 }
1685 
1686 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint,
1687    MEMFLAGS flags) {
1688   char* result = pd_reserve_memory(bytes, addr, alignment_hint);




  37 #include "logging/logStream.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #ifdef ASSERT
  40 #include "memory/guardedMemory.hpp"
  41 #endif
  42 #include "memory/resourceArea.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "prims/jvm.h"
  45 #include "prims/jvm_misc.hpp"
  46 #include "prims/privilegedStack.hpp"
  47 #include "runtime/arguments.hpp"
  48 #include "runtime/atomic.hpp"
  49 #include "runtime/frame.inline.hpp"
  50 #include "runtime/interfaceSupport.hpp"
  51 #include "runtime/java.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/mutexLocker.hpp"
  54 #include "runtime/os.inline.hpp"
  55 #include "runtime/stubRoutines.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/threadSMR.hpp"
  58 #include "runtime/vm_version.hpp"
  59 #include "services/attachListener.hpp"
  60 #include "services/mallocTracker.hpp"
  61 #include "services/memTracker.hpp"
  62 #include "services/nmtCommon.hpp"
  63 #include "services/threadService.hpp"
  64 #include "utilities/align.hpp"
  65 #include "utilities/defaultStream.hpp"
  66 #include "utilities/events.hpp"
  67 
  68 # include <signal.h>
  69 # include <errno.h>
  70 
  71 OSThread*         os::_starting_thread    = NULL;
  72 address           os::_polling_page       = NULL;
  73 volatile int32_t* os::_mem_serialize_page = NULL;
  74 uintptr_t         os::_serialize_page_mask = 0;
  75 volatile unsigned int os::_rand_seed      = 1;
  76 int               os::_processor_count    = 0;
  77 int               os::_initial_active_processor_count = 0;


 181   const int printed = jio_snprintf(buffer, buffer_length,
 182                                    "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d",
 183                                    year,
 184                                    month,
 185                                    time_struct.tm_mday,
 186                                    time_struct.tm_hour,
 187                                    time_struct.tm_min,
 188                                    time_struct.tm_sec,
 189                                    milliseconds_after_second,
 190                                    sign_local_to_UTC,
 191                                    zone_hours,
 192                                    zone_min);
 193   if (printed == 0) {
 194     assert(false, "Failed jio_printf");
 195     return NULL;
 196   }
 197   return buffer;
 198 }
 199 
 200 OSReturn os::set_priority(Thread* thread, ThreadPriority p) {
 201   debug_only(Thread::check_for_dangling_thread_pointer(thread);)








 202 
 203   if (p >= MinPriority && p <= MaxPriority) {
 204     int priority = java_to_os_priority[p];
 205     return set_native_priority(thread, priority);
 206   } else {
 207     assert(false, "Should not happen");
 208     return OS_ERR;
 209   }
 210 }
 211 
 212 // The mapping from OS priority back to Java priority may be inexact because
 213 // Java priorities can map M:1 with native priorities. If you want the definite
 214 // Java priority then use JavaThread::java_priority()
 215 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) {
 216   int p;
 217   int os_prio;
 218   OSReturn ret = get_native_priority(thread, &os_prio);
 219   if (ret != OS_OK) return ret;
 220 
 221   if (java_to_os_priority[MaxPriority] > java_to_os_priority[MinPriority]) {


1076                    "in the heap", p2i(addr));
1077       return;
1078     }
1079   }
1080   if (JNIHandles::is_global_handle((jobject) addr)) {
1081     st->print_cr(INTPTR_FORMAT " is a global jni handle", p2i(addr));
1082     return;
1083   }
1084   if (JNIHandles::is_weak_global_handle((jobject) addr)) {
1085     st->print_cr(INTPTR_FORMAT " is a weak global jni handle", p2i(addr));
1086     return;
1087   }
1088 #ifndef PRODUCT
1089   // we don't keep the block list in product mode
1090   if (JNIHandleBlock::any_contains((jobject) addr)) {
1091     st->print_cr(INTPTR_FORMAT " is a local jni handle", p2i(addr));
1092     return;
1093   }
1094 #endif
1095 
1096   {
1097     ThreadsListHandle tlh;
1098     JavaThreadIterator jti(tlh.list());
1099     for (JavaThread *thread = jti.first(); thread != NULL; thread = jti.next()) {
1100       // Check for privilege stack
1101       if (thread->privileged_stack_top() != NULL &&
1102           thread->privileged_stack_top()->contains(addr)) {
1103         st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
1104                      "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
1105         if (verbose) thread->print_on(st);
1106         return;
1107       }
1108       // If the addr is a java thread print information about that.
1109       if (addr == (address)thread) {
1110         if (verbose) {
1111           thread->print_on(st);
1112         } else {
1113           st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
1114         }
1115         return;
1116       }
1117       // If the addr is in the stack region for this thread then report that
1118       // and print thread info
1119       if (thread->on_local_stack(addr)) {
1120         st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
1121                      INTPTR_FORMAT, p2i(addr), p2i(thread));
1122         if (verbose) thread->print_on(st);
1123         return;
1124       }

1125     }
1126   } // ThreadsListHandle destroyed here.
1127 
1128   // Check if in metaspace and print types that have vptrs (only method now)
1129   if (Metaspace::contains(addr)) {
1130     if (Method::has_method_vptr((const void*)addr)) {
1131       ((Method*)addr)->print_value_on(st);
1132       st->cr();
1133     } else {
1134       // Use addr->print() from the debugger instead (not here)
1135       st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
1136     }
1137     return;
1138   }
1139 
1140   // Try an OS specific find
1141   if (os::find(addr, st)) {
1142     return;
1143   }
1144 
1145   st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1146 }


1644     if (logical_processors > 1) {
1645       const unsigned int physical_packages =
1646         os::active_processor_count() / logical_processors;
1647       if (physical_packages >= server_processors) {
1648         result = true;
1649       }
1650     } else {
1651       result = true;
1652     }
1653   }
1654   return result;
1655 }
1656 
1657 void os::initialize_initial_active_processor_count() {
1658   assert(_initial_active_processor_count == 0, "Initial active processor count already set.");
1659   _initial_active_processor_count = active_processor_count();
1660   log_debug(os)("Initial active processor count set to %d" , _initial_active_processor_count);
1661 }
1662 
1663 void os::SuspendedThreadTask::run() {

1664   internal_do_task();
1665   _done = true;
1666 }
1667 
1668 bool os::create_stack_guard_pages(char* addr, size_t bytes) {
1669   return os::pd_create_stack_guard_pages(addr, bytes);
1670 }
1671 
1672 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) {
1673   char* result = pd_reserve_memory(bytes, addr, alignment_hint);
1674   if (result != NULL) {
1675     MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
1676   }
1677 
1678   return result;
1679 }
1680 
1681 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint,
1682    MEMFLAGS flags) {
1683   char* result = pd_reserve_memory(bytes, addr, alignment_hint);


< prev index next >