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 *
874 FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
875 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
876 "Process not found");
877 }
878
879 char* filename = get_sharedmem_filename(dirname, vmid);
880
881 // copy heap memory to resource memory. the open_sharedmem_file
882 // method below need to use the filename, but could throw an
883 // exception. using a resource array prevents the leak that
884 // would otherwise occur.
885 char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
886 strcpy(rfilename, filename);
887
888 // free the c heap resources that are no longer needed
889 if (luser != user) FREE_C_HEAP_ARRAY(char, luser, mtInternal);
890 FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
891 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
892
893 // open the shared memory file for the give vmid
894 fd = open_sharedmem_file(rfilename, file_flags, CHECK);
895 assert(fd != OS_ERR, "unexpected value");
896
897 if (*sizep == 0) {
898 size = sharedmem_filesize(fd, CHECK);
899 } else {
900 size = *sizep;
901 }
902
903 assert(size > 0, "unexpected size <= 0");
904
905 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
906
907 result = ::close(fd);
908 assert(result != OS_ERR, "could not close file");
909
910 if (mapAddress == MAP_FAILED) {
911 if (PrintMiscellaneous && Verbose) {
912 warning("mmap failed: %s\n", strerror(errno));
913 }
914 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
915 "Could not map PerfMemory");
916 }
|
1 /*
2 * Copyright (c) 2001, 2014, 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 *
874 FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
875 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
876 "Process not found");
877 }
878
879 char* filename = get_sharedmem_filename(dirname, vmid);
880
881 // copy heap memory to resource memory. the open_sharedmem_file
882 // method below need to use the filename, but could throw an
883 // exception. using a resource array prevents the leak that
884 // would otherwise occur.
885 char* rfilename = NEW_RESOURCE_ARRAY(char, strlen(filename) + 1);
886 strcpy(rfilename, filename);
887
888 // free the c heap resources that are no longer needed
889 if (luser != user) FREE_C_HEAP_ARRAY(char, luser, mtInternal);
890 FREE_C_HEAP_ARRAY(char, dirname, mtInternal);
891 FREE_C_HEAP_ARRAY(char, filename, mtInternal);
892
893 // open the shared memory file for the give vmid
894 fd = open_sharedmem_file(rfilename, file_flags, THREAD);
895
896 if (fd == OS_ERR) {
897 return;
898 }
899
900 if (HAS_PENDING_EXCEPTION) {
901 ::close(fd);
902 return;
903 }
904
905 if (*sizep == 0) {
906 size = sharedmem_filesize(fd, CHECK);
907 } else {
908 size = *sizep;
909 }
910
911 assert(size > 0, "unexpected size <= 0");
912
913 mapAddress = (char*)::mmap((char*)0, size, mmap_prot, MAP_SHARED, fd, 0);
914
915 result = ::close(fd);
916 assert(result != OS_ERR, "could not close file");
917
918 if (mapAddress == MAP_FAILED) {
919 if (PrintMiscellaneous && Verbose) {
920 warning("mmap failed: %s\n", strerror(errno));
921 }
922 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
923 "Could not map PerfMemory");
924 }
|