Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/windows/os_windows.hpp
40930 views
1
/*
2
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef OS_WINDOWS_OS_WINDOWS_HPP
26
#define OS_WINDOWS_OS_WINDOWS_HPP
27
// Win32_OS defines the interface to windows operating systems
28
29
// strtok_s is the Windows thread-safe equivalent of POSIX strtok_r
30
#define strtok_r strtok_s
31
32
#define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR)
33
#define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO)
34
35
// Information about the protection of the page at address '0' on this os.
36
static bool zero_page_read_protected() { return true; }
37
38
// File conventions
39
static const char* file_separator() { return "\\"; }
40
static const char* line_separator() { return "\r\n"; }
41
static const char* path_separator() { return ";"; }
42
43
class win32 {
44
friend class os;
45
friend unsigned __stdcall thread_native_entry(class Thread*);
46
47
protected:
48
static int _vm_page_size;
49
static int _vm_allocation_granularity;
50
static int _processor_type;
51
static int _processor_level;
52
static julong _physical_memory;
53
static size_t _default_stack_size;
54
static bool _is_windows_server;
55
static bool _has_exit_bug;
56
57
static void print_windows_version(outputStream* st);
58
static void print_uptime_info(outputStream* st);
59
60
public:
61
// Windows-specific interface:
62
static void initialize_system_info();
63
static void setmode_streams();
64
65
// Processor info as provided by NT
66
static int processor_type() { return _processor_type; }
67
static int processor_level() {
68
return _processor_level;
69
}
70
static julong available_memory();
71
static julong physical_memory() { return _physical_memory; }
72
73
// load dll from Windows system directory or Windows directory
74
static HINSTANCE load_Windows_dll(const char* name, char *ebuf, int ebuflen);
75
76
private:
77
enum Ept { EPT_THREAD, EPT_PROCESS, EPT_PROCESS_DIE };
78
// Wrapper around _endthreadex(), exit() and _exit()
79
static int exit_process_or_thread(Ept what, int exit_code);
80
81
static void initialize_performance_counter();
82
83
public:
84
// Generic interface:
85
86
// Trace number of created threads
87
static intx _os_thread_limit;
88
static volatile intx _os_thread_count;
89
90
// Tells whether this is a server version of Windows
91
static bool is_windows_server() { return _is_windows_server; }
92
93
// Tells whether there can be the race bug during process exit on this platform
94
static bool has_exit_bug() { return _has_exit_bug; }
95
96
// Returns the byte size of a virtual memory page
97
static int vm_page_size() { return _vm_page_size; }
98
99
// Returns the size in bytes of memory blocks which can be allocated.
100
static int vm_allocation_granularity() { return _vm_allocation_granularity; }
101
102
// Read the headers for the executable that started the current process into
103
// the structure passed in (see winnt.h).
104
static void read_executable_headers(PIMAGE_NT_HEADERS);
105
106
// Default stack size for the current process.
107
static size_t default_stack_size() { return _default_stack_size; }
108
109
static bool get_frame_at_stack_banging_point(JavaThread* thread,
110
struct _EXCEPTION_POINTERS* exceptionInfo,
111
address pc, frame* fr);
112
113
struct mapping_info_t {
114
// Start of allocation (AllocationBase)
115
address base;
116
// Total size of allocation over all regions
117
size_t size;
118
// Total committed size
119
size_t committed_size;
120
// Number of regions
121
int regions;
122
};
123
// Given an address p which points into an area allocated with VirtualAlloc(),
124
// return information about that area.
125
static bool find_mapping(address p, mapping_info_t* mapping_info);
126
127
#ifndef _WIN64
128
// A wrapper to install a structured exception handler for fast JNI accesors.
129
static address fast_jni_accessor_wrapper(BasicType);
130
#endif
131
132
// Fast access to current thread
133
protected:
134
static int _thread_ptr_offset;
135
private:
136
static void initialize_thread_ptr_offset();
137
public:
138
static inline void set_thread_ptr_offset(int offset) {
139
_thread_ptr_offset = offset;
140
}
141
static inline int get_thread_ptr_offset() { return _thread_ptr_offset; }
142
};
143
144
/*
145
* Crash protection for the JfrSampler thread. Wrap the callback
146
* with a __try { call() }
147
* To be able to use this - don't take locks, don't rely on destructors,
148
* don't make OS library calls, don't allocate memory, don't print,
149
* don't call code that could leave the heap / memory in an inconsistent state,
150
* or anything else where we are not in control if we suddenly jump out.
151
*/
152
class ThreadCrashProtection : public StackObj {
153
public:
154
static bool is_crash_protected(Thread* thr) {
155
return _crash_protection != NULL && _protected_thread == thr;
156
}
157
158
ThreadCrashProtection();
159
bool call(os::CrashProtectionCallback& cb);
160
private:
161
static Thread* _protected_thread;
162
static ThreadCrashProtection* _crash_protection;
163
};
164
165
class PlatformEvent : public CHeapObj<mtSynchronizer> {
166
private:
167
double CachePad [4] ; // increase odds that _Event is sole occupant of cache line
168
volatile int _Event ;
169
HANDLE _ParkHandle ;
170
171
public: // TODO-FIXME: make dtor private
172
~PlatformEvent() { guarantee (0, "invariant") ; }
173
174
public:
175
PlatformEvent() {
176
_Event = 0 ;
177
_ParkHandle = CreateEvent (NULL, false, false, NULL) ;
178
guarantee (_ParkHandle != NULL, "invariant") ;
179
}
180
181
// Exercise caution using reset() and fired() - they may require MEMBARs
182
void reset() { _Event = 0 ; }
183
int fired() { return _Event; }
184
void park () ;
185
void unpark () ;
186
int park (jlong millis) ;
187
} ;
188
189
190
191
class PlatformParker {
192
NONCOPYABLE(PlatformParker);
193
194
protected:
195
HANDLE _ParkHandle;
196
197
public:
198
PlatformParker() {
199
_ParkHandle = CreateEvent (NULL, true, false, NULL) ;
200
guarantee(_ParkHandle != NULL, "invariant") ;
201
}
202
~PlatformParker() {
203
CloseHandle(_ParkHandle);
204
}
205
};
206
207
// Platform specific implementations that underpin VM Mutex/Monitor classes.
208
// Note that CRITICAL_SECTION supports recursive locking, while the semantics
209
// of the VM Mutex class does not. It is up to the Mutex class to hide this
210
// difference in behaviour.
211
212
class PlatformMutex : public CHeapObj<mtSynchronizer> {
213
NONCOPYABLE(PlatformMutex);
214
215
protected:
216
CRITICAL_SECTION _mutex; // Native mutex for locking
217
218
public:
219
PlatformMutex();
220
~PlatformMutex();
221
void lock();
222
void unlock();
223
bool try_lock();
224
};
225
226
class PlatformMonitor : public PlatformMutex {
227
private:
228
CONDITION_VARIABLE _cond; // Native condition variable for blocking
229
NONCOPYABLE(PlatformMonitor);
230
231
public:
232
PlatformMonitor();
233
~PlatformMonitor();
234
int wait(jlong millis);
235
void notify();
236
void notify_all();
237
};
238
239
#endif // OS_WINDOWS_OS_WINDOWS_HPP
240
241