author | vlivanov |
Mon, 15 Feb 2016 20:26:02 +0300 | |
changeset 36074 | 11263906664c |
parent 33977 | a27f0d8a7861 |
child 36508 | 5f9eee6b383b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
22551
diff
changeset
|
2 |
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "classfile/vmSymbols.hpp" |
|
28 |
#include "memory/allocation.inline.hpp" |
|
29 |
#include "memory/resourceArea.hpp" |
|
30 |
#include "oops/oop.inline.hpp" |
|
31 |
#include "runtime/arguments.hpp" |
|
32 |
#include "runtime/java.hpp" |
|
33 |
#include "runtime/javaCalls.hpp" |
|
34 |
#include "runtime/os.hpp" |
|
35 |
#include "runtime/statSampler.hpp" |
|
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
22551
diff
changeset
|
36 |
#include "runtime/vm_version.hpp" |
1 | 37 |
|
38 |
// -------------------------------------------------------- |
|
39 |
// StatSamplerTask |
|
40 |
||
41 |
class StatSamplerTask : public PeriodicTask { |
|
42 |
public: |
|
43 |
StatSamplerTask(int interval_time) : PeriodicTask(interval_time) {} |
|
44 |
void task() { StatSampler::collect_sample(); } |
|
45 |
}; |
|
46 |
||
47 |
||
48 |
//---------------------------------------------------------- |
|
49 |
// Implementation of StatSampler |
|
50 |
||
51 |
StatSamplerTask* StatSampler::_task = NULL; |
|
52 |
PerfDataList* StatSampler::_sampled = NULL; |
|
53 |
||
54 |
/* |
|
55 |
* the initialize method is called from the engage() method |
|
56 |
* and is responsible for initializing various global variables. |
|
57 |
*/ |
|
58 |
void StatSampler::initialize() { |
|
59 |
||
60 |
if (!UsePerfData) return; |
|
61 |
||
62 |
// create performance data that could not be created prior |
|
63 |
// to vm_init_globals() or otherwise have no logical home. |
|
64 |
||
65 |
create_misc_perfdata(); |
|
66 |
||
67 |
// get copy of the sampled list |
|
68 |
_sampled = PerfDataManager::sampled(); |
|
69 |
||
70 |
} |
|
71 |
||
72 |
/* |
|
73 |
* The engage() method is called at initialization time via |
|
74 |
* Thread::create_vm() to initialize the StatSampler and |
|
75 |
* register it with the WatcherThread as a periodic task. |
|
76 |
*/ |
|
77 |
void StatSampler::engage() { |
|
78 |
||
79 |
if (!UsePerfData) return; |
|
80 |
||
81 |
if (!is_active()) { |
|
82 |
||
83 |
initialize(); |
|
84 |
||
85 |
// start up the periodic task |
|
86 |
_task = new StatSamplerTask(PerfDataSamplingInterval); |
|
87 |
_task->enroll(); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
||
92 |
/* |
|
93 |
* the disengage() method is responsible for deactivating the periodic |
|
94 |
* task and, if logging was enabled, for logging the final sample. This |
|
95 |
* method is called from before_exit() in java.cpp and is only called |
|
96 |
* after the WatcherThread has been stopped. |
|
97 |
*/ |
|
98 |
void StatSampler::disengage() { |
|
99 |
||
100 |
if (!UsePerfData) return; |
|
101 |
||
102 |
if (!is_active()) |
|
103 |
return; |
|
104 |
||
105 |
// remove StatSamplerTask |
|
106 |
_task->disenroll(); |
|
107 |
delete _task; |
|
108 |
_task = NULL; |
|
109 |
||
110 |
// force a final sample |
|
111 |
sample_data(_sampled); |
|
112 |
} |
|
113 |
||
114 |
/* |
|
115 |
* the destroy method is responsible for releasing any resources used by |
|
116 |
* the StatSampler prior to shutdown of the VM. this method is called from |
|
117 |
* before_exit() in java.cpp and is only called after the WatcherThread |
|
118 |
* has stopped. |
|
119 |
*/ |
|
120 |
void StatSampler::destroy() { |
|
121 |
||
122 |
if (!UsePerfData) return; |
|
123 |
||
124 |
if (_sampled != NULL) { |
|
125 |
delete(_sampled); |
|
126 |
_sampled = NULL; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
/* |
|
131 |
* The sample_data() method is responsible for sampling the |
|
132 |
* the data value for each PerfData instance in the given list. |
|
133 |
*/ |
|
134 |
void StatSampler::sample_data(PerfDataList* list) { |
|
135 |
||
136 |
assert(list != NULL, "null list unexpected"); |
|
137 |
||
138 |
for (int index = 0; index < list->length(); index++) { |
|
139 |
PerfData* item = list->at(index); |
|
140 |
item->sample(); |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
/* |
|
145 |
* the collect_sample() method is the method invoked by the |
|
146 |
* WatcherThread via the PeriodicTask::task() method. This method |
|
147 |
* is responsible for collecting data samples from sampled |
|
148 |
* PerfData instances every PerfDataSamplingInterval milliseconds. |
|
149 |
* It is also responsible for logging the requested set of |
|
150 |
* PerfData instances every _sample_count milliseconds. While |
|
151 |
* logging data, it will output a column header after every _print_header |
|
152 |
* rows of data have been logged. |
|
153 |
*/ |
|
154 |
void StatSampler::collect_sample() { |
|
155 |
||
156 |
// future - check for new PerfData objects. PerfData objects might |
|
157 |
// get added to the PerfDataManager lists after we have already |
|
158 |
// built our local copies. |
|
159 |
// |
|
160 |
// if (PerfDataManager::count() > previous) { |
|
161 |
// // get a new copy of the sampled list |
|
162 |
// if (_sampled != NULL) { |
|
163 |
// delete(_sampled); |
|
164 |
// _sampled = NULL; |
|
165 |
// } |
|
166 |
// _sampled = PerfDataManager::sampled(); |
|
167 |
// } |
|
168 |
||
169 |
assert(_sampled != NULL, "list not initialized"); |
|
170 |
||
171 |
sample_data(_sampled); |
|
172 |
} |
|
173 |
||
174 |
/* |
|
175 |
* method to upcall into Java to return the value of the specified |
|
176 |
* property as a utf8 string, or NULL if does not exist. The caller |
|
177 |
* is responsible for setting a ResourceMark for proper cleanup of |
|
178 |
* the utf8 strings. |
|
179 |
*/ |
|
180 |
const char* StatSampler::get_system_property(const char* name, TRAPS) { |
|
181 |
||
182 |
// setup the arguments to getProperty |
|
183 |
Handle key_str = java_lang_String::create_from_str(name, CHECK_NULL); |
|
184 |
||
185 |
// return value |
|
186 |
JavaValue result(T_OBJECT); |
|
187 |
||
188 |
// public static String getProperty(String key, String def); |
|
189 |
JavaCalls::call_static(&result, |
|
4571 | 190 |
KlassHandle(THREAD, SystemDictionary::System_klass()), |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
191 |
vmSymbols::getProperty_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
192 |
vmSymbols::string_string_signature(), |
1 | 193 |
key_str, |
194 |
CHECK_NULL); |
|
195 |
||
196 |
oop value_oop = (oop)result.get_jobject(); |
|
197 |
if (value_oop == NULL) { |
|
198 |
return NULL; |
|
199 |
} |
|
200 |
||
201 |
// convert Java String to utf8 string |
|
202 |
char* value = java_lang_String::as_utf8_string(value_oop); |
|
203 |
||
204 |
return value; |
|
205 |
} |
|
206 |
||
207 |
/* |
|
208 |
* The list of System Properties that have corresponding PerfData |
|
209 |
* string instrumentation created by retrieving the named property's |
|
210 |
* value from System.getProperty() and unconditionally creating a |
|
22551 | 211 |
* PerfStringConstant object initialized to the retrieved value. This |
212 |
* is not an exhaustive list of Java properties with corresponding string |
|
1 | 213 |
* instrumentation as the create_system_property_instrumentation() method |
214 |
* creates other property based instrumentation conditionally. |
|
215 |
*/ |
|
216 |
||
217 |
// stable interface, supported counters |
|
218 |
static const char* property_counters_ss[] = { |
|
219 |
"java.vm.specification.version", |
|
220 |
"java.vm.specification.name", |
|
221 |
"java.vm.specification.vendor", |
|
222 |
"java.vm.version", |
|
223 |
"java.vm.name", |
|
224 |
"java.vm.vendor", |
|
225 |
"java.vm.info", |
|
33977
a27f0d8a7861
8139986: Store debug level in java.vm.debug and conditionally print in "java -version"
amurillo
parents:
27562
diff
changeset
|
226 |
"jdk.debug", |
1 | 227 |
"java.library.path", |
228 |
"java.class.path", |
|
987
843415f667e6
6625846: Export system property java.version via jvmstat
thurka
parents:
1
diff
changeset
|
229 |
"java.version", |
1 | 230 |
"java.home", |
231 |
NULL |
|
232 |
}; |
|
233 |
||
234 |
// unstable interface, supported counters |
|
235 |
static const char* property_counters_us[] = { |
|
236 |
NULL |
|
237 |
}; |
|
238 |
||
239 |
// unstable interface, unsupported counters |
|
240 |
static const char* property_counters_uu[] = { |
|
241 |
"sun.boot.class.path", |
|
242 |
"sun.boot.library.path", |
|
243 |
NULL |
|
244 |
}; |
|
245 |
||
246 |
typedef struct { |
|
247 |
const char** property_list; |
|
248 |
CounterNS name_space; |
|
249 |
} PropertyCounters; |
|
250 |
||
251 |
static PropertyCounters property_counters[] = { |
|
252 |
{ property_counters_ss, JAVA_PROPERTY }, |
|
253 |
{ property_counters_us, COM_PROPERTY }, |
|
254 |
{ property_counters_uu, SUN_PROPERTY }, |
|
255 |
{ NULL, SUN_PROPERTY } |
|
256 |
}; |
|
257 |
||
258 |
||
259 |
/* |
|
260 |
* Method to create PerfData string instruments that contain the values |
|
261 |
* of various system properties. String instruments are created for each |
|
262 |
* property specified in the property lists provided in property_counters[]. |
|
263 |
* Property counters have a counter name space prefix prepended to the |
|
264 |
* property name as indicated in property_counters[]. |
|
265 |
*/ |
|
266 |
void StatSampler::create_system_property_instrumentation(TRAPS) { |
|
267 |
||
268 |
ResourceMark rm; |
|
269 |
||
270 |
for (int i = 0; property_counters[i].property_list != NULL; i++) { |
|
271 |
||
272 |
for (int j = 0; property_counters[i].property_list[j] != NULL; j++) { |
|
273 |
||
274 |
const char* property_name = property_counters[i].property_list[j]; |
|
275 |
assert(property_name != NULL, "property name should not be NULL"); |
|
276 |
||
277 |
const char* value = get_system_property(property_name, CHECK); |
|
278 |
||
279 |
// the property must exist |
|
280 |
assert(value != NULL, "property name should be valid"); |
|
281 |
||
282 |
if (value != NULL) { |
|
283 |
// create the property counter |
|
284 |
PerfDataManager::create_string_constant(property_counters[i].name_space, |
|
285 |
property_name, value, CHECK); |
|
286 |
} |
|
287 |
} |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
/* |
|
292 |
* The create_misc_perfdata() method provides a place to create |
|
293 |
* PerfData instances that would otherwise have no better place |
|
294 |
* to exist. |
|
295 |
*/ |
|
296 |
void StatSampler::create_misc_perfdata() { |
|
297 |
||
298 |
ResourceMark rm; |
|
299 |
EXCEPTION_MARK; |
|
300 |
||
301 |
// numeric constants |
|
302 |
||
303 |
// frequency of the native high resolution timer |
|
304 |
PerfDataManager::create_constant(SUN_OS, "hrt.frequency", |
|
305 |
PerfData::U_Hertz, os::elapsed_frequency(), |
|
306 |
CHECK); |
|
307 |
||
308 |
// string constants |
|
309 |
||
310 |
// create string instrumentation for various Java properties. |
|
311 |
create_system_property_instrumentation(CHECK); |
|
312 |
||
22551 | 313 |
// HotSpot flags (from .hotspotrc) and args (from command line) |
1 | 314 |
// |
315 |
PerfDataManager::create_string_constant(JAVA_RT, "vmFlags", |
|
316 |
Arguments::jvm_flags(), CHECK); |
|
317 |
PerfDataManager::create_string_constant(JAVA_RT, "vmArgs", |
|
318 |
Arguments::jvm_args(), CHECK); |
|
319 |
||
320 |
// java class name/jar file and arguments to main class |
|
321 |
// note: name is cooridnated with launcher and Arguments.cpp |
|
322 |
PerfDataManager::create_string_constant(SUN_RT, "javaCommand", |
|
323 |
Arguments::java_command(), CHECK); |
|
324 |
||
325 |
// the Java VM Internal version string |
|
326 |
PerfDataManager::create_string_constant(SUN_RT, "internalVersion", |
|
327 |
VM_Version::internal_vm_info_string(), |
|
328 |
CHECK); |
|
329 |
||
330 |
// create sampled instrumentation objects |
|
331 |
create_sampled_perfdata(); |
|
332 |
} |
|
333 |
||
334 |
/* |
|
335 |
* helper class to provide for sampling of the elapsed_counter value |
|
336 |
* maintained in the OS class. |
|
337 |
*/ |
|
338 |
class HighResTimeSampler : public PerfSampleHelper { |
|
339 |
public: |
|
340 |
jlong take_sample() { return os::elapsed_counter(); } |
|
341 |
}; |
|
342 |
||
343 |
/* |
|
344 |
* the create_sampled_perdata() method provides a place to instantiate |
|
345 |
* sampled PerfData instances that would otherwise have no better place |
|
346 |
* to exist. |
|
347 |
*/ |
|
348 |
void StatSampler::create_sampled_perfdata() { |
|
349 |
||
350 |
EXCEPTION_MARK; |
|
351 |
||
352 |
// setup sampling of the elapsed time counter maintained in the |
|
353 |
// the os class. This counter can be used as either a time stamp |
|
354 |
// for each logged entry or as a liveness indicator for the VM. |
|
355 |
PerfSampleHelper* psh = new HighResTimeSampler(); |
|
356 |
PerfDataManager::create_counter(SUN_OS, "hrt.ticks", |
|
357 |
PerfData::U_Ticks, psh, CHECK); |
|
358 |
} |
|
359 |
||
360 |
/* |
|
361 |
* the statSampler_exit() function is called from os_init.cpp on |
|
362 |
* exit of the vm. |
|
363 |
*/ |
|
364 |
void statSampler_exit() { |
|
365 |
||
366 |
if (!UsePerfData) return; |
|
367 |
||
368 |
StatSampler::destroy(); |
|
369 |
} |