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_linux.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
1149
1150 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
1151
1152 result = ::close(fd);
1153 assert(result != OS_ERR, "could not close file");
1154
1155 if (mapAddress == MAP_FAILED) {
1156 if (PrintMiscellaneous && Verbose) {
1157 warning("mmap failed: %s\n", os::strerror(errno));
1158 }
1159 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1160 "Could not map PerfMemory");
1161 }
1162
1163 // it does not go through os api, the operation has to record from here
1164 MemTracker::record_virtual_memory_reserve_and_commit((address)mapAddress, size, CURRENT_PC, mtInternal);
1165
1166 *addr = mapAddress;
1167 *sizep = size;
1168
1169 if (PerfTraceMemOps) {
1170 tty->print("mapped " SIZE_FORMAT " bytes for vmid %d at "
1171 INTPTR_FORMAT "\n", size, vmid, p2i((void*)mapAddress));
1172 }
1173 }
1174
1175
1176
1177
1178 // create the PerfData memory region
1179 //
1180 // This method creates the memory region used to store performance
1181 // data for the JVM. The memory may be created in standard or
1182 // shared memory.
1183 //
1184 void PerfMemory::create_memory_region(size_t size) {
1185
1186 if (PerfDisableSharedMem) {
1187 // do not share the memory for the performance data.
1188 _start = create_standard_memory(size);
1189 }
1190 else {
1191 _start = create_shared_memory(size);
1192 if (_start == NULL) {
1193
1194 // creation of the shared memory region failed, attempt
1195 // to create a contiguous, non-shared memory region instead.
1196 //
|
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_linux.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
1150
1151 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
1152
1153 result = ::close(fd);
1154 assert(result != OS_ERR, "could not close file");
1155
1156 if (mapAddress == MAP_FAILED) {
1157 if (PrintMiscellaneous && Verbose) {
1158 warning("mmap failed: %s\n", os::strerror(errno));
1159 }
1160 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
1161 "Could not map PerfMemory");
1162 }
1163
1164 // it does not go through os api, the operation has to record from here
1165 MemTracker::record_virtual_memory_reserve_and_commit((address)mapAddress, size, CURRENT_PC, mtInternal);
1166
1167 *addr = mapAddress;
1168 *sizep = size;
1169
1170 log_debug(perf, memops)("mapped " SIZE_FORMAT " bytes for vmid %d at "
1171 INTPTR_FORMAT "\n", size, vmid, p2i((void*)mapAddress));
1172 }
1173
1174 // create the PerfData memory region
1175 //
1176 // This method creates the memory region used to store performance
1177 // data for the JVM. The memory may be created in standard or
1178 // shared memory.
1179 //
1180 void PerfMemory::create_memory_region(size_t size) {
1181
1182 if (PerfDisableSharedMem) {
1183 // do not share the memory for the performance data.
1184 _start = create_standard_memory(size);
1185 }
1186 else {
1187 _start = create_shared_memory(size);
1188 if (_start == NULL) {
1189
1190 // creation of the shared memory region failed, attempt
1191 // to create a contiguous, non-shared memory region instead.
1192 //
|