37 #include "logging/log.hpp"
38 #include "logging/logStream.hpp"
39 #include "memory/allocation.inline.hpp"
40 #ifdef ASSERT
41 #include "memory/guardedMemory.hpp"
42 #endif
43 #include "memory/resourceArea.hpp"
44 #include "oops/oop.inline.hpp"
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));
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/log.hpp"
38 #include "logging/logStream.hpp"
39 #include "memory/allocation.inline.hpp"
40 #ifdef ASSERT
41 #include "memory/guardedMemory.hpp"
42 #endif
43 #include "memory/resourceArea.hpp"
44 #include "oops/oop.inline.hpp"
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 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1097 // Check for privilege stack
1098 if (thread->privileged_stack_top() != NULL &&
1099 thread->privileged_stack_top()->contains(addr)) {
1100 st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
1101 "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
1102 if (verbose) thread->print_on(st);
1103 return;
1104 }
1105 // If the addr is a java thread print information about that.
1106 if (addr == (address)thread) {
1107 if (verbose) {
1108 thread->print_on(st);
1109 } else {
1110 st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
1111 }
1112 return;
1113 }
1114 // If the addr is in the stack region for this thread then report that
1115 // and print thread info
1116 if (thread->on_local_stack(addr)) {
1117 st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
1118 INTPTR_FORMAT, p2i(addr), p2i(thread));
1119 if (verbose) thread->print_on(st);
1120 return;
1121 }
1122 }
1123
1124 // Check if in metaspace and print types that have vptrs (only method now)
1125 if (Metaspace::contains(addr)) {
1126 if (Method::has_method_vptr((const void*)addr)) {
1127 ((Method*)addr)->print_value_on(st);
1128 st->cr();
1129 } else {
1130 // Use addr->print() from the debugger instead (not here)
1131 st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
1132 }
1133 return;
1134 }
1135
1136 // Try an OS specific find
1137 if (os::find(addr, st)) {
1138 return;
1139 }
1140
1141 st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
1640 if (logical_processors > 1) {
1641 const unsigned int physical_packages =
1642 os::active_processor_count() / logical_processors;
1643 if (physical_packages >= server_processors) {
1644 result = true;
1645 }
1646 } else {
1647 result = true;
1648 }
1649 }
1650 return result;
1651 }
1652
1653 void os::initialize_initial_active_processor_count() {
1654 assert(_initial_active_processor_count == 0, "Initial active processor count already set.");
1655 _initial_active_processor_count = active_processor_count();
1656 log_debug(os)("Initial active processor count set to %d" , _initial_active_processor_count);
1657 }
1658
1659 void os::SuspendedThreadTask::run() {
1660 internal_do_task();
1661 _done = true;
1662 }
1663
1664 bool os::create_stack_guard_pages(char* addr, size_t bytes) {
1665 return os::pd_create_stack_guard_pages(addr, bytes);
1666 }
1667
1668 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) {
1669 char* result = pd_reserve_memory(bytes, addr, alignment_hint);
1670 if (result != NULL) {
1671 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC);
1672 }
1673
1674 return result;
1675 }
1676
1677 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint,
1678 MEMFLAGS flags) {
1679 char* result = pd_reserve_memory(bytes, addr, alignment_hint);
|