Mercurial > hg > graal-compiler
comparison src/share/vm/runtime/os.cpp @ 11173:6b0fd0964b87
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 31 Jul 2013 11:00:54 +0200 |
parents | 836a62f43af9 5e3b6f79d280 |
children | cefad50507d8 |
comparison
equal
deleted
inserted
replaced
10912:4ea54634f03e | 11173:6b0fd0964b87 |
---|---|
593 | 593 |
594 void* os::malloc(size_t size, MEMFLAGS memflags, address caller) { | 594 void* os::malloc(size_t size, MEMFLAGS memflags, address caller) { |
595 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); | 595 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); |
596 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); | 596 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); |
597 | 597 |
598 #ifdef ASSERT | |
599 // checking for the WatcherThread and crash_protection first | |
600 // since os::malloc can be called when the libjvm.{dll,so} is | |
601 // first loaded and we don't have a thread yet. | |
602 // try to find the thread after we see that the watcher thread | |
603 // exists and has crash protection. | |
604 WatcherThread *wt = WatcherThread::watcher_thread(); | |
605 if (wt != NULL && wt->has_crash_protection()) { | |
606 Thread* thread = ThreadLocalStorage::get_thread_slow(); | |
607 if (thread == wt) { | |
608 assert(!wt->has_crash_protection(), | |
609 "Can't malloc with crash protection from WatcherThread"); | |
610 } | |
611 } | |
612 #endif | |
613 | |
598 if (size == 0) { | 614 if (size == 0) { |
599 // return a valid pointer if size is zero | 615 // return a valid pointer if size is zero |
600 // if NULL is returned the calling functions assume out of memory. | 616 // if NULL is returned the calling functions assume out of memory. |
601 size = 1; | 617 size = 1; |
602 } | 618 } |
645 | 661 |
646 void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, address caller) { | 662 void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, address caller) { |
647 #ifndef ASSERT | 663 #ifndef ASSERT |
648 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); | 664 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); |
649 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); | 665 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); |
666 MemTracker::Tracker tkr = MemTracker::get_realloc_tracker(); | |
650 void* ptr = ::realloc(memblock, size); | 667 void* ptr = ::realloc(memblock, size); |
651 if (ptr != NULL) { | 668 if (ptr != NULL) { |
652 MemTracker::record_realloc((address)memblock, (address)ptr, size, memflags, | 669 tkr.record((address)memblock, (address)ptr, size, memflags, |
653 caller == 0 ? CALLER_PC : caller); | 670 caller == 0 ? CALLER_PC : caller); |
671 } else { | |
672 tkr.discard(); | |
654 } | 673 } |
655 return ptr; | 674 return ptr; |
656 #else | 675 #else |
657 if (memblock == NULL) { | 676 if (memblock == NULL) { |
658 return malloc(size, memflags, (caller == 0 ? CALLER_PC : caller)); | 677 return malloc(size, memflags, (caller == 0 ? CALLER_PC : caller)); |
1457 } | 1476 } |
1458 | 1477 |
1459 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { | 1478 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { |
1460 char* result = pd_reserve_memory(bytes, addr, alignment_hint); | 1479 char* result = pd_reserve_memory(bytes, addr, alignment_hint); |
1461 if (result != NULL) { | 1480 if (result != NULL) { |
1462 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1481 MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC); |
1463 } | 1482 } |
1464 | 1483 |
1465 return result; | 1484 return result; |
1466 } | 1485 } |
1467 | 1486 |
1468 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint, | 1487 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint, |
1469 MEMFLAGS flags) { | 1488 MEMFLAGS flags) { |
1470 char* result = pd_reserve_memory(bytes, addr, alignment_hint); | 1489 char* result = pd_reserve_memory(bytes, addr, alignment_hint); |
1471 if (result != NULL) { | 1490 if (result != NULL) { |
1472 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1491 MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC); |
1473 MemTracker::record_virtual_memory_type((address)result, flags); | 1492 MemTracker::record_virtual_memory_type((address)result, flags); |
1474 } | 1493 } |
1475 | 1494 |
1476 return result; | 1495 return result; |
1477 } | 1496 } |
1478 | 1497 |
1479 char* os::attempt_reserve_memory_at(size_t bytes, char* addr) { | 1498 char* os::attempt_reserve_memory_at(size_t bytes, char* addr) { |
1480 char* result = pd_attempt_reserve_memory_at(bytes, addr); | 1499 char* result = pd_attempt_reserve_memory_at(bytes, addr); |
1481 if (result != NULL) { | 1500 if (result != NULL) { |
1482 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1501 MemTracker::record_virtual_memory_reserve((address)result, bytes, mtNone, CALLER_PC); |
1483 } | 1502 } |
1484 return result; | 1503 return result; |
1485 } | 1504 } |
1486 | 1505 |
1487 void os::split_reserved_memory(char *base, size_t size, | 1506 void os::split_reserved_memory(char *base, size_t size, |
1504 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); | 1523 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); |
1505 } | 1524 } |
1506 return res; | 1525 return res; |
1507 } | 1526 } |
1508 | 1527 |
1528 void os::commit_memory_or_exit(char* addr, size_t bytes, bool executable, | |
1529 const char* mesg) { | |
1530 pd_commit_memory_or_exit(addr, bytes, executable, mesg); | |
1531 MemTracker::record_virtual_memory_commit((address)addr, bytes, CALLER_PC); | |
1532 } | |
1533 | |
1534 void os::commit_memory_or_exit(char* addr, size_t size, size_t alignment_hint, | |
1535 bool executable, const char* mesg) { | |
1536 os::pd_commit_memory_or_exit(addr, size, alignment_hint, executable, mesg); | |
1537 MemTracker::record_virtual_memory_commit((address)addr, size, CALLER_PC); | |
1538 } | |
1539 | |
1509 bool os::uncommit_memory(char* addr, size_t bytes) { | 1540 bool os::uncommit_memory(char* addr, size_t bytes) { |
1541 MemTracker::Tracker tkr = MemTracker::get_virtual_memory_uncommit_tracker(); | |
1510 bool res = pd_uncommit_memory(addr, bytes); | 1542 bool res = pd_uncommit_memory(addr, bytes); |
1511 if (res) { | 1543 if (res) { |
1512 MemTracker::record_virtual_memory_uncommit((address)addr, bytes); | 1544 tkr.record((address)addr, bytes); |
1545 } else { | |
1546 tkr.discard(); | |
1513 } | 1547 } |
1514 return res; | 1548 return res; |
1515 } | 1549 } |
1516 | 1550 |
1517 bool os::release_memory(char* addr, size_t bytes) { | 1551 bool os::release_memory(char* addr, size_t bytes) { |
1552 MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker(); | |
1518 bool res = pd_release_memory(addr, bytes); | 1553 bool res = pd_release_memory(addr, bytes); |
1519 if (res) { | 1554 if (res) { |
1520 MemTracker::record_virtual_memory_release((address)addr, bytes); | 1555 tkr.record((address)addr, bytes); |
1556 } else { | |
1557 tkr.discard(); | |
1521 } | 1558 } |
1522 return res; | 1559 return res; |
1523 } | 1560 } |
1524 | 1561 |
1525 | 1562 |
1526 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | 1563 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
1527 char *addr, size_t bytes, bool read_only, | 1564 char *addr, size_t bytes, bool read_only, |
1528 bool allow_exec) { | 1565 bool allow_exec) { |
1529 char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec); | 1566 char* result = pd_map_memory(fd, file_name, file_offset, addr, bytes, read_only, allow_exec); |
1530 if (result != NULL) { | 1567 if (result != NULL) { |
1531 MemTracker::record_virtual_memory_reserve((address)result, bytes, CALLER_PC); | 1568 MemTracker::record_virtual_memory_reserve_and_commit((address)result, bytes, mtNone, CALLER_PC); |
1532 MemTracker::record_virtual_memory_commit((address)result, bytes, CALLER_PC); | |
1533 } | 1569 } |
1534 return result; | 1570 return result; |
1535 } | 1571 } |
1536 | 1572 |
1537 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, | 1573 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, |
1540 return pd_remap_memory(fd, file_name, file_offset, addr, bytes, | 1576 return pd_remap_memory(fd, file_name, file_offset, addr, bytes, |
1541 read_only, allow_exec); | 1577 read_only, allow_exec); |
1542 } | 1578 } |
1543 | 1579 |
1544 bool os::unmap_memory(char *addr, size_t bytes) { | 1580 bool os::unmap_memory(char *addr, size_t bytes) { |
1581 MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker(); | |
1545 bool result = pd_unmap_memory(addr, bytes); | 1582 bool result = pd_unmap_memory(addr, bytes); |
1546 if (result) { | 1583 if (result) { |
1547 MemTracker::record_virtual_memory_uncommit((address)addr, bytes); | 1584 tkr.record((address)addr, bytes); |
1548 MemTracker::record_virtual_memory_release((address)addr, bytes); | 1585 } else { |
1586 tkr.discard(); | |
1549 } | 1587 } |
1550 return result; | 1588 return result; |
1551 } | 1589 } |
1552 | 1590 |
1553 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { | 1591 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { |