src/os/bsd/vm/perfMemory_bsd.cpp

changeset 6443
f4f6ae481e1a
parent 5272
1f4355cee9a2
child 6680
78bbf4d43a14
equal deleted inserted replaced
6442:b5c8a61d7fa0 6443:f4f6ae481e1a
1 /* 1 /*
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2013, 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.
58 if (mapAddress == NULL) { 58 if (mapAddress == NULL) {
59 return NULL; 59 return NULL;
60 } 60 }
61 61
62 // commit memory 62 // commit memory
63 if (!os::commit_memory(mapAddress, size)) { 63 if (!os::commit_memory(mapAddress, size, !ExecMem)) {
64 if (PrintMiscellaneous && Verbose) { 64 if (PrintMiscellaneous && Verbose) {
65 warning("Could not commit PerfData memory\n"); 65 warning("Could not commit PerfData memory\n");
66 } 66 }
67 os::release_memory(mapAddress, size); 67 os::release_memory(mapAddress, size);
68 return NULL; 68 return NULL;
118 118
119 remaining -= (size_t)result; 119 remaining -= (size_t)result;
120 addr += result; 120 addr += result;
121 } 121 }
122 122
123 RESTARTABLE(::close(fd), result); 123 result = ::close(fd);
124 if (PrintMiscellaneous && Verbose) { 124 if (PrintMiscellaneous && Verbose) {
125 if (result == OS_ERR) { 125 if (result == OS_ERR) {
126 warning("Could not close %s: %s\n", destfile, strerror(errno)); 126 warning("Could not close %s: %s\n", destfile, strerror(errno));
127 } 127 }
128 } 128 }
630 RESTARTABLE(::ftruncate(fd, (off_t)size), result); 630 RESTARTABLE(::ftruncate(fd, (off_t)size), result);
631 if (result == OS_ERR) { 631 if (result == OS_ERR) {
632 if (PrintMiscellaneous && Verbose) { 632 if (PrintMiscellaneous && Verbose) {
633 warning("could not set shared memory file size: %s\n", strerror(errno)); 633 warning("could not set shared memory file size: %s\n", strerror(errno));
634 } 634 }
635 RESTARTABLE(::close(fd), result); 635 ::close(fd);
636 return -1; 636 return -1;
637 } 637 }
638 638
639 // Verify that we have enough disk space for this file. 639 // Verify that we have enough disk space for this file.
640 // We'll get random SIGBUS crashes on memory accesses if 640 // We'll get random SIGBUS crashes on memory accesses if
654 } 654 }
655 655
656 if (result != -1) { 656 if (result != -1) {
657 return fd; 657 return fd;
658 } else { 658 } else {
659 RESTARTABLE(::close(fd), result); 659 ::close(fd);
660 return -1; 660 return -1;
661 } 661 }
662 } 662 }
663 663
664 // open the shared memory file for the given user and vmid. returns 664 // open the shared memory file for the given user and vmid. returns
732 return NULL; 732 return NULL;
733 } 733 }
734 734
735 mapAddress = (char*)::mmap((char*)0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 735 mapAddress = (char*)::mmap((char*)0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
736 736
737 // attempt to close the file - restart it if it was interrupted, 737 result = ::close(fd);
738 // but ignore other failures
739 RESTARTABLE(::close(fd), result);
740 assert(result != OS_ERR, "could not close file"); 738 assert(result != OS_ERR, "could not close file");
741 739
742 if (mapAddress == MAP_FAILED) { 740 if (mapAddress == MAP_FAILED) {
743 if (PrintMiscellaneous && Verbose) { 741 if (PrintMiscellaneous && Verbose) {
744 warning("mmap failed - %s\n", strerror(errno)); 742 warning("mmap failed - %s\n", strerror(errno));
753 751
754 // clear the shared memory region 752 // clear the shared memory region
755 (void)::memset((void*) mapAddress, 0, size); 753 (void)::memset((void*) mapAddress, 0, size);
756 754
757 // it does not go through os api, the operation has to record from here 755 // it does not go through os api, the operation has to record from here
758 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC); 756 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, mtInternal, CURRENT_PC);
759 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
760 757
761 return mapAddress; 758 return mapAddress;
762 } 759 }
763 760
764 // release a named shared memory region 761 // release a named shared memory region
907 904
908 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0); 905 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
909 906
910 // attempt to close the file - restart if it gets interrupted, 907 // attempt to close the file - restart if it gets interrupted,
911 // but ignore other failures 908 // but ignore other failures
912 RESTARTABLE(::close(fd), result); 909 result = ::close(fd);
913 assert(result != OS_ERR, "could not close file"); 910 assert(result != OS_ERR, "could not close file");
914 911
915 if (mapAddress == MAP_FAILED) { 912 if (mapAddress == MAP_FAILED) {
916 if (PrintMiscellaneous && Verbose) { 913 if (PrintMiscellaneous && Verbose) {
917 warning("mmap failed: %s\n", strerror(errno)); 914 warning("mmap failed: %s\n", strerror(errno));
919 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), 916 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
920 "Could not map PerfMemory"); 917 "Could not map PerfMemory");
921 } 918 }
922 919
923 // it does not go through os api, the operation has to record from here 920 // it does not go through os api, the operation has to record from here
924 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC); 921 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, mtInternal, CURRENT_PC);
925 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
926 922
927 *addr = mapAddress; 923 *addr = mapAddress;
928 *sizep = size; 924 *sizep = size;
929 925
930 if (PerfTraceMemOps) { 926 if (PerfTraceMemOps) {

mercurial