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 *
738 // but ignore other failures
739 RESTARTABLE(::close(fd), result);
740 assert(result != OS_ERR, "could not close file");
741
742 if (mapAddress == MAP_FAILED) {
743 if (PrintMiscellaneous && Verbose) {
744 warning("mmap failed - %s\n", strerror(errno));
745 }
746 remove_file(filename);
747 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
748 return NULL;
749 }
750
751 // save the file name for use in delete_shared_memory()
752 backing_store_file_name = filename;
753
754 // clear the shared memory region
755 (void)::memset((void*) mapAddress, 0, size);
756
757 // 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);
759 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
760
761 return mapAddress;
762 }
763
764 // release a named shared memory region
765 //
766 static void unmap_shared(char* addr, size_t bytes) {
767 os::release_memory(addr, bytes);
768 }
769
770 // create the PerfData memory region in shared memory.
771 //
772 static char* create_shared_memory(size_t size) {
773
774 // create the shared memory region.
775 return mmap_create_shared(size);
776 }
777
778 // delete the shared PerfData memory region
779 //
904 }
905
906 assert(size > 0, "unexpected size <= 0");
907
908 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
909
910 // attempt to close the file - restart if it gets interrupted,
911 // but ignore other failures
912 RESTARTABLE(::close(fd), result);
913 assert(result != OS_ERR, "could not close file");
914
915 if (mapAddress == MAP_FAILED) {
916 if (PrintMiscellaneous && Verbose) {
917 warning("mmap failed: %s\n", strerror(errno));
918 }
919 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
920 "Could not map PerfMemory");
921 }
922
923 // 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);
925 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
926
927 *addr = mapAddress;
928 *sizep = size;
929
930 if (PerfTraceMemOps) {
931 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
932 INTPTR_FORMAT "\n", size, vmid, (void*)mapAddress);
933 }
934 }
935
936
937
938
939 // create the PerfData memory region
940 //
941 // This method creates the memory region used to store performance
942 // data for the JVM. The memory may be created in standard or
943 // shared memory.
944 //
945 void PerfMemory::create_memory_region(size_t size) {
|
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 *
738 // but ignore other failures
739 RESTARTABLE(::close(fd), result);
740 assert(result != OS_ERR, "could not close file");
741
742 if (mapAddress == MAP_FAILED) {
743 if (PrintMiscellaneous && Verbose) {
744 warning("mmap failed - %s\n", strerror(errno));
745 }
746 remove_file(filename);
747 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
748 return NULL;
749 }
750
751 // save the file name for use in delete_shared_memory()
752 backing_store_file_name = filename;
753
754 // clear the shared memory region
755 (void)::memset((void*) mapAddress, 0, size);
756
757 // it does not go through os api, the operation has to record from here
758 NMTTrackOp op(NMTTrackOp::ReserveAndCommitOp);
759 op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);
760
761 return mapAddress;
762 }
763
764 // release a named shared memory region
765 //
766 static void unmap_shared(char* addr, size_t bytes) {
767 os::release_memory(addr, bytes);
768 }
769
770 // create the PerfData memory region in shared memory.
771 //
772 static char* create_shared_memory(size_t size) {
773
774 // create the shared memory region.
775 return mmap_create_shared(size);
776 }
777
778 // delete the shared PerfData memory region
779 //
904 }
905
906 assert(size > 0, "unexpected size <= 0");
907
908 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
909
910 // attempt to close the file - restart if it gets interrupted,
911 // but ignore other failures
912 RESTARTABLE(::close(fd), result);
913 assert(result != OS_ERR, "could not close file");
914
915 if (mapAddress == MAP_FAILED) {
916 if (PrintMiscellaneous && Verbose) {
917 warning("mmap failed: %s\n", strerror(errno));
918 }
919 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
920 "Could not map PerfMemory");
921 }
922
923 // it does not go through os api, the operation has to record from here
924 NMTTrackOp op(NMTTrackOp::ReserveAndCommitOp);
925 op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);
926
927 *addr = mapAddress;
928 *sizep = size;
929
930 if (PerfTraceMemOps) {
931 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
932 INTPTR_FORMAT "\n", size, vmid, (void*)mapAddress);
933 }
934 }
935
936
937
938
939 // create the PerfData memory region
940 //
941 // This method creates the memory region used to store performance
942 // data for the JVM. The memory may be created in standard or
943 // shared memory.
944 //
945 void PerfMemory::create_memory_region(size_t size) {
|