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