Mercurial > hg > truffle
annotate src/share/vm/runtime/os.cpp @ 20388:7430aa5718a5
Merge
author | amurillo |
---|---|
date | Wed, 03 Sep 2014 08:52:08 -0700 |
parents | 833b0f92429a |
children | ed3d653e4012 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
27 #include "classfile/javaClasses.hpp" | |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "classfile/vmSymbols.hpp" | |
30 #include "code/icBuffer.hpp" | |
31 #include "code/vtableStubs.hpp" | |
32 #include "gc_implementation/shared/vmGCOperations.hpp" | |
33 #include "interpreter/interpreter.hpp" | |
34 #include "memory/allocation.inline.hpp" | |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
35 #ifdef ASSERT |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
36 #include "memory/guardedMemory.hpp" |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
37 #endif |
1972 | 38 #include "oops/oop.inline.hpp" |
39 #include "prims/jvm.h" | |
40 #include "prims/jvm_misc.hpp" | |
41 #include "prims/privilegedStack.hpp" | |
42 #include "runtime/arguments.hpp" | |
43 #include "runtime/frame.inline.hpp" | |
44 #include "runtime/interfaceSupport.hpp" | |
45 #include "runtime/java.hpp" | |
46 #include "runtime/javaCalls.hpp" | |
47 #include "runtime/mutexLocker.hpp" | |
48 #include "runtime/os.hpp" | |
49 #include "runtime/stubRoutines.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
6985
diff
changeset
|
50 #include "runtime/thread.inline.hpp" |
1972 | 51 #include "services/attachListener.hpp" |
20360 | 52 #include "services/nmtCommon.hpp" |
6197 | 53 #include "services/memTracker.hpp" |
1972 | 54 #include "services/threadService.hpp" |
55 #include "utilities/defaultStream.hpp" | |
56 #include "utilities/events.hpp" | |
57 #ifdef TARGET_OS_FAMILY_linux | |
58 # include "os_linux.inline.hpp" | |
59 #endif | |
60 #ifdef TARGET_OS_FAMILY_solaris | |
61 # include "os_solaris.inline.hpp" | |
62 #endif | |
63 #ifdef TARGET_OS_FAMILY_windows | |
64 # include "os_windows.inline.hpp" | |
65 #endif | |
3960 | 66 #ifdef TARGET_OS_FAMILY_bsd |
67 # include "os_bsd.inline.hpp" | |
68 #endif | |
0 | 69 |
70 # include <signal.h> | |
71 | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
72 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
73 |
0 | 74 OSThread* os::_starting_thread = NULL; |
75 address os::_polling_page = NULL; | |
76 volatile int32_t* os::_mem_serialize_page = NULL; | |
77 uintptr_t os::_serialize_page_mask = 0; | |
78 long os::_rand_seed = 1; | |
79 int os::_processor_count = 0; | |
80 size_t os::_page_sizes[os::page_sizes_max]; | |
81 | |
82 #ifndef PRODUCT | |
2250 | 83 julong os::num_mallocs = 0; // # of calls to malloc/realloc |
84 julong os::alloc_bytes = 0; // # of bytes allocated | |
85 julong os::num_frees = 0; // # of calls to free | |
86 julong os::free_bytes = 0; // # of bytes freed | |
0 | 87 #endif |
88 | |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
89 static juint cur_malloc_words = 0; // current size for MallocMaxTestWords |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
90 |
4749
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
91 void os_init_globals() { |
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
92 // Called from init_globals(). |
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
93 // See Threads::create_vm() in thread.cpp, and init.cpp. |
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
94 os::init_globals(); |
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
95 } |
7ab5f6318694
7125934: Add a fast unordered timestamp capability to Hotspot on x86/x64
phh
parents:
4006
diff
changeset
|
96 |
0 | 97 // Fill in buffer with current local time as an ISO-8601 string. |
98 // E.g., yyyy-mm-ddThh:mm:ss-zzzz. | |
99 // Returns buffer, or NULL if it failed. | |
100 // This would mostly be a call to | |
101 // strftime(...., "%Y-%m-%d" "T" "%H:%M:%S" "%z", ....) | |
102 // except that on Windows the %z behaves badly, so we do it ourselves. | |
103 // Also, people wanted milliseconds on there, | |
104 // and strftime doesn't do milliseconds. | |
105 char* os::iso8601_time(char* buffer, size_t buffer_length) { | |
106 // Output will be of the form "YYYY-MM-DDThh:mm:ss.mmm+zzzz\0" | |
107 // 1 2 | |
108 // 12345678901234567890123456789 | |
109 static const char* iso8601_format = | |
110 "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d"; | |
111 static const size_t needed_buffer = 29; | |
112 | |
113 // Sanity check the arguments | |
114 if (buffer == NULL) { | |
115 assert(false, "NULL buffer"); | |
116 return NULL; | |
117 } | |
118 if (buffer_length < needed_buffer) { | |
119 assert(false, "buffer_length too small"); | |
120 return NULL; | |
121 } | |
122 // Get the current time | |
61 | 123 jlong milliseconds_since_19700101 = javaTimeMillis(); |
0 | 124 const int milliseconds_per_microsecond = 1000; |
125 const time_t seconds_since_19700101 = | |
126 milliseconds_since_19700101 / milliseconds_per_microsecond; | |
127 const int milliseconds_after_second = | |
128 milliseconds_since_19700101 % milliseconds_per_microsecond; | |
129 // Convert the time value to a tm and timezone variable | |
548
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
130 struct tm time_struct; |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
131 if (localtime_pd(&seconds_since_19700101, &time_struct) == NULL) { |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
132 assert(false, "Failed localtime_pd"); |
0 | 133 return NULL; |
134 } | |
3960 | 135 #if defined(_ALLBSD_SOURCE) |
136 const time_t zone = (time_t) time_struct.tm_gmtoff; | |
137 #else | |
0 | 138 const time_t zone = timezone; |
3960 | 139 #endif |
0 | 140 |
141 // If daylight savings time is in effect, | |
142 // we are 1 hour East of our time zone | |
143 const time_t seconds_per_minute = 60; | |
144 const time_t minutes_per_hour = 60; | |
145 const time_t seconds_per_hour = seconds_per_minute * minutes_per_hour; | |
146 time_t UTC_to_local = zone; | |
147 if (time_struct.tm_isdst > 0) { | |
148 UTC_to_local = UTC_to_local - seconds_per_hour; | |
149 } | |
150 // Compute the time zone offset. | |
548
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
151 // localtime_pd() sets timezone to the difference (in seconds) |
0 | 152 // between UTC and and local time. |
153 // ISO 8601 says we need the difference between local time and UTC, | |
548
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
154 // we change the sign of the localtime_pd() result. |
0 | 155 const time_t local_to_UTC = -(UTC_to_local); |
156 // Then we have to figure out if if we are ahead (+) or behind (-) UTC. | |
157 char sign_local_to_UTC = '+'; | |
158 time_t abs_local_to_UTC = local_to_UTC; | |
159 if (local_to_UTC < 0) { | |
160 sign_local_to_UTC = '-'; | |
161 abs_local_to_UTC = -(abs_local_to_UTC); | |
162 } | |
163 // Convert time zone offset seconds to hours and minutes. | |
164 const time_t zone_hours = (abs_local_to_UTC / seconds_per_hour); | |
165 const time_t zone_min = | |
166 ((abs_local_to_UTC % seconds_per_hour) / seconds_per_minute); | |
167 | |
168 // Print an ISO 8601 date and time stamp into the buffer | |
169 const int year = 1900 + time_struct.tm_year; | |
170 const int month = 1 + time_struct.tm_mon; | |
171 const int printed = jio_snprintf(buffer, buffer_length, iso8601_format, | |
172 year, | |
173 month, | |
174 time_struct.tm_mday, | |
175 time_struct.tm_hour, | |
176 time_struct.tm_min, | |
177 time_struct.tm_sec, | |
178 milliseconds_after_second, | |
179 sign_local_to_UTC, | |
180 zone_hours, | |
181 zone_min); | |
182 if (printed == 0) { | |
183 assert(false, "Failed jio_printf"); | |
184 return NULL; | |
185 } | |
186 return buffer; | |
187 } | |
188 | |
189 OSReturn os::set_priority(Thread* thread, ThreadPriority p) { | |
190 #ifdef ASSERT | |
191 if (!(!thread->is_Java_thread() || | |
192 Thread::current() == thread || | |
193 Threads_lock->owned_by_self() | |
194 || thread->is_Compiler_thread() | |
195 )) { | |
196 assert(false, "possibility of dangling Thread pointer"); | |
197 } | |
198 #endif | |
199 | |
200 if (p >= MinPriority && p <= MaxPriority) { | |
201 int priority = java_to_os_priority[p]; | |
202 return set_native_priority(thread, priority); | |
203 } else { | |
204 assert(false, "Should not happen"); | |
205 return OS_ERR; | |
206 } | |
207 } | |
208 | |
6766 | 209 // The mapping from OS priority back to Java priority may be inexact because |
210 // Java priorities can map M:1 with native priorities. If you want the definite | |
211 // Java priority then use JavaThread::java_priority() | |
0 | 212 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) { |
213 int p; | |
214 int os_prio; | |
215 OSReturn ret = get_native_priority(thread, &os_prio); | |
216 if (ret != OS_OK) return ret; | |
217 | |
6766 | 218 if (java_to_os_priority[MaxPriority] > java_to_os_priority[MinPriority]) { |
219 for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] > os_prio; p--) ; | |
220 } else { | |
221 // niceness values are in reverse order | |
222 for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] < os_prio; p--) ; | |
223 } | |
0 | 224 priority = (ThreadPriority)p; |
225 return OS_OK; | |
226 } | |
227 | |
228 | |
229 // --------------------- sun.misc.Signal (optional) --------------------- | |
230 | |
231 | |
232 // SIGBREAK is sent by the keyboard to query the VM state | |
233 #ifndef SIGBREAK | |
234 #define SIGBREAK SIGQUIT | |
235 #endif | |
236 | |
237 // sigexitnum_pd is a platform-specific special signal used for terminating the Signal thread. | |
238 | |
239 | |
240 static void signal_thread_entry(JavaThread* thread, TRAPS) { | |
241 os::set_priority(thread, NearMaxPriority); | |
242 while (true) { | |
243 int sig; | |
244 { | |
245 // FIXME : Currently we have not decieded what should be the status | |
246 // for this java thread blocked here. Once we decide about | |
247 // that we should fix this. | |
248 sig = os::signal_wait(); | |
249 } | |
250 if (sig == os::sigexitnum_pd()) { | |
251 // Terminate the signal thread | |
252 return; | |
253 } | |
254 | |
255 switch (sig) { | |
256 case SIGBREAK: { | |
257 // Check if the signal is a trigger to start the Attach Listener - in that | |
258 // case don't print stack traces. | |
259 if (!DisableAttachMechanism && AttachListener::is_init_trigger()) { | |
260 continue; | |
261 } | |
262 // Print stack traces | |
263 // Any SIGBREAK operations added here should make sure to flush | |
264 // the output stream (e.g. tty->flush()) after output. See 4803766. | |
265 // Each module also prints an extra carriage return after its output. | |
266 VM_PrintThreads op; | |
267 VMThread::execute(&op); | |
268 VM_PrintJNI jni_op; | |
269 VMThread::execute(&jni_op); | |
270 VM_FindDeadlocks op1(tty); | |
271 VMThread::execute(&op1); | |
272 Universe::print_heap_at_SIGBREAK(); | |
273 if (PrintClassHistogram) { | |
10405 | 274 VM_GC_HeapInspection op1(gclog_or_tty, true /* force full GC before heap inspection */); |
0 | 275 VMThread::execute(&op1); |
276 } | |
277 if (JvmtiExport::should_post_data_dump()) { | |
278 JvmtiExport::post_data_dump(); | |
279 } | |
280 break; | |
281 } | |
282 default: { | |
283 // Dispatch the signal to java | |
284 HandleMark hm(THREAD); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
285 Klass* k = SystemDictionary::resolve_or_null(vmSymbols::sun_misc_Signal(), THREAD); |
0 | 286 KlassHandle klass (THREAD, k); |
287 if (klass.not_null()) { | |
288 JavaValue result(T_VOID); | |
289 JavaCallArguments args; | |
290 args.push_int(sig); | |
291 JavaCalls::call_static( | |
292 &result, | |
293 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
294 vmSymbols::dispatch_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
295 vmSymbols::int_void_signature(), |
0 | 296 &args, |
297 THREAD | |
298 ); | |
299 } | |
300 if (HAS_PENDING_EXCEPTION) { | |
301 // tty is initialized early so we don't expect it to be null, but | |
302 // if it is we can't risk doing an initialization that might | |
303 // trigger additional out-of-memory conditions | |
304 if (tty != NULL) { | |
305 char klass_name[256]; | |
306 char tmp_sig_name[16]; | |
307 const char* sig_name = "UNKNOWN"; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
308 InstanceKlass::cast(PENDING_EXCEPTION->klass())-> |
0 | 309 name()->as_klass_external_name(klass_name, 256); |
310 if (os::exception_name(sig, tmp_sig_name, 16) != NULL) | |
311 sig_name = tmp_sig_name; | |
312 warning("Exception %s occurred dispatching signal %s to handler" | |
313 "- the VM may need to be forcibly terminated", | |
314 klass_name, sig_name ); | |
315 } | |
316 CLEAR_PENDING_EXCEPTION; | |
317 } | |
318 } | |
319 } | |
320 } | |
321 } | |
322 | |
12233
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12147
diff
changeset
|
323 void os::init_before_ergo() { |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12147
diff
changeset
|
324 // We need to initialize large page support here because ergonomics takes some |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12147
diff
changeset
|
325 // decisions depending on large page support and the calculated large page size. |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12147
diff
changeset
|
326 large_page_init(); |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12147
diff
changeset
|
327 } |
0 | 328 |
329 void os::signal_init() { | |
330 if (!ReduceSignalUsage) { | |
331 // Setup JavaThread for processing signals | |
332 EXCEPTION_MARK; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
333 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
0 | 334 instanceKlassHandle klass (THREAD, k); |
335 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); | |
336 | |
337 const char thread_name[] = "Signal Dispatcher"; | |
338 Handle string = java_lang_String::create_from_str(thread_name, CHECK); | |
339 | |
340 // Initialize thread_oop to put it into the system threadGroup | |
341 Handle thread_group (THREAD, Universe::system_thread_group()); | |
342 JavaValue result(T_VOID); | |
343 JavaCalls::call_special(&result, thread_oop, | |
344 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
345 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
346 vmSymbols::threadgroup_string_void_signature(), |
0 | 347 thread_group, |
348 string, | |
349 CHECK); | |
350 | |
1142 | 351 KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass()); |
0 | 352 JavaCalls::call_special(&result, |
353 thread_group, | |
354 group, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
355 vmSymbols::add_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1980
diff
changeset
|
356 vmSymbols::thread_void_signature(), |
0 | 357 thread_oop, // ARG 1 |
358 CHECK); | |
359 | |
360 os::signal_init_pd(); | |
361 | |
362 { MutexLocker mu(Threads_lock); | |
363 JavaThread* signal_thread = new JavaThread(&signal_thread_entry); | |
364 | |
365 // At this point it may be possible that no osthread was created for the | |
366 // JavaThread due to lack of memory. We would have to throw an exception | |
367 // in that case. However, since this must work and we do not allow | |
368 // exceptions anyway, check and abort if this fails. | |
369 if (signal_thread == NULL || signal_thread->osthread() == NULL) { | |
370 vm_exit_during_initialization("java.lang.OutOfMemoryError", | |
371 "unable to create new native thread"); | |
372 } | |
373 | |
374 java_lang_Thread::set_thread(thread_oop(), signal_thread); | |
375 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); | |
376 java_lang_Thread::set_daemon(thread_oop()); | |
377 | |
378 signal_thread->set_threadObj(thread_oop()); | |
379 Threads::add(signal_thread); | |
380 Thread::start(signal_thread); | |
381 } | |
382 // Handle ^BREAK | |
383 os::signal(SIGBREAK, os::user_handler()); | |
384 } | |
385 } | |
386 | |
387 | |
388 void os::terminate_signal_thread() { | |
389 if (!ReduceSignalUsage) | |
390 signal_notify(sigexitnum_pd()); | |
391 } | |
392 | |
393 | |
394 // --------------------- loading libraries --------------------- | |
395 | |
396 typedef jint (JNICALL *JNI_OnLoad_t)(JavaVM *, void *); | |
397 extern struct JavaVM_ main_vm; | |
398 | |
399 static void* _native_java_library = NULL; | |
400 | |
401 void* os::native_java_library() { | |
402 if (_native_java_library == NULL) { | |
403 char buffer[JVM_MAXPATHLEN]; | |
404 char ebuf[1024]; | |
405 | |
242 | 406 // Try to load verify dll first. In 1.3 java dll depends on it and is not |
407 // always able to find it when the loading executable is outside the JDK. | |
0 | 408 // In order to keep working with 1.2 we ignore any loading errors. |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
409 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
410 "verify")) { |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
411 dll_load(buffer, ebuf, sizeof(ebuf)); |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
412 } |
0 | 413 |
414 // Load java dll | |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
415 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
416 "java")) { |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
417 _native_java_library = dll_load(buffer, ebuf, sizeof(ebuf)); |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
418 } |
0 | 419 if (_native_java_library == NULL) { |
420 vm_exit_during_initialization("Unable to load native library", ebuf); | |
421 } | |
3960 | 422 |
423 #if defined(__OpenBSD__) | |
424 // Work-around OpenBSD's lack of $ORIGIN support by pre-loading libnet.so | |
425 // ignore errors | |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
426 if (dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
427 "net")) { |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
428 dll_load(buffer, ebuf, sizeof(ebuf)); |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
429 } |
3960 | 430 #endif |
242 | 431 } |
432 static jboolean onLoaded = JNI_FALSE; | |
433 if (onLoaded) { | |
434 // We may have to wait to fire OnLoad until TLS is initialized. | |
435 if (ThreadLocalStorage::is_initialized()) { | |
436 // The JNI_OnLoad handling is normally done by method load in | |
437 // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library | |
438 // explicitly so we have to check for JNI_OnLoad as well | |
439 const char *onLoadSymbols[] = JNI_ONLOAD_SYMBOLS; | |
440 JNI_OnLoad_t JNI_OnLoad = CAST_TO_FN_PTR( | |
441 JNI_OnLoad_t, dll_lookup(_native_java_library, onLoadSymbols[0])); | |
442 if (JNI_OnLoad != NULL) { | |
443 JavaThread* thread = JavaThread::current(); | |
444 ThreadToNativeFromVM ttn(thread); | |
445 HandleMark hm(thread); | |
446 jint ver = (*JNI_OnLoad)(&main_vm, NULL); | |
447 onLoaded = JNI_TRUE; | |
448 if (!Threads::is_supported_jni_version_including_1_1(ver)) { | |
449 vm_exit_during_initialization("Unsupported JNI version"); | |
450 } | |
0 | 451 } |
452 } | |
453 } | |
454 return _native_java_library; | |
455 } | |
456 | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
457 /* |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
458 * Support for finding Agent_On(Un)Load/Attach<_lib_name> if it exists. |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
459 * If check_lib == true then we are looking for an |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
460 * Agent_OnLoad_lib_name or Agent_OnAttach_lib_name function to determine if |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
461 * this library is statically linked into the image. |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
462 * If check_lib == false then we will look for the appropriate symbol in the |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
463 * executable if agent_lib->is_static_lib() == true or in the shared library |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
464 * referenced by 'handle'. |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
465 */ |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
466 void* os::find_agent_function(AgentLibrary *agent_lib, bool check_lib, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
467 const char *syms[], size_t syms_len) { |
12220 | 468 assert(agent_lib != NULL, "sanity check"); |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
469 const char *lib_name; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
470 void *handle = agent_lib->os_lib(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
471 void *entryName = NULL; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
472 char *agent_function_name; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
473 size_t i; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
474 |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
475 // If checking then use the agent name otherwise test is_static_lib() to |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
476 // see how to process this lookup |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
477 lib_name = ((check_lib || agent_lib->is_static_lib()) ? agent_lib->name() : NULL); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
478 for (i = 0; i < syms_len; i++) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
479 agent_function_name = build_agent_function_name(syms[i], lib_name, agent_lib->is_absolute_path()); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
480 if (agent_function_name == NULL) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
481 break; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
482 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
483 entryName = dll_lookup(handle, agent_function_name); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
484 FREE_C_HEAP_ARRAY(char, agent_function_name, mtThread); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
485 if (entryName != NULL) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
486 break; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
487 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
488 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
489 return entryName; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
490 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
491 |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
492 // See if the passed in agent is statically linked into the VM image. |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
493 bool os::find_builtin_agent(AgentLibrary *agent_lib, const char *syms[], |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
494 size_t syms_len) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
495 void *ret; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
496 void *proc_handle; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
497 void *save_handle; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
498 |
12220 | 499 assert(agent_lib != NULL, "sanity check"); |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
500 if (agent_lib->name() == NULL) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
501 return false; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
502 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
503 proc_handle = get_default_process_handle(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
504 // Check for Agent_OnLoad/Attach_lib_name function |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
505 save_handle = agent_lib->os_lib(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
506 // We want to look in this process' symbol table. |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
507 agent_lib->set_os_lib(proc_handle); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
508 ret = find_agent_function(agent_lib, true, syms, syms_len); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
509 if (ret != NULL) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
510 // Found an entry point like Agent_OnLoad_lib_name so we have a static agent |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
511 agent_lib->set_valid(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
512 agent_lib->set_static_lib(true); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
513 return true; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
514 } |
12220 | 515 agent_lib->set_os_lib(save_handle); |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
516 return false; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
517 } |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11151
diff
changeset
|
518 |
0 | 519 // --------------------- heap allocation utilities --------------------- |
520 | |
6197 | 521 char *os::strdup(const char *str, MEMFLAGS flags) { |
0 | 522 size_t size = strlen(str); |
6197 | 523 char *dup_str = (char *)malloc(size + 1, flags); |
0 | 524 if (dup_str == NULL) return NULL; |
525 strcpy(dup_str, str); | |
526 return dup_str; | |
527 } | |
528 | |
529 | |
530 | |
531 #define paranoid 0 /* only set to 1 if you suspect checking code has bug */ | |
532 | |
533 #ifdef ASSERT | |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
534 static void verify_memory(void* ptr) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
535 GuardedMemory guarded(ptr); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
536 if (!guarded.verify_guards()) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
537 tty->print_cr("## nof_mallocs = " UINT64_FORMAT ", nof_frees = " UINT64_FORMAT, os::num_mallocs, os::num_frees); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
538 tty->print_cr("## memory stomp:"); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
539 guarded.print_on(tty); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
540 fatal("memory stomping error"); |
0 | 541 } |
542 } | |
543 #endif | |
544 | |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
545 // |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
546 // This function supports testing of the malloc out of memory |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
547 // condition without really running the system out of memory. |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
548 // |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
549 static u_char* testMalloc(size_t alloc_size) { |
8808
81d1b58c078f
8010396: checking MallocMaxTestWords in testMalloc() function is redundant
rdurbin
parents:
8802
diff
changeset
|
550 assert(MallocMaxTestWords > 0, "sanity check"); |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
551 |
8808
81d1b58c078f
8010396: checking MallocMaxTestWords in testMalloc() function is redundant
rdurbin
parents:
8802
diff
changeset
|
552 if ((cur_malloc_words + (alloc_size / BytesPerWord)) > MallocMaxTestWords) { |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
553 return NULL; |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
554 } |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
555 |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
556 u_char* ptr = (u_char*)::malloc(alloc_size); |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
557 |
8808
81d1b58c078f
8010396: checking MallocMaxTestWords in testMalloc() function is redundant
rdurbin
parents:
8802
diff
changeset
|
558 if (ptr != NULL) { |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
559 Atomic::add(((jint) (alloc_size / BytesPerWord)), |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
560 (volatile jint *) &cur_malloc_words); |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
561 } |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
562 return ptr; |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
563 } |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
564 |
20360 | 565 void* os::malloc(size_t size, MEMFLAGS flags) { |
566 return os::malloc(size, flags, CALLER_PC); | |
567 } | |
568 | |
569 void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) { | |
2250 | 570 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); |
571 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); | |
0 | 572 |
11151 | 573 #ifdef ASSERT |
574 // checking for the WatcherThread and crash_protection first | |
575 // since os::malloc can be called when the libjvm.{dll,so} is | |
576 // first loaded and we don't have a thread yet. | |
577 // try to find the thread after we see that the watcher thread | |
578 // exists and has crash protection. | |
579 WatcherThread *wt = WatcherThread::watcher_thread(); | |
580 if (wt != NULL && wt->has_crash_protection()) { | |
581 Thread* thread = ThreadLocalStorage::get_thread_slow(); | |
582 if (thread == wt) { | |
583 assert(!wt->has_crash_protection(), | |
584 "Can't malloc with crash protection from WatcherThread"); | |
585 } | |
586 } | |
587 #endif | |
588 | |
0 | 589 if (size == 0) { |
590 // return a valid pointer if size is zero | |
591 // if NULL is returned the calling functions assume out of memory. | |
592 size = 1; | |
593 } | |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
594 |
20360 | 595 // NMT support |
596 NMT_TrackingLevel level = MemTracker::tracking_level(); | |
597 size_t nmt_header_size = MemTracker::malloc_header_size(level); | |
598 | |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
599 #ifndef ASSERT |
20360 | 600 const size_t alloc_size = size + nmt_header_size; |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
601 #else |
20360 | 602 const size_t alloc_size = GuardedMemory::get_total_size(size + nmt_header_size); |
603 if (size + nmt_header_size > alloc_size) { // Check for rollover. | |
6982
e4f764ddb06a
7122219: Passed StringTableSize value not verified
hseigel
parents:
6882
diff
changeset
|
604 return NULL; |
e4f764ddb06a
7122219: Passed StringTableSize value not verified
hseigel
parents:
6882
diff
changeset
|
605 } |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
606 #endif |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
607 |
0 | 608 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); |
8802
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
609 |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
610 u_char* ptr; |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
611 if (MallocMaxTestWords > 0) { |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
612 ptr = testMalloc(alloc_size); |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
613 } else { |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
614 ptr = (u_char*)::malloc(alloc_size); |
eca90b8a06eb
7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test
rdurbin
parents:
7994
diff
changeset
|
615 } |
6197 | 616 |
0 | 617 #ifdef ASSERT |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
618 if (ptr == NULL) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
619 return NULL; |
0 | 620 } |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
621 // Wrap memory with guard |
20360 | 622 GuardedMemory guarded(ptr, size + nmt_header_size); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
623 ptr = guarded.get_user_ptr(); |
0 | 624 #endif |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
625 if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
626 tty->print_cr("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr); |
0 | 627 breakpoint(); |
628 } | |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
629 debug_only(if (paranoid) verify_memory(ptr)); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
630 if (PrintMalloc && tty != NULL) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
631 tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
632 } |
6197 | 633 |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
634 // we do not track guard memory |
20360 | 635 return MemTracker::record_malloc((address)ptr, size, memflags, stack, level); |
0 | 636 } |
637 | |
20360 | 638 void* os::realloc(void *memblock, size_t size, MEMFLAGS flags) { |
639 return os::realloc(memblock, size, flags, CALLER_PC); | |
640 } | |
0 | 641 |
20360 | 642 void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCallStack& stack) { |
0 | 643 #ifndef ASSERT |
2250 | 644 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); |
645 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); | |
20360 | 646 // NMT support |
647 void* membase = MemTracker::record_free(memblock); | |
648 NMT_TrackingLevel level = MemTracker::tracking_level(); | |
649 size_t nmt_header_size = MemTracker::malloc_header_size(level); | |
650 void* ptr = ::realloc(membase, size + nmt_header_size); | |
651 return MemTracker::record_malloc(ptr, size, memflags, stack, level); | |
0 | 652 #else |
653 if (memblock == NULL) { | |
20360 | 654 return os::malloc(size, memflags, stack); |
0 | 655 } |
656 if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) { | |
2250 | 657 tty->print_cr("os::realloc caught " PTR_FORMAT, memblock); |
0 | 658 breakpoint(); |
659 } | |
20360 | 660 // NMT support |
661 void* membase = MemTracker::malloc_base(memblock); | |
662 verify_memory(membase); | |
0 | 663 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
664 if (size == 0) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
665 return NULL; |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
666 } |
0 | 667 // always move the block |
20360 | 668 void* ptr = os::malloc(size, memflags, stack); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
669 if (PrintMalloc) { |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
670 tty->print_cr("os::remalloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, memblock, ptr); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
671 } |
0 | 672 // Copy to new memory if malloc didn't fail |
673 if ( ptr != NULL ) { | |
20360 | 674 GuardedMemory guarded(MemTracker::malloc_base(memblock)); |
675 // Guard's user data contains NMT header | |
676 size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock); | |
677 memcpy(ptr, memblock, MIN2(size, memblock_size)); | |
678 if (paranoid) verify_memory(MemTracker::malloc_base(ptr)); | |
0 | 679 if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) { |
2250 | 680 tty->print_cr("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr); |
0 | 681 breakpoint(); |
682 } | |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
683 os::free(memblock); |
0 | 684 } |
685 return ptr; | |
686 #endif | |
687 } | |
688 | |
689 | |
6197 | 690 void os::free(void *memblock, MEMFLAGS memflags) { |
2250 | 691 NOT_PRODUCT(inc_stat_counter(&num_frees, 1)); |
0 | 692 #ifdef ASSERT |
693 if (memblock == NULL) return; | |
694 if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) { | |
2250 | 695 if (tty != NULL) tty->print_cr("os::free caught " PTR_FORMAT, memblock); |
0 | 696 breakpoint(); |
697 } | |
20360 | 698 void* membase = MemTracker::record_free(memblock); |
699 verify_memory(membase); | |
0 | 700 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
701 |
20360 | 702 GuardedMemory guarded(membase); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
703 size_t size = guarded.get_user_size(); |
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
704 inc_stat_counter(&free_bytes, size); |
20360 | 705 membase = guarded.release_for_freeing(); |
20318
fa62fb12cdca
6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
dsimms
parents:
17937
diff
changeset
|
706 if (PrintMalloc && tty != NULL) { |
20360 | 707 fprintf(stderr, "os::free " SIZE_FORMAT " bytes --> " PTR_FORMAT "\n", size, (uintptr_t)membase); |
0 | 708 } |
20360 | 709 ::free(membase); |
710 #else | |
711 void* membase = MemTracker::record_free(memblock); | |
712 ::free(membase); | |
0 | 713 #endif |
714 } | |
715 | |
716 void os::init_random(long initval) { | |
717 _rand_seed = initval; | |
718 } | |
719 | |
720 | |
721 long os::random() { | |
722 /* standard, well-known linear congruential random generator with | |
723 * next_rand = (16807*seed) mod (2**31-1) | |
724 * see | |
725 * (1) "Random Number Generators: Good Ones Are Hard to Find", | |
726 * S.K. Park and K.W. Miller, Communications of the ACM 31:10 (Oct 1988), | |
727 * (2) "Two Fast Implementations of the 'Minimal Standard' Random | |
728 * Number Generator", David G. Carta, Comm. ACM 33, 1 (Jan 1990), pp. 87-88. | |
729 */ | |
730 const long a = 16807; | |
731 const unsigned long m = 2147483647; | |
732 const long q = m / a; assert(q == 127773, "weird math"); | |
733 const long r = m % a; assert(r == 2836, "weird math"); | |
734 | |
735 // compute az=2^31p+q | |
736 unsigned long lo = a * (long)(_rand_seed & 0xFFFF); | |
737 unsigned long hi = a * (long)((unsigned long)_rand_seed >> 16); | |
738 lo += (hi & 0x7FFF) << 16; | |
739 | |
740 // if q overflowed, ignore the overflow and increment q | |
741 if (lo > m) { | |
742 lo &= m; | |
743 ++lo; | |
744 } | |
745 lo += hi >> 15; | |
746 | |
747 // if (p+q) overflowed, ignore the overflow and increment (p+q) | |
748 if (lo > m) { | |
749 lo &= m; | |
750 ++lo; | |
751 } | |
752 return (_rand_seed = lo); | |
753 } | |
754 | |
755 // The INITIALIZED state is distinguished from the SUSPENDED state because the | |
756 // conditions in which a thread is first started are different from those in which | |
757 // a suspension is resumed. These differences make it hard for us to apply the | |
758 // tougher checks when starting threads that we want to do when resuming them. | |
759 // However, when start_thread is called as a result of Thread.start, on a Java | |
760 // thread, the operation is synchronized on the Java Thread object. So there | |
761 // cannot be a race to start the thread and hence for the thread to exit while | |
762 // we are working on it. Non-Java threads that start Java threads either have | |
763 // to do so in a context in which races are impossible, or should do appropriate | |
764 // locking. | |
765 | |
766 void os::start_thread(Thread* thread) { | |
767 // guard suspend/resume | |
768 MutexLockerEx ml(thread->SR_lock(), Mutex::_no_safepoint_check_flag); | |
769 OSThread* osthread = thread->osthread(); | |
770 osthread->set_state(RUNNABLE); | |
771 pd_start_thread(thread); | |
772 } | |
773 | |
774 //--------------------------------------------------------------------------- | |
775 // Helper functions for fatal error handler | |
776 | |
777 void os::print_hex_dump(outputStream* st, address start, address end, int unitsize) { | |
778 assert(unitsize == 1 || unitsize == 2 || unitsize == 4 || unitsize == 8, "just checking"); | |
779 | |
780 int cols = 0; | |
781 int cols_per_line = 0; | |
782 switch (unitsize) { | |
783 case 1: cols_per_line = 16; break; | |
784 case 2: cols_per_line = 8; break; | |
785 case 4: cols_per_line = 4; break; | |
786 case 8: cols_per_line = 2; break; | |
787 default: return; | |
788 } | |
789 | |
790 address p = start; | |
791 st->print(PTR_FORMAT ": ", start); | |
792 while (p < end) { | |
793 switch (unitsize) { | |
794 case 1: st->print("%02x", *(u1*)p); break; | |
795 case 2: st->print("%04x", *(u2*)p); break; | |
796 case 4: st->print("%08x", *(u4*)p); break; | |
797 case 8: st->print("%016" FORMAT64_MODIFIER "x", *(u8*)p); break; | |
798 } | |
799 p += unitsize; | |
800 cols++; | |
801 if (cols >= cols_per_line && p < end) { | |
802 cols = 0; | |
803 st->cr(); | |
804 st->print(PTR_FORMAT ": ", p); | |
805 } else { | |
806 st->print(" "); | |
807 } | |
808 } | |
809 st->cr(); | |
810 } | |
811 | |
812 void os::print_environment_variables(outputStream* st, const char** env_list, | |
813 char* buffer, int len) { | |
814 if (env_list) { | |
815 st->print_cr("Environment Variables:"); | |
816 | |
817 for (int i = 0; env_list[i] != NULL; i++) { | |
818 if (getenv(env_list[i], buffer, len)) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
819 st->print("%s", env_list[i]); |
0 | 820 st->print("="); |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17935
diff
changeset
|
821 st->print_cr("%s", buffer); |
0 | 822 } |
823 } | |
824 } | |
825 } | |
826 | |
827 void os::print_cpu_info(outputStream* st) { | |
828 // cpu | |
829 st->print("CPU:"); | |
830 st->print("total %d", os::processor_count()); | |
831 // It's not safe to query number of active processors after crash | |
832 // st->print("(active %d)", os::active_processor_count()); | |
833 st->print(" %s", VM_Version::cpu_features()); | |
834 st->cr(); | |
3800
bf6481e5f96d
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
2469
diff
changeset
|
835 pd_print_cpu_info(st); |
0 | 836 } |
837 | |
838 void os::print_date_and_time(outputStream *st) { | |
17839
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
839 const int secs_per_day = 86400; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
840 const int secs_per_hour = 3600; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
841 const int secs_per_min = 60; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
842 |
0 | 843 time_t tloc; |
844 (void)time(&tloc); | |
845 st->print("time: %s", ctime(&tloc)); // ctime adds newline. | |
846 | |
847 double t = os::elapsedTime(); | |
848 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in | |
849 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int | |
850 // before printf. We lost some precision, but who cares? | |
17839
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
851 int eltime = (int)t; // elapsed time in seconds |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
852 |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
853 // print elapsed time in a human-readable format: |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
854 int eldays = eltime / secs_per_day; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
855 int day_secs = eldays * secs_per_day; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
856 int elhours = (eltime - day_secs) / secs_per_hour; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
857 int hour_secs = elhours * secs_per_hour; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
858 int elmins = (eltime - day_secs - hour_secs) / secs_per_min; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
859 int minute_secs = elmins * secs_per_min; |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
860 int elsecs = (eltime - day_secs - hour_secs - minute_secs); |
5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
dbuck
parents:
17799
diff
changeset
|
861 st->print_cr("elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs); |
0 | 862 } |
863 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
864 // moved from debug.cpp (used to be find()) but still called from there |
1907 | 865 // The verbose parameter is only set by the debug code in one case |
866 void os::print_location(outputStream* st, intptr_t x, bool verbose) { | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
867 address addr = (address)x; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
868 CodeBlob* b = CodeCache::find_blob_unsafe(addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
869 if (b != NULL) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
870 if (b->is_buffer_blob()) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
871 // the interpreter is generated into a buffer blob |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
872 InterpreterCodelet* i = Interpreter::codelet_containing(addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
873 if (i != NULL) { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
874 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", addr, (int)(addr - i->code_begin())); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
875 i->print_on(st); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
876 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
877 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
878 if (Interpreter::contains(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
879 st->print_cr(INTPTR_FORMAT " is pointing into interpreter code" |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
880 " (not bytecode specific)", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
881 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
882 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
883 // |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
884 if (AdapterHandlerLibrary::contains(b)) { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
885 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an AdapterHandler", addr, (int)(addr - b->code_begin())); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
886 AdapterHandlerLibrary::print_handler_on(st, b); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
887 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
888 // the stubroutines are generated into a buffer blob |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
889 StubCodeDesc* d = StubCodeDesc::desc_for(addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
890 if (d != NULL) { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
891 st->print_cr(INTPTR_FORMAT " is at begin+%d in a stub", addr, (int)(addr - d->begin())); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
892 d->print_on(st); |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
893 st->cr(); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
894 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
895 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
896 if (StubRoutines::contains(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
897 st->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) " |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
898 "stub routine", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
899 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
900 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
901 // the InlineCacheBuffer is using stubs generated into a buffer blob |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
902 if (InlineCacheBuffer::contains(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
903 st->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
904 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
905 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
906 VtableStub* v = VtableStubs::stub_containing(addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
907 if (v != NULL) { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
908 st->print_cr(INTPTR_FORMAT " is at entry_point+%d in a vtable stub", addr, (int)(addr - v->entry_point())); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
909 v->print_on(st); |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
910 st->cr(); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
911 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
912 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
913 } |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
914 nmethod* nm = b->as_nmethod_or_null(); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
915 if (nm != NULL) { |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
916 ResourceMark rm; |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
917 st->print(INTPTR_FORMAT " is at entry_point+%d in (nmethod*)" INTPTR_FORMAT, |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
918 addr, (int)(addr - nm->entry_point()), nm); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
919 if (verbose) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
920 st->print(" for "); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
921 nm->method()->print_value_on(st); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
922 } |
6816
87ac5c0a404d
8000228: Missing call to cr() when printing entry_point in nmethod, in os::print_location
stefank
parents:
6814
diff
changeset
|
923 st->cr(); |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
924 nm->print_nmethod(verbose); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
925 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
926 } |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6197
diff
changeset
|
927 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", addr, (int)(addr - b->code_begin())); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
928 b->print_on(st); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
929 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
930 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
931 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
932 if (Universe::heap()->is_in(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
933 HeapWord* p = Universe::heap()->block_start(addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
934 bool print = false; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
935 // If we couldn't find it it just may mean that heap wasn't parseable |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
936 // See if we were just given an oop directly |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
937 if (p != NULL && Universe::heap()->block_is_obj(p)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
938 print = true; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
939 } else if (p == NULL && ((oopDesc*)addr)->is_oop()) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
940 p = (HeapWord*) addr; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
941 print = true; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
942 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
943 if (print) { |
6814
85f1cded9793
8000230: Change os::print_location to be more descriptive when a location is pointing into an object
stefank
parents:
6766
diff
changeset
|
944 if (p == (HeapWord*) addr) { |
85f1cded9793
8000230: Change os::print_location to be more descriptive when a location is pointing into an object
stefank
parents:
6766
diff
changeset
|
945 st->print_cr(INTPTR_FORMAT " is an oop", addr); |
85f1cded9793
8000230: Change os::print_location to be more descriptive when a location is pointing into an object
stefank
parents:
6766
diff
changeset
|
946 } else { |
85f1cded9793
8000230: Change os::print_location to be more descriptive when a location is pointing into an object
stefank
parents:
6766
diff
changeset
|
947 st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, addr, p); |
85f1cded9793
8000230: Change os::print_location to be more descriptive when a location is pointing into an object
stefank
parents:
6766
diff
changeset
|
948 } |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
949 oop(p)->print_on(st); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
950 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
951 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
952 } else { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
953 if (Universe::heap()->is_in_reserved(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
954 st->print_cr(INTPTR_FORMAT " is an unallocated location " |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
955 "in the heap", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
956 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
957 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
958 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
959 if (JNIHandles::is_global_handle((jobject) addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
960 st->print_cr(INTPTR_FORMAT " is a global jni handle", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
961 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
962 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
963 if (JNIHandles::is_weak_global_handle((jobject) addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
964 st->print_cr(INTPTR_FORMAT " is a weak global jni handle", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
965 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
966 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
967 #ifndef PRODUCT |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
968 // we don't keep the block list in product mode |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
969 if (JNIHandleBlock::any_contains((jobject) addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
970 st->print_cr(INTPTR_FORMAT " is a local jni handle", addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
971 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
972 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
973 #endif |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
974 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
975 for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
976 // Check for privilege stack |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
977 if (thread->privileged_stack_top() != NULL && |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
978 thread->privileged_stack_top()->contains(addr)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
979 st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack " |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
980 "for thread: " INTPTR_FORMAT, addr, thread); |
1907 | 981 if (verbose) thread->print_on(st); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
982 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
983 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
984 // If the addr is a java thread print information about that. |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
985 if (addr == (address)thread) { |
1907 | 986 if (verbose) { |
987 thread->print_on(st); | |
988 } else { | |
989 st->print_cr(INTPTR_FORMAT " is a thread", addr); | |
990 } | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
991 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
992 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
993 // If the addr is in the stack region for this thread then report that |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
994 // and print thread info |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
995 if (thread->stack_base() >= addr && |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
996 addr > (thread->stack_base() - thread->stack_size())) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
997 st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: " |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
998 INTPTR_FORMAT, addr, thread); |
1907 | 999 if (verbose) thread->print_on(st); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1000 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1001 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1002 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1003 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1004 |
17935
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1005 // Check if in metaspace and print types that have vptrs (only method now) |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1006 if (Metaspace::contains(addr)) { |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1007 if (Method::has_method_vptr((const void*)addr)) { |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1008 ((Method*)addr)->print_value_on(st); |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1009 st->cr(); |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1010 } else { |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1011 // Use addr->print() from the debugger instead (not here) |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1012 st->print_cr(INTPTR_FORMAT " is pointing into metadata", addr); |
7384f6a12fc1
8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents:
17839
diff
changeset
|
1013 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1014 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1015 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1016 |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1017 // Try an OS specific find |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1018 if (os::find(addr, st)) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1019 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1020 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1021 |
1907 | 1022 st->print_cr(INTPTR_FORMAT " is an unknown value", addr); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1023 } |
0 | 1024 |
1025 // Looks like all platforms except IA64 can use the same function to check | |
1026 // if C stack is walkable beyond current frame. The check for fp() is not | |
1027 // necessary on Sparc, but it's harmless. | |
1028 bool os::is_first_C_frame(frame* fr) { | |
14403
75ef1a499665
8019973: PPC64 (part 11): Fix IA64 preprocessor conditionals on AIX.
goetz
parents:
10986
diff
changeset
|
1029 #if (defined(IA64) && !defined(AIX)) && !defined(_WIN32) |
7994 | 1030 // On IA64 we have to check if the callers bsp is still valid |
1031 // (i.e. within the register stack bounds). | |
1032 // Notice: this only works for threads created by the VM and only if | |
1033 // we walk the current stack!!! If we want to be able to walk | |
1034 // arbitrary other threads, we'll have to somehow store the thread | |
1035 // object in the frame. | |
1036 Thread *thread = Thread::current(); | |
1037 if ((address)fr->fp() <= | |
1038 thread->register_stack_base() HPUX_ONLY(+ 0x0) LINUX_ONLY(+ 0x50)) { | |
1039 // This check is a little hacky, because on Linux the first C | |
1040 // frame's ('start_thread') register stack frame starts at | |
1041 // "register_stack_base + 0x48" while on HPUX, the first C frame's | |
1042 // ('__pthread_bound_body') register stack frame seems to really | |
1043 // start at "register_stack_base". | |
1044 return true; | |
1045 } else { | |
1046 return false; | |
1047 } | |
1048 #elif defined(IA64) && defined(_WIN32) | |
0 | 1049 return true; |
7994 | 1050 #else |
0 | 1051 // Load up sp, fp, sender sp and sender fp, check for reasonable values. |
1052 // Check usp first, because if that's bad the other accessors may fault | |
1053 // on some architectures. Ditto ufp second, etc. | |
1054 uintptr_t fp_align_mask = (uintptr_t)(sizeof(address)-1); | |
1055 // sp on amd can be 32 bit aligned. | |
1056 uintptr_t sp_align_mask = (uintptr_t)(sizeof(int)-1); | |
1057 | |
1058 uintptr_t usp = (uintptr_t)fr->sp(); | |
1059 if ((usp & sp_align_mask) != 0) return true; | |
1060 | |
1061 uintptr_t ufp = (uintptr_t)fr->fp(); | |
1062 if ((ufp & fp_align_mask) != 0) return true; | |
1063 | |
1064 uintptr_t old_sp = (uintptr_t)fr->sender_sp(); | |
1065 if ((old_sp & sp_align_mask) != 0) return true; | |
1066 if (old_sp == 0 || old_sp == (uintptr_t)-1) return true; | |
1067 | |
1068 uintptr_t old_fp = (uintptr_t)fr->link(); | |
1069 if ((old_fp & fp_align_mask) != 0) return true; | |
1070 if (old_fp == 0 || old_fp == (uintptr_t)-1 || old_fp == ufp) return true; | |
1071 | |
1072 // stack grows downwards; if old_fp is below current fp or if the stack | |
1073 // frame is too large, either the stack is corrupted or fp is not saved | |
1074 // on stack (i.e. on x86, ebp may be used as general register). The stack | |
1075 // is not walkable beyond current frame. | |
1076 if (old_fp < ufp) return true; | |
1077 if (old_fp - ufp > 64 * K) return true; | |
1078 | |
1079 return false; | |
7994 | 1080 #endif |
0 | 1081 } |
1082 | |
1083 #ifdef ASSERT | |
1084 extern "C" void test_random() { | |
1085 const double m = 2147483647; | |
1086 double mean = 0.0, variance = 0.0, t; | |
1087 long reps = 10000; | |
1088 unsigned long seed = 1; | |
1089 | |
1090 tty->print_cr("seed %ld for %ld repeats...", seed, reps); | |
1091 os::init_random(seed); | |
1092 long num; | |
1093 for (int k = 0; k < reps; k++) { | |
1094 num = os::random(); | |
1095 double u = (double)num / m; | |
1096 assert(u >= 0.0 && u <= 1.0, "bad random number!"); | |
1097 | |
1098 // calculate mean and variance of the random sequence | |
1099 mean += u; | |
1100 variance += (u*u); | |
1101 } | |
1102 mean /= reps; | |
1103 variance /= (reps - 1); | |
1104 | |
1105 assert(num == 1043618065, "bad seed"); | |
1106 tty->print_cr("mean of the 1st 10000 numbers: %f", mean); | |
1107 tty->print_cr("variance of the 1st 10000 numbers: %f", variance); | |
1108 const double eps = 0.0001; | |
1109 t = fabsd(mean - 0.5018); | |
1110 assert(t < eps, "bad mean"); | |
1111 t = (variance - 0.3355) < 0.0 ? -(variance - 0.3355) : variance - 0.3355; | |
1112 assert(t < eps, "bad variance"); | |
1113 } | |
1114 #endif | |
1115 | |
1116 | |
1117 // Set up the boot classpath. | |
1118 | |
1119 char* os::format_boot_path(const char* format_string, | |
1120 const char* home, | |
1121 int home_len, | |
1122 char fileSep, | |
1123 char pathSep) { | |
1124 assert((fileSep == '/' && pathSep == ':') || | |
1125 (fileSep == '\\' && pathSep == ';'), "unexpected seperator chars"); | |
1126 | |
1127 // Scan the format string to determine the length of the actual | |
1128 // boot classpath, and handle platform dependencies as well. | |
1129 int formatted_path_len = 0; | |
1130 const char* p; | |
1131 for (p = format_string; *p != 0; ++p) { | |
1132 if (*p == '%') formatted_path_len += home_len - 1; | |
1133 ++formatted_path_len; | |
1134 } | |
1135 | |
6197 | 1136 char* formatted_path = NEW_C_HEAP_ARRAY(char, formatted_path_len + 1, mtInternal); |
0 | 1137 if (formatted_path == NULL) { |
1138 return NULL; | |
1139 } | |
1140 | |
1141 // Create boot classpath from format, substituting separator chars and | |
1142 // java home directory. | |
1143 char* q = formatted_path; | |
1144 for (p = format_string; *p != 0; ++p) { | |
1145 switch (*p) { | |
1146 case '%': | |
1147 strcpy(q, home); | |
1148 q += home_len; | |
1149 break; | |
1150 case '/': | |
1151 *q++ = fileSep; | |
1152 break; | |
1153 case ':': | |
1154 *q++ = pathSep; | |
1155 break; | |
1156 default: | |
1157 *q++ = *p; | |
1158 } | |
1159 } | |
1160 *q = '\0'; | |
1161 | |
1162 assert((q - formatted_path) == formatted_path_len, "formatted_path size botched"); | |
1163 return formatted_path; | |
1164 } | |
1165 | |
1166 | |
1167 bool os::set_boot_path(char fileSep, char pathSep) { | |
1168 const char* home = Arguments::get_java_home(); | |
1169 int home_len = (int)strlen(home); | |
1170 | |
1171 static const char* meta_index_dir_format = "%/lib/"; | |
1172 static const char* meta_index_format = "%/lib/meta-index"; | |
1173 char* meta_index = format_boot_path(meta_index_format, home, home_len, fileSep, pathSep); | |
1174 if (meta_index == NULL) return false; | |
1175 char* meta_index_dir = format_boot_path(meta_index_dir_format, home, home_len, fileSep, pathSep); | |
1176 if (meta_index_dir == NULL) return false; | |
1177 Arguments::set_meta_index_path(meta_index, meta_index_dir); | |
1178 | |
1179 // Any modification to the JAR-file list, for the boot classpath must be | |
1180 // aligned with install/install/make/common/Pack.gmk. Note: boot class | |
1181 // path class JARs, are stripped for StackMapTable to reduce download size. | |
1182 static const char classpath_format[] = | |
1183 "%/lib/resources.jar:" | |
1184 "%/lib/rt.jar:" | |
1185 "%/lib/sunrsasign.jar:" | |
1186 "%/lib/jsse.jar:" | |
1187 "%/lib/jce.jar:" | |
1188 "%/lib/charsets.jar:" | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4749
diff
changeset
|
1189 "%/lib/jfr.jar:" |
0 | 1190 "%/classes"; |
1191 char* sysclasspath = format_boot_path(classpath_format, home, home_len, fileSep, pathSep); | |
1192 if (sysclasspath == NULL) return false; | |
1193 Arguments::set_sysclasspath(sysclasspath); | |
1194 | |
1195 return true; | |
1196 } | |
1197 | |
691 | 1198 /* |
1199 * Splits a path, based on its separator, the number of | |
1200 * elements is returned back in n. | |
1201 * It is the callers responsibility to: | |
1202 * a> check the value of n, and n may be 0. | |
1203 * b> ignore any empty path elements | |
1204 * c> free up the data. | |
1205 */ | |
1206 char** os::split_path(const char* path, int* n) { | |
1207 *n = 0; | |
1208 if (path == NULL || strlen(path) == 0) { | |
1209 return NULL; | |
1210 } | |
1211 const char psepchar = *os::path_separator(); | |
6197 | 1212 char* inpath = (char*)NEW_C_HEAP_ARRAY(char, strlen(path) + 1, mtInternal); |
691 | 1213 if (inpath == NULL) { |
1214 return NULL; | |
1215 } | |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6882
diff
changeset
|
1216 strcpy(inpath, path); |
691 | 1217 int count = 1; |
1218 char* p = strchr(inpath, psepchar); | |
1219 // Get a count of elements to allocate memory | |
1220 while (p != NULL) { | |
1221 count++; | |
1222 p++; | |
1223 p = strchr(p, psepchar); | |
1224 } | |
6197 | 1225 char** opath = (char**) NEW_C_HEAP_ARRAY(char*, count, mtInternal); |
691 | 1226 if (opath == NULL) { |
1227 return NULL; | |
1228 } | |
1229 | |
1230 // do the actual splitting | |
1231 p = inpath; | |
1232 for (int i = 0 ; i < count ; i++) { | |
1233 size_t len = strcspn(p, os::path_separator()); | |
1234 if (len > JVM_MAXPATHLEN) { | |
1235 return NULL; | |
1236 } | |
1237 // allocate the string and add terminator storage | |
6197 | 1238 char* s = (char*)NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
691 | 1239 if (s == NULL) { |
1240 return NULL; | |
1241 } | |
1242 strncpy(s, p, len); | |
1243 s[len] = '\0'; | |
1244 opath[i] = s; | |
1245 p += len + 1; | |
1246 } | |
6197 | 1247 FREE_C_HEAP_ARRAY(char, inpath, mtInternal); |
691 | 1248 *n = count; |
1249 return opath; | |
1250 } | |
1251 | |
0 | 1252 void os::set_memory_serialize_page(address page) { |
1253 int count = log2_intptr(sizeof(class JavaThread)) - log2_intptr(64); | |
1254 _mem_serialize_page = (volatile int32_t *)page; | |
1255 // We initialize the serialization page shift count here | |
1256 // We assume a cache line size of 64 bytes | |
1257 assert(SerializePageShiftCount == count, | |
1258 "thread size changed, fix SerializePageShiftCount constant"); | |
1259 set_serialize_page_mask((uintptr_t)(vm_page_size() - sizeof(int32_t))); | |
1260 } | |
1261 | |
55
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1262 static volatile intptr_t SerializePageLock = 0; |
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1263 |
0 | 1264 // This method is called from signal handler when SIGSEGV occurs while the current |
1265 // thread tries to store to the "read-only" memory serialize page during state | |
1266 // transition. | |
1267 void os::block_on_serialize_page_trap() { | |
1268 if (TraceSafepoint) { | |
1269 tty->print_cr("Block until the serialize page permission restored"); | |
1270 } | |
55
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1271 // When VMThread is holding the SerializePageLock during modifying the |
0 | 1272 // access permission of the memory serialize page, the following call |
1273 // will block until the permission of that page is restored to rw. | |
1274 // Generally, it is unsafe to manipulate locks in signal handlers, but in | |
1275 // this case, it's OK as the signal is synchronous and we know precisely when | |
55
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1276 // it can occur. |
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1277 Thread::muxAcquire(&SerializePageLock, "set_memory_serialize_page"); |
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1278 Thread::muxRelease(&SerializePageLock); |
0 | 1279 } |
1280 | |
1281 // Serialize all thread state variables | |
1282 void os::serialize_thread_states() { | |
1283 // On some platforms such as Solaris & Linux, the time duration of the page | |
1284 // permission restoration is observed to be much longer than expected due to | |
1285 // scheduler starvation problem etc. To avoid the long synchronization | |
55
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1286 // time and expensive page trap spinning, 'SerializePageLock' is used to block |
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1287 // the mutator thread if such case is encountered. See bug 6546278 for details. |
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1288 Thread::muxAcquire(&SerializePageLock, "serialize_thread_states"); |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
1289 os::protect_memory((char *)os::get_memory_serialize_page(), |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
242
diff
changeset
|
1290 os::vm_page_size(), MEM_PROT_READ); |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
242
diff
changeset
|
1291 os::protect_memory((char *)os::get_memory_serialize_page(), |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
242
diff
changeset
|
1292 os::vm_page_size(), MEM_PROT_RW); |
55
2a8eb116ebbe
6610420: Debug VM crashes during monitor lock rank checking
xlu
parents:
0
diff
changeset
|
1293 Thread::muxRelease(&SerializePageLock); |
0 | 1294 } |
1295 | |
1296 // Returns true if the current stack pointer is above the stack shadow | |
1297 // pages, false otherwise. | |
1298 | |
1299 bool os::stack_shadow_pages_available(Thread *thread, methodHandle method) { | |
1300 assert(StackRedPages > 0 && StackYellowPages > 0,"Sanity check"); | |
1301 address sp = current_stack_pointer(); | |
1302 // Check if we have StackShadowPages above the yellow zone. This parameter | |
605 | 1303 // is dependent on the depth of the maximum VM call stack possible from |
0 | 1304 // the handler for stack overflow. 'instanceof' in the stack overflow |
1305 // handler or a println uses at least 8k stack of VM and native code | |
1306 // respectively. | |
1307 const int framesize_in_bytes = | |
1308 Interpreter::size_top_interpreter_activation(method()) * wordSize; | |
1309 int reserved_area = ((StackShadowPages + StackRedPages + StackYellowPages) | |
1310 * vm_page_size()) + framesize_in_bytes; | |
1311 // The very lower end of the stack | |
1312 address stack_limit = thread->stack_base() - thread->stack_size(); | |
1313 return (sp > (stack_limit + reserved_area)); | |
1314 } | |
1315 | |
1316 size_t os::page_size_for_region(size_t region_min_size, size_t region_max_size, | |
1317 uint min_pages) | |
1318 { | |
1319 assert(min_pages > 0, "sanity"); | |
1320 if (UseLargePages) { | |
1321 const size_t max_page_size = region_max_size / min_pages; | |
1322 | |
1323 for (unsigned int i = 0; _page_sizes[i] != 0; ++i) { | |
1324 const size_t sz = _page_sizes[i]; | |
1325 const size_t mask = sz - 1; | |
1326 if ((region_min_size & mask) == 0 && (region_max_size & mask) == 0) { | |
1327 // The largest page size with no fragmentation. | |
1328 return sz; | |
1329 } | |
1330 | |
1331 if (sz <= max_page_size) { | |
1332 // The largest page size that satisfies the min_pages requirement. | |
1333 return sz; | |
1334 } | |
1335 } | |
1336 } | |
1337 | |
1338 return vm_page_size(); | |
1339 } | |
1340 | |
1341 #ifndef PRODUCT | |
3859 | 1342 void os::trace_page_sizes(const char* str, const size_t* page_sizes, int count) |
1343 { | |
1344 if (TracePageSizes) { | |
1345 tty->print("%s: ", str); | |
1346 for (int i = 0; i < count; ++i) { | |
1347 tty->print(" " SIZE_FORMAT, page_sizes[i]); | |
1348 } | |
1349 tty->cr(); | |
1350 } | |
1351 } | |
1352 | |
0 | 1353 void os::trace_page_sizes(const char* str, const size_t region_min_size, |
1354 const size_t region_max_size, const size_t page_size, | |
1355 const char* base, const size_t size) | |
1356 { | |
1357 if (TracePageSizes) { | |
1358 tty->print_cr("%s: min=" SIZE_FORMAT " max=" SIZE_FORMAT | |
1359 " pg_sz=" SIZE_FORMAT " base=" PTR_FORMAT | |
1360 " size=" SIZE_FORMAT, | |
1361 str, region_min_size, region_max_size, | |
1362 page_size, base, size); | |
1363 } | |
1364 } | |
1365 #endif // #ifndef PRODUCT | |
1366 | |
1367 // This is the working definition of a server class machine: | |
1368 // >= 2 physical CPU's and >=2GB of memory, with some fuzz | |
1369 // because the graphics memory (?) sometimes masks physical memory. | |
1370 // If you want to change the definition of a server class machine | |
1371 // on some OS or platform, e.g., >=4GB on Windohs platforms, | |
1372 // then you'll have to parameterize this method based on that state, | |
1373 // as was done for logical processors here, or replicate and | |
1374 // specialize this method for each platform. (Or fix os to have | |
1375 // some inheritance structure and use subclassing. Sigh.) | |
1376 // If you want some platform to always or never behave as a server | |
1377 // class machine, change the setting of AlwaysActAsServerClassMachine | |
1378 // and NeverActAsServerClassMachine in globals*.hpp. | |
1379 bool os::is_server_class_machine() { | |
1380 // First check for the early returns | |
1381 if (NeverActAsServerClassMachine) { | |
1382 return false; | |
1383 } | |
1384 if (AlwaysActAsServerClassMachine) { | |
1385 return true; | |
1386 } | |
1387 // Then actually look at the machine | |
1388 bool result = false; | |
1389 const unsigned int server_processors = 2; | |
1390 const julong server_memory = 2UL * G; | |
1391 // We seem not to get our full complement of memory. | |
1392 // We allow some part (1/8?) of the memory to be "missing", | |
1393 // based on the sizes of DIMMs, and maybe graphics cards. | |
1394 const julong missing_memory = 256UL * M; | |
1395 | |
1396 /* Is this a server class machine? */ | |
1397 if ((os::active_processor_count() >= (int)server_processors) && | |
1398 (os::physical_memory() >= (server_memory - missing_memory))) { | |
1399 const unsigned int logical_processors = | |
1400 VM_Version::logical_processors_per_package(); | |
1401 if (logical_processors > 1) { | |
1402 const unsigned int physical_packages = | |
1403 os::active_processor_count() / logical_processors; | |
1404 if (physical_packages > server_processors) { | |
1405 result = true; | |
1406 } | |
1407 } else { | |
1408 result = true; | |
1409 } | |
1410 } | |
1411 return result; | |
1412 } | |
2469
677234770800
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
2387
diff
changeset
|
1413 |
10405 | 1414 void os::SuspendedThreadTask::run() { |
1415 assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this"); | |
1416 internal_do_task(); | |
1417 _done = true; | |
1418 } | |
1419 | |
6197 | 1420 bool os::create_stack_guard_pages(char* addr, size_t bytes) { |
1421 return os::pd_create_stack_guard_pages(addr, bytes); | |
1422 } | |
1423 | |
1424 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { | |
1425 char* result = pd_reserve_memory(bytes, addr, alignment_hint); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6816
diff
changeset
|
1426 if (result != NULL) { |
20360 | 1427 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
6197 | 1428 } |
1429 | |
1430 return result; | |
1431 } | |
10221
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1432 |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1433 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint, |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1434 MEMFLAGS flags) { |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1435 char* result = pd_reserve_memory(bytes, addr, alignment_hint); |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1436 if (result != NULL) { |
20360 | 1437 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
10221
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1438 MemTracker::record_virtual_memory_type((address)result, flags); |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1439 } |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1440 |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1441 return result; |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1442 } |
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
8808
diff
changeset
|
1443 |
6197 | 1444 char* os::attempt_reserve_memory_at(size_t bytes, char* addr) { |
1445 char* result = pd_attempt_reserve_memory_at(bytes, addr); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6816
diff
changeset
|
1446 if (result != NULL) { |
20360 | 1447 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
6197 | 1448 } |
1449 return result; | |
1450 } | |
1451 | |
1452 void os::split_reserved_memory(char *base, size_t size, | |
1453 size_t split, bool realloc) { | |
1454 pd_split_reserved_memory(base, size, split, realloc); | |
1455 } | |
1456 | |
1457 bool os::commit_memory(char* addr, size_t bytes, bool executable) { | |
1458 bool res = pd_commit_memory(addr, bytes, executable); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6816
diff
changeset
|
1459 if (res) { |
6197 | 1460 MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC); |
1461 } | |
1462 return res; | |
1463 } | |
1464 | |
1465 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, | |
1466 bool executable) { | |
1467 bool res = os::pd_commit_memory(addr, size, alignment_hint, executable); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6816
diff
changeset
|
1468 if (res) { |
6197 | 1469 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); |
1470 } | |
1471 return res; | |
1472 } | |
1473 | |
10969
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1474 void os::commit_memory_or_exit(char* addr, size_t bytes, bool executable, |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1475 const char* mesg) { |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1476 pd_commit_memory_or_exit(addr, bytes, executable, mesg); |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1477 MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC); |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1478 } |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1479 |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1480 void os::commit_memory_or_exit(char* addr, size_t size, size_t alignment_hint, |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1481 bool executable, const char* mesg) { |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1482 os::pd_commit_memory_or_exit(addr, size, alignment_hint, executable, mesg); |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1483 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1484 } |
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10405
diff
changeset
|
1485 |
6197 | 1486 bool os::uncommit_memory(char* addr, size_t bytes) { |
20360 | 1487 bool res; |
1488 if (MemTracker::tracking_level() > NMT_minimal) { | |
1489 Tracker tkr = MemTracker::get_virtual_memory_uncommit_tracker(); | |
1490 res = pd_uncommit_memory(addr, bytes); | |
1491 if (res) { | |
1492 tkr.record((address)addr, bytes); | |
1493 } | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10969
diff
changeset
|
1494 } else { |
20360 | 1495 res = pd_uncommit_memory(addr, bytes); |
6197 | 1496 } |
1497 return res; | |
1498 } | |
1499 | |
1500 bool os::release_memory(char* addr, size_t bytes) { | |
20360 | 1501 bool res; |
1502 if (MemTracker::tracking_level() > NMT_minimal) { | |
1503 Tracker tkr = MemTracker::get_virtual_memory_release_tracker(); | |
1504 res = pd_release_memory(addr, bytes); | |
1505 if (res) { | |
1506 tkr.record((address)addr, bytes); | |
1507 } | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10969
diff
changeset
|
1508 } else { |
20360 | 1509 res = pd_release_memory(addr, bytes); |
6197 | 1510 } |
1511 return res; | |
1512 } | |
1513 | |
1514 | |
1515 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | |
1516 char *addr, size_t bytes, bool read_only, | |
1517 bool allow_exec) { | |
1518 char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6816
diff
changeset
|
1519 if (result != NULL) { |
20360 | 1520 MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, CALLER_PC); |
6197 | 1521 } |
1522 return result; | |
1523 } | |
1524 | |
1525 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, | |
1526 char *addr, size_t bytes, bool read_only, | |
1527 bool allow_exec) { | |
1528 return pd_remap_memory(fd, file_name, file_offset, addr, bytes, | |
1529 read_only, allow_exec); | |
1530 } | |
1531 | |
1532 bool os::unmap_memory(char *addr, size_t bytes) { | |
20360 | 1533 bool result; |
1534 if (MemTracker::tracking_level() > NMT_minimal) { | |
1535 Tracker tkr = MemTracker::get_virtual_memory_release_tracker(); | |
1536 result = pd_unmap_memory(addr, bytes); | |
1537 if (result) { | |
1538 tkr.record((address)addr, bytes); | |
1539 } | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
10969
diff
changeset
|
1540 } else { |
20360 | 1541 result = pd_unmap_memory(addr, bytes); |
6197 | 1542 } |
1543 return result; | |
1544 } | |
1545 | |
1546 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { | |
1547 pd_free_memory(addr, bytes, alignment_hint); | |
1548 } | |
1549 | |
1550 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { | |
1551 pd_realign_memory(addr, bytes, alignment_hint); | |
1552 } | |
1553 | |
10405 | 1554 #ifndef TARGET_OS_FAMILY_windows |
1555 /* try to switch state from state "from" to state "to" | |
1556 * returns the state set after the method is complete | |
1557 */ | |
1558 os::SuspendResume::State os::SuspendResume::switch_state(os::SuspendResume::State from, | |
1559 os::SuspendResume::State to) | |
1560 { | |
1561 os::SuspendResume::State result = | |
1562 (os::SuspendResume::State) Atomic::cmpxchg((jint) to, (jint *) &_state, (jint) from); | |
1563 if (result == from) { | |
1564 // success | |
1565 return to; | |
1566 } | |
1567 return result; | |
1568 } | |
1569 #endif |