54 #include "runtime/stubRoutines.hpp"
55 #include "runtime/thread.inline.hpp"
56 #include "runtime/vm_version.hpp"
57 #include "services/attachListener.hpp"
58 #include "services/mallocTracker.hpp"
59 #include "services/memTracker.hpp"
60 #include "services/nmtCommon.hpp"
61 #include "services/threadService.hpp"
62 #include "utilities/defaultStream.hpp"
63 #include "utilities/events.hpp"
64
65 # include <signal.h>
66 # include <errno.h>
67
68 OSThread* os::_starting_thread = NULL;
69 address os::_polling_page = NULL;
70 volatile int32_t* os::_mem_serialize_page = NULL;
71 uintptr_t os::_serialize_page_mask = 0;
72 long os::_rand_seed = 1;
73 int os::_processor_count = 0;
74 size_t os::_page_sizes[os::page_sizes_max];
75
76 #ifndef PRODUCT
77 julong os::num_mallocs = 0; // # of calls to malloc/realloc
78 julong os::alloc_bytes = 0; // # of bytes allocated
79 julong os::num_frees = 0; // # of calls to free
80 julong os::free_bytes = 0; // # of bytes freed
81 #endif
82
83 static juint cur_malloc_words = 0; // current size for MallocMaxTestWords
84
85 void os_init_globals() {
86 // Called from init_globals().
87 // See Threads::create_vm() in thread.cpp, and init.cpp.
88 os::init_globals();
89 }
90
91 // Fill in buffer with current local time as an ISO-8601 string.
92 // E.g., yyyy-mm-ddThh:mm:ss-zzzz.
93 // Returns buffer, or NULL if it failed.
1741 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
1742 pd_realign_memory(addr, bytes, alignment_hint);
1743 }
1744
1745 #ifndef TARGET_OS_FAMILY_windows
1746 /* try to switch state from state "from" to state "to"
1747 * returns the state set after the method is complete
1748 */
1749 os::SuspendResume::State os::SuspendResume::switch_state(os::SuspendResume::State from,
1750 os::SuspendResume::State to)
1751 {
1752 os::SuspendResume::State result =
1753 (os::SuspendResume::State) Atomic::cmpxchg((jint) to, (jint *) &_state, (jint) from);
1754 if (result == from) {
1755 // success
1756 return to;
1757 }
1758 return result;
1759 }
1760 #endif
1761
1762 /////////////// Unit tests ///////////////
1763
1764 #ifndef PRODUCT
1765
1766 #define assert_eq(a,b) assert(a == b, SIZE_FORMAT " != " SIZE_FORMAT, a, b)
1767
1768 class TestOS : AllStatic {
1769 static size_t small_page_size() {
1770 return os::vm_page_size();
1771 }
1772
1773 static size_t large_page_size() {
1774 const size_t large_page_size_example = 4 * M;
1775 return os::page_size_for_region_aligned(large_page_size_example, 1);
1776 }
1777
1778 static void test_page_size_for_region_aligned() {
1779 if (UseLargePages) {
1780 const size_t small_page = small_page_size();
|
54 #include "runtime/stubRoutines.hpp"
55 #include "runtime/thread.inline.hpp"
56 #include "runtime/vm_version.hpp"
57 #include "services/attachListener.hpp"
58 #include "services/mallocTracker.hpp"
59 #include "services/memTracker.hpp"
60 #include "services/nmtCommon.hpp"
61 #include "services/threadService.hpp"
62 #include "utilities/defaultStream.hpp"
63 #include "utilities/events.hpp"
64
65 # include <signal.h>
66 # include <errno.h>
67
68 OSThread* os::_starting_thread = NULL;
69 address os::_polling_page = NULL;
70 volatile int32_t* os::_mem_serialize_page = NULL;
71 uintptr_t os::_serialize_page_mask = 0;
72 long os::_rand_seed = 1;
73 int os::_processor_count = 0;
74 int os::_initial_active_processor_count = 0;
75 size_t os::_page_sizes[os::page_sizes_max];
76
77 #ifndef PRODUCT
78 julong os::num_mallocs = 0; // # of calls to malloc/realloc
79 julong os::alloc_bytes = 0; // # of bytes allocated
80 julong os::num_frees = 0; // # of calls to free
81 julong os::free_bytes = 0; // # of bytes freed
82 #endif
83
84 static juint cur_malloc_words = 0; // current size for MallocMaxTestWords
85
86 void os_init_globals() {
87 // Called from init_globals().
88 // See Threads::create_vm() in thread.cpp, and init.cpp.
89 os::init_globals();
90 }
91
92 // Fill in buffer with current local time as an ISO-8601 string.
93 // E.g., yyyy-mm-ddThh:mm:ss-zzzz.
94 // Returns buffer, or NULL if it failed.
1742 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
1743 pd_realign_memory(addr, bytes, alignment_hint);
1744 }
1745
1746 #ifndef TARGET_OS_FAMILY_windows
1747 /* try to switch state from state "from" to state "to"
1748 * returns the state set after the method is complete
1749 */
1750 os::SuspendResume::State os::SuspendResume::switch_state(os::SuspendResume::State from,
1751 os::SuspendResume::State to)
1752 {
1753 os::SuspendResume::State result =
1754 (os::SuspendResume::State) Atomic::cmpxchg((jint) to, (jint *) &_state, (jint) from);
1755 if (result == from) {
1756 // success
1757 return to;
1758 }
1759 return result;
1760 }
1761 #endif
1762
1763 void os::set_processor_count(int count) {
1764 assert(_processor_count == 0, "Trying to set processor count twice, from %d to %d", _processor_count, count);
1765 _processor_count = count;
1766 _initial_active_processor_count = active_processor_count();
1767 log_trace(os)("Initial active processor count is %d", _initial_active_processor_count);
1768 }
1769
1770 /////////////// Unit tests ///////////////
1771
1772 #ifndef PRODUCT
1773
1774 #define assert_eq(a,b) assert(a == b, SIZE_FORMAT " != " SIZE_FORMAT, a, b)
1775
1776 class TestOS : AllStatic {
1777 static size_t small_page_size() {
1778 return os::vm_page_size();
1779 }
1780
1781 static size_t large_page_size() {
1782 const size_t large_page_size_example = 4 * M;
1783 return os::page_size_for_region_aligned(large_page_size_example, 1);
1784 }
1785
1786 static void test_page_size_for_region_aligned() {
1787 if (UseLargePages) {
1788 const size_t small_page = small_page_size();
|