Mercurial > hg > truffle
annotate src/share/vm/runtime/perfMemory.cpp @ 20470:bc4ce33c0985
8049529: LogCompilation: annotate make_not_compilable with compilation level
Reviewed-by: roland, iveresov
author | vlivanov |
---|---|
date | Mon, 14 Jul 2014 03:27:21 -0700 |
parents | ce8f6bb717c9 |
children | 7848fc12602b |
rev | line source |
---|---|
0 | 1 /* |
17632
2604e2767d2c
8030955: assert(_prologue != NULL) failed: prologue pointer must be initialized
hseigel
parents:
6842
diff
changeset
|
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
470
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
470
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
470
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "memory/allocation.inline.hpp" | |
27 #include "runtime/arguments.hpp" | |
28 #include "runtime/java.hpp" | |
29 #include "runtime/mutex.hpp" | |
30 #include "runtime/mutexLocker.hpp" | |
20197
ce8f6bb717c9
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
17937
diff
changeset
|
31 #include "runtime/orderAccess.inline.hpp" |
1972 | 32 #include "runtime/os.hpp" |
33 #include "runtime/perfData.hpp" | |
34 #include "runtime/perfMemory.hpp" | |
35 #include "runtime/statSampler.hpp" | |
36 #include "utilities/globalDefinitions.hpp" | |
0 | 37 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17632
diff
changeset
|
38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17632
diff
changeset
|
39 |
434 | 40 // Prefix of performance data file. |
41 const char PERFDATA_NAME[] = "hsperfdata"; | |
42 | |
43 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating | |
44 // character will be included in the sizeof(PERFDATA_NAME) operation. | |
45 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) + | |
46 UINT_CHARS + 1; | |
47 | |
0 | 48 char* PerfMemory::_start = NULL; |
49 char* PerfMemory::_end = NULL; | |
50 char* PerfMemory::_top = NULL; | |
51 size_t PerfMemory::_capacity = 0; | |
52 jint PerfMemory::_initialized = false; | |
53 PerfDataPrologue* PerfMemory::_prologue = NULL; | |
54 | |
55 void perfMemory_init() { | |
56 | |
57 if (!UsePerfData) return; | |
58 | |
59 PerfMemory::initialize(); | |
60 } | |
61 | |
62 void perfMemory_exit() { | |
63 | |
64 if (!UsePerfData) return; | |
65 if (!PerfMemory::is_initialized()) return; | |
66 | |
67 // if the StatSampler is active, then we don't want to remove | |
68 // resources it may be dependent on. Typically, the StatSampler | |
69 // is disengaged from the watcher thread when this method is called, | |
70 // but it is not disengaged if this method is invoked during a | |
71 // VM abort. | |
72 // | |
73 if (!StatSampler::is_active()) | |
74 PerfDataManager::destroy(); | |
75 | |
76 // remove the persistent external resources, if any. this method | |
77 // does not unmap or invalidate any virtual memory allocated during | |
78 // initialization. | |
79 // | |
80 PerfMemory::destroy(); | |
81 } | |
82 | |
83 void PerfMemory::initialize() { | |
84 | |
85 if (_prologue != NULL) | |
86 // initialization already performed | |
87 return; | |
88 | |
89 size_t capacity = align_size_up(PerfDataMemorySize, | |
90 os::vm_allocation_granularity()); | |
91 | |
92 if (PerfTraceMemOps) { | |
93 tty->print("PerfDataMemorySize = " SIZE_FORMAT "," | |
94 " os::vm_allocation_granularity = " SIZE_FORMAT "," | |
95 " adjusted size = " SIZE_FORMAT "\n", | |
96 PerfDataMemorySize, | |
97 os::vm_allocation_granularity(), | |
98 capacity); | |
99 } | |
100 | |
101 // allocate PerfData memory region | |
102 create_memory_region(capacity); | |
103 | |
104 if (_start == NULL) { | |
105 | |
106 // the PerfMemory region could not be created as desired. Rather | |
107 // than terminating the JVM, we revert to creating the instrumentation | |
108 // on the C heap. When running in this mode, external monitoring | |
109 // clients cannot attach to and monitor this JVM. | |
110 // | |
111 // the warning is issued only in debug mode in order to avoid | |
112 // additional output to the stdout or stderr output streams. | |
113 // | |
114 if (PrintMiscellaneous && Verbose) { | |
115 warning("Could not create PerfData Memory region, reverting to malloc"); | |
116 } | |
117 | |
6197 | 118 _prologue = NEW_C_HEAP_OBJ(PerfDataPrologue, mtInternal); |
0 | 119 } |
120 else { | |
121 | |
122 // the PerfMemory region was created as expected. | |
123 | |
124 if (PerfTraceMemOps) { | |
125 tty->print("PerfMemory created: address = " INTPTR_FORMAT "," | |
126 " size = " SIZE_FORMAT "\n", | |
127 (void*)_start, | |
128 _capacity); | |
129 } | |
130 | |
131 _prologue = (PerfDataPrologue *)_start; | |
132 _end = _start + _capacity; | |
133 _top = _start + sizeof(PerfDataPrologue); | |
134 } | |
135 | |
136 assert(_prologue != NULL, "prologue pointer must be initialized"); | |
137 | |
138 #ifdef VM_LITTLE_ENDIAN | |
139 _prologue->magic = (jint)0xc0c0feca; | |
140 _prologue->byte_order = PERFDATA_LITTLE_ENDIAN; | |
141 #else | |
142 _prologue->magic = (jint)0xcafec0c0; | |
143 _prologue->byte_order = PERFDATA_BIG_ENDIAN; | |
144 #endif | |
145 | |
146 _prologue->major_version = PERFDATA_MAJOR_VERSION; | |
147 _prologue->minor_version = PERFDATA_MINOR_VERSION; | |
148 _prologue->accessible = 0; | |
149 | |
150 _prologue->entry_offset = sizeof(PerfDataPrologue); | |
151 _prologue->num_entries = 0; | |
152 _prologue->used = 0; | |
153 _prologue->overflow = 0; | |
154 _prologue->mod_time_stamp = 0; | |
155 | |
156 OrderAccess::release_store(&_initialized, 1); | |
157 } | |
158 | |
159 void PerfMemory::destroy() { | |
160 | |
17632
2604e2767d2c
8030955: assert(_prologue != NULL) failed: prologue pointer must be initialized
hseigel
parents:
6842
diff
changeset
|
161 if (_prologue == NULL) return; |
0 | 162 |
163 if (_start != NULL && _prologue->overflow != 0) { | |
164 | |
165 // This state indicates that the contiguous memory region exists and | |
166 // that it wasn't large enough to hold all the counters. In this case, | |
167 // we output a warning message to the user on exit if the -XX:+Verbose | |
168 // flag is set (a debug only flag). External monitoring tools can detect | |
169 // this condition by monitoring the _prologue->overflow word. | |
170 // | |
171 // There are two tunables that can help resolve this issue: | |
172 // - increase the size of the PerfMemory with -XX:PerfDataMemorySize=<n> | |
173 // - decrease the maximum string constant length with | |
174 // -XX:PerfMaxStringConstLength=<n> | |
175 // | |
176 if (PrintMiscellaneous && Verbose) { | |
177 warning("PerfMemory Overflow Occurred.\n" | |
178 "\tCapacity = " SIZE_FORMAT " bytes" | |
179 " Used = " SIZE_FORMAT " bytes" | |
180 " Overflow = " INT32_FORMAT " bytes" | |
181 "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.", | |
182 PerfMemory::capacity(), | |
183 PerfMemory::used(), | |
184 _prologue->overflow); | |
185 } | |
186 } | |
187 | |
188 if (_start != NULL) { | |
189 | |
190 // this state indicates that the contiguous memory region was successfully | |
191 // and that persistent resources may need to be cleaned up. This is | |
192 // expected to be the typical condition. | |
193 // | |
194 delete_memory_region(); | |
195 } | |
196 | |
197 _start = NULL; | |
198 _end = NULL; | |
199 _top = NULL; | |
200 _prologue = NULL; | |
201 _capacity = 0; | |
202 } | |
203 | |
204 // allocate an aligned block of memory from the PerfData memory | |
205 // region. This method assumes that the PerfData memory region | |
206 // was aligned on a double word boundary when created. | |
207 // | |
208 char* PerfMemory::alloc(size_t size) { | |
209 | |
210 if (!UsePerfData) return NULL; | |
211 | |
212 MutexLocker ml(PerfDataMemAlloc_lock); | |
213 | |
214 assert(_prologue != NULL, "called before initialization"); | |
215 | |
216 // check that there is enough memory for this request | |
217 if ((_top + size) >= _end) { | |
218 | |
219 _prologue->overflow += (jint)size; | |
220 | |
221 return NULL; | |
222 } | |
223 | |
224 char* result = _top; | |
225 | |
226 _top += size; | |
227 | |
228 assert(contains(result), "PerfData memory pointer out of range"); | |
229 | |
230 _prologue->used = (jint)used(); | |
231 _prologue->num_entries = _prologue->num_entries + 1; | |
232 | |
233 return result; | |
234 } | |
235 | |
236 void PerfMemory::mark_updated() { | |
237 if (!UsePerfData) return; | |
238 | |
239 _prologue->mod_time_stamp = os::elapsed_counter(); | |
240 } | |
241 | |
242 // Returns the complete path including the file name of performance data file. | |
243 // Caller is expected to release the allocated memory. | |
244 char* PerfMemory::get_perfdata_file_path() { | |
245 char* dest_file = NULL; | |
246 | |
247 if (PerfDataSaveFile != NULL) { | |
248 // dest_file_name stores the validated file name if file_name | |
249 // contains %p which will be replaced by pid. | |
6197 | 250 dest_file = NEW_C_HEAP_ARRAY(char, JVM_MAXPATHLEN, mtInternal); |
0 | 251 if(!Arguments::copy_expand_pid(PerfDataSaveFile, strlen(PerfDataSaveFile), |
252 dest_file, JVM_MAXPATHLEN)) { | |
6197 | 253 FREE_C_HEAP_ARRAY(char, dest_file, mtInternal); |
0 | 254 if (PrintMiscellaneous && Verbose) { |
255 warning("Invalid performance data file path name specified, "\ | |
256 "fall back to a default name"); | |
257 } | |
258 } else { | |
259 return dest_file; | |
260 } | |
261 } | |
262 // create the name of the file for retaining the instrumentation memory. | |
6197 | 263 dest_file = NEW_C_HEAP_ARRAY(char, PERFDATA_FILENAME_LEN, mtInternal); |
0 | 264 jio_snprintf(dest_file, PERFDATA_FILENAME_LEN, |
265 "%s_%d", PERFDATA_NAME, os::current_process_id()); | |
266 | |
267 return dest_file; | |
268 } |