1 /*
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1481 mapAddress = MapViewOfFile(
1482 sharedmem_fileMapHandle, /* HANDLE = file mapping object */
1483 FILE_MAP_ALL_ACCESS, /* DWORD access flags */
1484 0, /* DWORD High word of offset */
1485 0, /* DWORD Low word of offset */
1486 (DWORD)size); /* DWORD Number of bytes to map */
1487
1488 if (mapAddress == NULL) {
1489 if (PrintMiscellaneous && Verbose) {
1490 warning("MapViewOfFile failed, lasterror = %d\n", GetLastError());
1491 }
1492 CloseHandle(sharedmem_fileMapHandle);
1493 sharedmem_fileMapHandle = NULL;
1494 return NULL;
1495 }
1496
1497 // clear the shared memory region
1498 (void)memset(mapAddress, '\0', size);
1499
1500 // it does not go through os api, the operation has to record from here
1501 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC);
1502 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
1503
1504 return (char*) mapAddress;
1505 }
1506
1507 // this method deletes the file mapping object.
1508 //
1509 static void delete_file_mapping(char* addr, size_t size) {
1510
1511 // cleanup the persistent shared memory resources. since DestroyJavaVM does
1512 // not support unloading of the JVM, unmapping of the memory resource is not
1513 // performed. The memory will be reclaimed by the OS upon termination of all
1514 // processes mapping the resource. The file mapping handle and the file
1515 // handle are closed here to expedite the remove of the file by the OS. The
1516 // file is not removed directly because it was created with
1517 // FILE_FLAG_DELETE_ON_CLOSE semantics and any attempt to remove it would
1518 // be unsuccessful.
1519
1520 // close the fileMapHandle. the file mapping will still be retained
1521 // by the OS as long as any other JVM processes has an open file mapping
1522 // handle or a mapped view of the file.
1664 assert(fmh != INVALID_HANDLE_VALUE, "unexpected handle value");
1665
1666 // map the entire file into the address space
1667 mapAddress = MapViewOfFile(
1668 fmh, /* HANDLE Handle of file mapping object */
1669 mv_access, /* DWORD access flags */
1670 0, /* DWORD High word of offset */
1671 0, /* DWORD Low word of offset */
1672 size); /* DWORD Number of bytes to map */
1673
1674 if (mapAddress == NULL) {
1675 if (PrintMiscellaneous && Verbose) {
1676 warning("MapViewOfFile failed, lasterror = %d\n", GetLastError());
1677 }
1678 CloseHandle(fmh);
1679 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1680 "Could not map PerfMemory");
1681 }
1682
1683 // it does not go through os api, the operation has to record from here
1684 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC);
1685 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
1686
1687
1688 *addrp = (char*)mapAddress;
1689 *sizep = size;
1690
1691 // File mapping object can be closed at this time without
1692 // invalidating the mapped view of the file
1693 CloseHandle(fmh);
1694
1695 if (PerfTraceMemOps) {
1696 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
1697 INTPTR_FORMAT "\n", size, vmid, mapAddress);
1698 }
1699 }
1700
1701 // this method unmaps the the mapped view of the the
1702 // file mapping object.
1703 //
1704 static void remove_file_mapping(char* addr) {
1705
1819 // region specified by <address, size> will be inaccessible after
1820 // a call to this method.
1821 //
1822 // If the JVM chooses not to support the attachability feature,
1823 // this method should throw an UnsupportedOperation exception.
1824 //
1825 // This implementation utilizes named shared memory to detach
1826 // the indicated process's PerfData memory region from this
1827 // process's address space.
1828 //
1829 void PerfMemory::detach(char* addr, size_t bytes, TRAPS) {
1830
1831 assert(addr != 0, "address sanity check");
1832 assert(bytes > 0, "capacity sanity check");
1833
1834 if (PerfMemory::contains(addr) || PerfMemory::contains(addr + bytes - 1)) {
1835 // prevent accidental detachment of this process's PerfMemory region
1836 return;
1837 }
1838
1839 remove_file_mapping(addr);
1840 // it does not go through os api, the operation has to record from here
1841 MemTracker::record_virtual_memory_release((address)addr, bytes);
1842 }
1843
1844 char* PerfMemory::backing_store_filename() {
1845 return sharedmem_fileName;
1846 }
|
1 /*
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.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1481 mapAddress = MapViewOfFile(
1482 sharedmem_fileMapHandle, /* HANDLE = file mapping object */
1483 FILE_MAP_ALL_ACCESS, /* DWORD access flags */
1484 0, /* DWORD High word of offset */
1485 0, /* DWORD Low word of offset */
1486 (DWORD)size); /* DWORD Number of bytes to map */
1487
1488 if (mapAddress == NULL) {
1489 if (PrintMiscellaneous && Verbose) {
1490 warning("MapViewOfFile failed, lasterror = %d\n", GetLastError());
1491 }
1492 CloseHandle(sharedmem_fileMapHandle);
1493 sharedmem_fileMapHandle = NULL;
1494 return NULL;
1495 }
1496
1497 // clear the shared memory region
1498 (void)memset(mapAddress, '\0', size);
1499
1500 // it does not go through os api, the operation has to record from here
1501 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, mtInternal, CURRENT_PC);
1502
1503 return (char*) mapAddress;
1504 }
1505
1506 // this method deletes the file mapping object.
1507 //
1508 static void delete_file_mapping(char* addr, size_t size) {
1509
1510 // cleanup the persistent shared memory resources. since DestroyJavaVM does
1511 // not support unloading of the JVM, unmapping of the memory resource is not
1512 // performed. The memory will be reclaimed by the OS upon termination of all
1513 // processes mapping the resource. The file mapping handle and the file
1514 // handle are closed here to expedite the remove of the file by the OS. The
1515 // file is not removed directly because it was created with
1516 // FILE_FLAG_DELETE_ON_CLOSE semantics and any attempt to remove it would
1517 // be unsuccessful.
1518
1519 // close the fileMapHandle. the file mapping will still be retained
1520 // by the OS as long as any other JVM processes has an open file mapping
1521 // handle or a mapped view of the file.
1663 assert(fmh != INVALID_HANDLE_VALUE, "unexpected handle value");
1664
1665 // map the entire file into the address space
1666 mapAddress = MapViewOfFile(
1667 fmh, /* HANDLE Handle of file mapping object */
1668 mv_access, /* DWORD access flags */
1669 0, /* DWORD High word of offset */
1670 0, /* DWORD Low word of offset */
1671 size); /* DWORD Number of bytes to map */
1672
1673 if (mapAddress == NULL) {
1674 if (PrintMiscellaneous && Verbose) {
1675 warning("MapViewOfFile failed, lasterror = %d\n", GetLastError());
1676 }
1677 CloseHandle(fmh);
1678 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1679 "Could not map PerfMemory");
1680 }
1681
1682 // it does not go through os api, the operation has to record from here
1683 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, mtInternal, CURRENT_PC);
1684
1685
1686 *addrp = (char*)mapAddress;
1687 *sizep = size;
1688
1689 // File mapping object can be closed at this time without
1690 // invalidating the mapped view of the file
1691 CloseHandle(fmh);
1692
1693 if (PerfTraceMemOps) {
1694 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
1695 INTPTR_FORMAT "\n", size, vmid, mapAddress);
1696 }
1697 }
1698
1699 // this method unmaps the the mapped view of the the
1700 // file mapping object.
1701 //
1702 static void remove_file_mapping(char* addr) {
1703
1817 // region specified by <address, size> will be inaccessible after
1818 // a call to this method.
1819 //
1820 // If the JVM chooses not to support the attachability feature,
1821 // this method should throw an UnsupportedOperation exception.
1822 //
1823 // This implementation utilizes named shared memory to detach
1824 // the indicated process's PerfData memory region from this
1825 // process's address space.
1826 //
1827 void PerfMemory::detach(char* addr, size_t bytes, TRAPS) {
1828
1829 assert(addr != 0, "address sanity check");
1830 assert(bytes > 0, "capacity sanity check");
1831
1832 if (PerfMemory::contains(addr) || PerfMemory::contains(addr + bytes - 1)) {
1833 // prevent accidental detachment of this process's PerfMemory region
1834 return;
1835 }
1836
1837 MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
1838 remove_file_mapping(addr);
1839 // it does not go through os api, the operation has to record from here
1840 tkr.record((address)addr, bytes);
1841 }
1842
1843 char* PerfMemory::backing_store_filename() {
1844 return sharedmem_fileName;
1845 }
|