1 /*
2 * Copyright (c) 2001, 2016, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "memory/allocation.inline.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "os_bsd.inline.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/os.hpp"
33 #include "runtime/perfMemory.hpp"
34 #include "services/memTracker.hpp"
35 #include "utilities/exceptions.hpp"
36
37 // put OS-includes here
38 # include <sys/types.h>
39 # include <sys/mman.h>
40 # include <errno.h>
41 # include <stdio.h>
42 # include <unistd.h>
43 # include <sys/stat.h>
44 # include <signal.h>
45 # include <pwd.h>
46
1133
1134 // attempt to close the file - restart if it gets interrupted,
1135 // but ignore other failures
1136 result = ::close(fd);
1137 assert(result != OS_ERR, "could not close file");
1138
1139 if (mapAddress == MAP_FAILED) {
1140 if (PrintMiscellaneous && Verbose) {
1141 warning("mmap failed: %s\n", os::strerror(errno));
1142 }
1143 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1144 "Could not map PerfMemory");
1145 }
1146
1147 // it does not go through os api, the operation has to record from here
1148 MemTracker::record_virtual_memory_reserve_and_commit((address)mapAddress, size, CURRENT_PC, mtInternal);
1149
1150 *addr = mapAddress;
1151 *sizep = size;
1152
1153 if (PerfTraceMemOps) {
1154 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
1155 INTPTR_FORMAT "\n", size, vmid, p2i((void*)mapAddress));
1156 }
1157 }
1158
1159
1160
1161
1162 // create the PerfData memory region
1163 //
1164 // This method creates the memory region used to store performance
1165 // data for the JVM. The memory may be created in standard or
1166 // shared memory.
1167 //
1168 void PerfMemory::create_memory_region(size_t size) {
1169
1170 if (PerfDisableSharedMem) {
1171 // do not share the memory for the performance data.
1172 _start = create_standard_memory(size);
1173 }
1174 else {
1175 _start = create_shared_memory(size);
1176 if (_start == NULL) {
1177
1178 // creation of the shared memory region failed, attempt
1179 // to create a contiguous, non-shared memory region instead.
1180 //
|
1 /*
2 * Copyright (c) 2001, 2017, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "logging/log.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "oops/oop.inline.hpp"
31 #include "os_bsd.inline.hpp"
32 #include "runtime/handles.inline.hpp"
33 #include "runtime/os.hpp"
34 #include "runtime/perfMemory.hpp"
35 #include "services/memTracker.hpp"
36 #include "utilities/exceptions.hpp"
37
38 // put OS-includes here
39 # include <sys/types.h>
40 # include <sys/mman.h>
41 # include <errno.h>
42 # include <stdio.h>
43 # include <unistd.h>
44 # include <sys/stat.h>
45 # include <signal.h>
46 # include <pwd.h>
47
1134
1135 // attempt to close the file - restart if it gets interrupted,
1136 // but ignore other failures
1137 result = ::close(fd);
1138 assert(result != OS_ERR, "could not close file");
1139
1140 if (mapAddress == MAP_FAILED) {
1141 if (PrintMiscellaneous && Verbose) {
1142 warning("mmap failed: %s\n", os::strerror(errno));
1143 }
1144 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1145 "Could not map PerfMemory");
1146 }
1147
1148 // it does not go through os api, the operation has to record from here
1149 MemTracker::record_virtual_memory_reserve_and_commit((address)mapAddress, size, CURRENT_PC, mtInternal);
1150
1151 *addr = mapAddress;
1152 *sizep = size;
1153
1154 log_debug(perf, memops)("mapped " SIZE_FORMAT " bytes for vmid %d at "
1155 INTPTR_FORMAT "\n", size, vmid, p2i((void*)mapAddress));
1156 }
1157
1158 // create the PerfData memory region
1159 //
1160 // This method creates the memory region used to store performance
1161 // data for the JVM. The memory may be created in standard or
1162 // shared memory.
1163 //
1164 void PerfMemory::create_memory_region(size_t size) {
1165
1166 if (PerfDisableSharedMem) {
1167 // do not share the memory for the performance data.
1168 _start = create_standard_memory(size);
1169 }
1170 else {
1171 _start = create_shared_memory(size);
1172 if (_start == NULL) {
1173
1174 // creation of the shared memory region failed, attempt
1175 // to create a contiguous, non-shared memory region instead.
1176 //
|