src/os/windows/vm/perfMemory_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/os/windows/vm

src/os/windows/vm/perfMemory_windows.cpp

Print this page


   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 
1706   // the file mapping object was closed in open_file_mapping()


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   NMTTrackOp op(NMTTrackOp::ReserveOp);
1502   op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);
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   NMTTrackOp op(NMTTrackOp::ReserveOp);
1685   op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);

1686 
1687   *addrp = (char*)mapAddress;
1688   *sizep = size;
1689 
1690   // File mapping object can be closed at this time without
1691   // invalidating the mapped view of the file
1692   CloseHandle(fmh);
1693 
1694   if (PerfTraceMemOps) {
1695     tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
1696                INTPTR_FORMAT "\n", size, vmid, mapAddress);
1697   }
1698 }
1699 
1700 // this method unmaps the the mapped view of the the
1701 // file mapping object.
1702 //
1703 static void remove_file_mapping(char* addr) {
1704 
1705   // the file mapping object was closed in open_file_mapping()


1818 // region specified by <address, size> will be inaccessible after
1819 // a call to this method.
1820 //
1821 // If the JVM chooses not to support the attachability feature,
1822 // this method should throw an UnsupportedOperation exception.
1823 //
1824 // This implementation utilizes named shared memory to detach
1825 // the indicated process's PerfData memory region from this
1826 // process's address space.
1827 //
1828 void PerfMemory::detach(char* addr, size_t bytes, TRAPS) {
1829 
1830   assert(addr != 0, "address sanity check");
1831   assert(bytes > 0, "capacity sanity check");
1832 
1833   if (PerfMemory::contains(addr) || PerfMemory::contains(addr + bytes - 1)) {
1834     // prevent accidental detachment of this process's PerfMemory region
1835     return;
1836   }
1837 
1838   // remove_file_mapping() does not go through os api, need to notify
1839   // NMT from here, before actually released
1840   NMTTrackOp op(NMTTrackOp::ReleaseOp);
1841   op.execute_op((address)addr, bytes);
1842   remove_file_mapping(addr);


1843 }
1844 
1845 char* PerfMemory::backing_store_filename() {
1846   return sharedmem_fileName;
1847 }
src/os/windows/vm/perfMemory_windows.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File