Mercurial > hg > graal-compiler
comparison src/share/vm/runtime/os.cpp @ 6948:e522a00b91aa
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 12 Nov 2012 23:14:12 +0100 |
parents | 957c266d8bc5 716c64bda5ba |
children | 2cb439954abf |
comparison
equal
deleted
inserted
replaced
6711:ae13cc658b80 | 6948:e522a00b91aa |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
199 assert(false, "Should not happen"); | 199 assert(false, "Should not happen"); |
200 return OS_ERR; | 200 return OS_ERR; |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 | 204 // The mapping from OS priority back to Java priority may be inexact because |
205 // Java priorities can map M:1 with native priorities. If you want the definite | |
206 // Java priority then use JavaThread::java_priority() | |
205 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) { | 207 OSReturn os::get_priority(const Thread* const thread, ThreadPriority& priority) { |
206 int p; | 208 int p; |
207 int os_prio; | 209 int os_prio; |
208 OSReturn ret = get_native_priority(thread, &os_prio); | 210 OSReturn ret = get_native_priority(thread, &os_prio); |
209 if (ret != OS_OK) return ret; | 211 if (ret != OS_OK) return ret; |
210 | 212 |
211 for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] > os_prio; p--) ; | 213 if (java_to_os_priority[MaxPriority] > java_to_os_priority[MinPriority]) { |
214 for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] > os_prio; p--) ; | |
215 } else { | |
216 // niceness values are in reverse order | |
217 for (p = MaxPriority; p > MinPriority && java_to_os_priority[p] < os_prio; p--) ; | |
218 } | |
212 priority = (ThreadPriority)p; | 219 priority = (ThreadPriority)p; |
213 return OS_OK; | 220 return OS_OK; |
214 } | 221 } |
215 | 222 |
216 | 223 |
269 break; | 276 break; |
270 } | 277 } |
271 default: { | 278 default: { |
272 // Dispatch the signal to java | 279 // Dispatch the signal to java |
273 HandleMark hm(THREAD); | 280 HandleMark hm(THREAD); |
274 klassOop k = SystemDictionary::resolve_or_null(vmSymbols::sun_misc_Signal(), THREAD); | 281 Klass* k = SystemDictionary::resolve_or_null(vmSymbols::sun_misc_Signal(), THREAD); |
275 KlassHandle klass (THREAD, k); | 282 KlassHandle klass (THREAD, k); |
276 if (klass.not_null()) { | 283 if (klass.not_null()) { |
277 JavaValue result(T_VOID); | 284 JavaValue result(T_VOID); |
278 JavaCallArguments args; | 285 JavaCallArguments args; |
279 args.push_int(sig); | 286 args.push_int(sig); |
292 // trigger additional out-of-memory conditions | 299 // trigger additional out-of-memory conditions |
293 if (tty != NULL) { | 300 if (tty != NULL) { |
294 char klass_name[256]; | 301 char klass_name[256]; |
295 char tmp_sig_name[16]; | 302 char tmp_sig_name[16]; |
296 const char* sig_name = "UNKNOWN"; | 303 const char* sig_name = "UNKNOWN"; |
297 instanceKlass::cast(PENDING_EXCEPTION->klass())-> | 304 InstanceKlass::cast(PENDING_EXCEPTION->klass())-> |
298 name()->as_klass_external_name(klass_name, 256); | 305 name()->as_klass_external_name(klass_name, 256); |
299 if (os::exception_name(sig, tmp_sig_name, 16) != NULL) | 306 if (os::exception_name(sig, tmp_sig_name, 16) != NULL) |
300 sig_name = tmp_sig_name; | 307 sig_name = tmp_sig_name; |
301 warning("Exception %s occurred dispatching signal %s to handler" | 308 warning("Exception %s occurred dispatching signal %s to handler" |
302 "- the VM may need to be forcibly terminated", | 309 "- the VM may need to be forcibly terminated", |
312 | 319 |
313 void os::signal_init() { | 320 void os::signal_init() { |
314 if (!ReduceSignalUsage) { | 321 if (!ReduceSignalUsage) { |
315 // Setup JavaThread for processing signals | 322 // Setup JavaThread for processing signals |
316 EXCEPTION_MARK; | 323 EXCEPTION_MARK; |
317 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); | 324 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
318 instanceKlassHandle klass (THREAD, k); | 325 instanceKlassHandle klass (THREAD, k); |
319 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); | 326 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); |
320 | 327 |
321 const char thread_name[] = "Signal Dispatcher"; | 328 const char thread_name[] = "Signal Dispatcher"; |
322 Handle string = java_lang_String::create_from_str(thread_name, CHECK); | 329 Handle string = java_lang_String::create_from_str(thread_name, CHECK); |
591 } | 598 } |
592 debug_only(if (paranoid) verify_block(memblock)); | 599 debug_only(if (paranoid) verify_block(memblock)); |
593 if (PrintMalloc && tty != NULL) tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, memblock); | 600 if (PrintMalloc && tty != NULL) tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, memblock); |
594 | 601 |
595 // we do not track MallocCushion memory | 602 // we do not track MallocCushion memory |
596 if (MemTracker::is_on()) { | |
597 MemTracker::record_malloc((address)memblock, size, memflags, caller == 0 ? CALLER_PC : caller); | 603 MemTracker::record_malloc((address)memblock, size, memflags, caller == 0 ? CALLER_PC : caller); |
598 } | |
599 | 604 |
600 return memblock; | 605 return memblock; |
601 } | 606 } |
602 | 607 |
603 | 608 |
604 void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, address caller) { | 609 void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, address caller) { |
605 #ifndef ASSERT | 610 #ifndef ASSERT |
606 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); | 611 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); |
607 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); | 612 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); |
608 void* ptr = ::realloc(memblock, size); | 613 void* ptr = ::realloc(memblock, size); |
609 if (ptr != NULL && MemTracker::is_on()) { | 614 if (ptr != NULL) { |
610 MemTracker::record_realloc((address)memblock, (address)ptr, size, memflags, | 615 MemTracker::record_realloc((address)memblock, (address)ptr, size, memflags, |
611 caller == 0 ? CALLER_PC : caller); | 616 caller == 0 ? CALLER_PC : caller); |
612 } | 617 } |
613 return ptr; | 618 return ptr; |
614 #else | 619 #else |
869 addr, (int)(addr - nm->entry_point()), nm); | 874 addr, (int)(addr - nm->entry_point()), nm); |
870 if (verbose) { | 875 if (verbose) { |
871 st->print(" for "); | 876 st->print(" for "); |
872 nm->method()->print_value_on(st); | 877 nm->method()->print_value_on(st); |
873 } | 878 } |
879 st->cr(); | |
874 nm->print_nmethod(verbose); | 880 nm->print_nmethod(verbose); |
875 return; | 881 return; |
876 } | 882 } |
877 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", addr, (int)(addr - b->code_begin())); | 883 st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", addr, (int)(addr - b->code_begin())); |
878 b->print_on(st); | 884 b->print_on(st); |
889 } else if (p == NULL && ((oopDesc*)addr)->is_oop()) { | 895 } else if (p == NULL && ((oopDesc*)addr)->is_oop()) { |
890 p = (HeapWord*) addr; | 896 p = (HeapWord*) addr; |
891 print = true; | 897 print = true; |
892 } | 898 } |
893 if (print) { | 899 if (print) { |
894 st->print_cr(INTPTR_FORMAT " is an oop", addr); | 900 if (p == (HeapWord*) addr) { |
901 st->print_cr(INTPTR_FORMAT " is an oop", addr); | |
902 } else { | |
903 st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, addr, p); | |
904 } | |
895 oop(p)->print_on(st); | 905 oop(p)->print_on(st); |
896 if (p != (HeapWord*)x && oop(p)->is_constMethod() && | |
897 constMethodOop(p)->contains(addr)) { | |
898 Thread *thread = Thread::current(); | |
899 HandleMark hm(thread); | |
900 methodHandle mh (thread, constMethodOop(p)->method()); | |
901 if (!mh->is_native()) { | |
902 st->print_cr("bci_from(%p) = %d; print_codes():", | |
903 addr, mh->bci_from(address(x))); | |
904 mh->print_codes_on(st); | |
905 } | |
906 } | |
907 return; | 906 return; |
908 } | 907 } |
909 } else { | 908 } else { |
910 if (Universe::heap()->is_in_reserved(addr)) { | 909 if (Universe::heap()->is_in_reserved(addr)) { |
911 st->print_cr(INTPTR_FORMAT " is an unallocated location " | 910 st->print_cr(INTPTR_FORMAT " is an unallocated location " |
956 if (verbose) thread->print_on(st); | 955 if (verbose) thread->print_on(st); |
957 return; | 956 return; |
958 } | 957 } |
959 | 958 |
960 } | 959 } |
960 | |
961 #ifndef PRODUCT | |
962 // Check if in metaspace. | |
963 if (ClassLoaderDataGraph::contains((address)addr)) { | |
964 // Use addr->print() from the debugger instead (not here) | |
965 st->print_cr(INTPTR_FORMAT | |
966 " is pointing into metadata", addr); | |
967 return; | |
968 } | |
969 #endif | |
970 | |
961 // Try an OS specific find | 971 // Try an OS specific find |
962 if (os::find(addr, st)) { | 972 if (os::find(addr, st)) { |
963 return; | 973 return; |
964 } | 974 } |
965 | 975 |
1387 } | 1397 } |
1388 | 1398 |
1389 | 1399 |
1390 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { | 1400 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { |
1391 char* result = pd_reserve_memory(bytes, addr, alignment_hint); | 1401 char* result = pd_reserve_memory(bytes, addr, alignment_hint); |
1392 if (result != NULL && MemTracker::is_on()) { | 1402 if (result != NULL) { |
1393 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1403 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
1394 } | 1404 } |
1395 | 1405 |
1396 return result; | 1406 return result; |
1397 } | 1407 } |
1398 char* os::attempt_reserve_memory_at(size_t bytes, char* addr) { | 1408 char* os::attempt_reserve_memory_at(size_t bytes, char* addr) { |
1399 char* result = pd_attempt_reserve_memory_at(bytes, addr); | 1409 char* result = pd_attempt_reserve_memory_at(bytes, addr); |
1400 if (result != NULL && MemTracker::is_on()) { | 1410 if (result != NULL) { |
1401 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1411 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
1402 } | 1412 } |
1403 return result; | 1413 return result; |
1404 } | 1414 } |
1405 | 1415 |
1408 pd_split_reserved_memory(base, size, split, realloc); | 1418 pd_split_reserved_memory(base, size, split, realloc); |
1409 } | 1419 } |
1410 | 1420 |
1411 bool os::commit_memory(char* addr, size_t bytes, bool executable) { | 1421 bool os::commit_memory(char* addr, size_t bytes, bool executable) { |
1412 bool res = pd_commit_memory(addr, bytes, executable); | 1422 bool res = pd_commit_memory(addr, bytes, executable); |
1413 if (res && MemTracker::is_on()) { | 1423 if (res) { |
1414 MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC); | 1424 MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC); |
1415 } | 1425 } |
1416 return res; | 1426 return res; |
1417 } | 1427 } |
1418 | 1428 |
1419 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, | 1429 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, |
1420 bool executable) { | 1430 bool executable) { |
1421 bool res = os::pd_commit_memory(addr, size, alignment_hint, executable); | 1431 bool res = os::pd_commit_memory(addr, size, alignment_hint, executable); |
1422 if (res && MemTracker::is_on()) { | 1432 if (res) { |
1423 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); | 1433 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); |
1424 } | 1434 } |
1425 return res; | 1435 return res; |
1426 } | 1436 } |
1427 | 1437 |
1444 | 1454 |
1445 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | 1455 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
1446 char *addr, size_t bytes, bool read_only, | 1456 char *addr, size_t bytes, bool read_only, |
1447 bool allow_exec) { | 1457 bool allow_exec) { |
1448 char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec); | 1458 char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec); |
1449 if (result != NULL && MemTracker::is_on()) { | 1459 if (result != NULL) { |
1450 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1460 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); |
1461 MemTracker::record_virtual_memory_commit((address)result, bytes, CALLER_PC); | |
1451 } | 1462 } |
1452 return result; | 1463 return result; |
1453 } | 1464 } |
1454 | 1465 |
1455 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, | 1466 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, |
1460 } | 1471 } |
1461 | 1472 |
1462 bool os::unmap_memory(char *addr, size_t bytes) { | 1473 bool os::unmap_memory(char *addr, size_t bytes) { |
1463 bool result = pd_unmap_memory(addr, bytes); | 1474 bool result = pd_unmap_memory(addr, bytes); |
1464 if (result) { | 1475 if (result) { |
1476 MemTracker::record_virtual_memory_uncommit((address)addr, bytes); | |
1465 MemTracker::record_virtual_memory_release((address)addr, bytes); | 1477 MemTracker::record_virtual_memory_release((address)addr, bytes); |
1466 } | 1478 } |
1467 return result; | 1479 return result; |
1468 } | 1480 } |
1469 | 1481 |