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 *
753 // but ignore other failures
754 RESTARTABLE(::close(fd), result);
755 assert(result != OS_ERR, "could not close file");
756
757 if (mapAddress == MAP_FAILED) {
758 if (PrintMiscellaneous && Verbose) {
759 warning("mmap failed - %s\n", strerror(errno));
760 }
761 remove_file(filename);
762 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
763 return NULL;
764 }
765
766 // save the file name for use in delete_shared_memory()
767 backing_store_file_name = filename;
768
769 // clear the shared memory region
770 (void)::memset((void*) mapAddress, 0, size);
771
772 // it does not go through os api, the operation has to record from here
773 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC);
774 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
775
776 return mapAddress;
777 }
778
779 // release a named shared memory region
780 //
781 static void unmap_shared(char* addr, size_t bytes) {
782 os::release_memory(addr, bytes);
783 }
784
785 // create the PerfData memory region in shared memory.
786 //
787 static char* create_shared_memory(size_t size) {
788
789 // create the shared memory region.
790 return mmap_create_shared(size);
791 }
792
793 // delete the shared PerfData memory region
794 //
919 }
920
921 assert(size > 0, "unexpected size <= 0");
922
923 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
924
925 // attempt to close the file - restart if it gets interrupted,
926 // but ignore other failures
927 RESTARTABLE(::close(fd), result);
928 assert(result != OS_ERR, "could not close file");
929
930 if (mapAddress == MAP_FAILED) {
931 if (PrintMiscellaneous && Verbose) {
932 warning("mmap failed: %s\n", strerror(errno));
933 }
934 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
935 "Could not map PerfMemory");
936 }
937
938 // it does not go through os api, the operation has to record from here
939 MemTracker::record_virtual_memory_reserve((address)mapAddress, size, CURRENT_PC);
940 MemTracker::record_virtual_memory_type((address)mapAddress, mtInternal);
941
942 *addr = mapAddress;
943 *sizep = size;
944
945 if (PerfTraceMemOps) {
946 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
947 INTPTR_FORMAT "\n", size, vmid, (void*)mapAddress);
948 }
949 }
950
951
952
953
954 // create the PerfData memory region
955 //
956 // This method creates the memory region used to store performance
957 // data for the JVM. The memory may be created in standard or
958 // shared memory.
959 //
960 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 *
753 // but ignore other failures
754 RESTARTABLE(::close(fd), result);
755 assert(result != OS_ERR, "could not close file");
756
757 if (mapAddress == MAP_FAILED) {
758 if (PrintMiscellaneous && Verbose) {
759 warning("mmap failed - %s\n", strerror(errno));
760 }
761 remove_file(filename);
762 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
763 return NULL;
764 }
765
766 // save the file name for use in delete_shared_memory()
767 backing_store_file_name = filename;
768
769 // clear the shared memory region
770 (void)::memset((void*) mapAddress, 0, size);
771
772 // it does not go through os api, the operation has to record from here
773 NMTTrackOp op(NMTTrackOp::ReserveOp);
774 op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);
775
776 return mapAddress;
777 }
778
779 // release a named shared memory region
780 //
781 static void unmap_shared(char* addr, size_t bytes) {
782 os::release_memory(addr, bytes);
783 }
784
785 // create the PerfData memory region in shared memory.
786 //
787 static char* create_shared_memory(size_t size) {
788
789 // create the shared memory region.
790 return mmap_create_shared(size);
791 }
792
793 // delete the shared PerfData memory region
794 //
919 }
920
921 assert(size > 0, "unexpected size <= 0");
922
923 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
924
925 // attempt to close the file - restart if it gets interrupted,
926 // but ignore other failures
927 RESTARTABLE(::close(fd), result);
928 assert(result != OS_ERR, "could not close file");
929
930 if (mapAddress == MAP_FAILED) {
931 if (PrintMiscellaneous && Verbose) {
932 warning("mmap failed: %s\n", strerror(errno));
933 }
934 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
935 "Could not map PerfMemory");
936 }
937
938 // it does not go through os api, the operation has to record from here
939 NMTTrackOp op(NMTTrackOp::ReserveOp);
940 op.execute_op((address)mapAddress, size, mtInternal, CURRENT_PC);
941
942 *addr = mapAddress;
943 *sizep = size;
944
945 if (PerfTraceMemOps) {
946 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
947 INTPTR_FORMAT "\n", size, vmid, (void*)mapAddress);
948 }
949 }
950
951
952
953
954 // create the PerfData memory region
955 //
956 // This method creates the memory region used to store performance
957 // data for the JVM. The memory may be created in standard or
958 // shared memory.
959 //
960 void PerfMemory::create_memory_region(size_t size) {
|