@@ -173,15 +173,15 @@ void StatSampler::collect_sample() {
173
173
}
174
174
175
175
/*
176
- * method to upcall into Java to return the value of the specified
177
- * property as a utf8 string, or NULL if does not exist. The caller
178
- * is responsible for setting a ResourceMark for proper cleanup of
179
- * the utf8 strings.
176
+ * Call into java.lang.System.getProperty to check that the value of the
177
+ * specified property matches
180
178
*/
181
- const char * StatSampler::get_system_property (const char * name, TRAPS) {
179
+ void StatSampler::assert_system_property (const char * name, const char * value, TRAPS) {
180
+ #ifdef ASSERT
181
+ ResourceMark rm (THREAD);
182
182
183
183
// setup the arguments to getProperty
184
- Handle key_str = java_lang_String::create_from_str (name, CHECK_NULL );
184
+ Handle key_str = java_lang_String::create_from_str (name, CHECK );
185
185
186
186
// return value
187
187
JavaValue result (T_OBJECT);
@@ -192,100 +192,73 @@ const char* StatSampler::get_system_property(const char* name, TRAPS) {
192
192
vmSymbols::getProperty_name (),
193
193
vmSymbols::string_string_signature (),
194
194
key_str,
195
- CHECK_NULL );
195
+ CHECK );
196
196
197
197
oop value_oop = (oop)result.get_jobject ();
198
- if (value_oop == NULL ) {
199
- return NULL ;
200
- }
198
+ assert (value_oop != NULL , " property must have a value" );
201
199
202
200
// convert Java String to utf8 string
203
- char * value = java_lang_String::as_utf8_string (value_oop);
201
+ char * system_value = java_lang_String::as_utf8_string (value_oop);
204
202
205
- return value;
203
+ assert (strcmp (value, system_value) == 0 , " property value mustn't differ from System.getProperty" );
204
+ #endif // ASSERT
206
205
}
207
206
208
207
/*
209
- * The list of System Properties that have corresponding PerfData
210
- * string instrumentation created by retrieving the named property's
211
- * value from System.getProperty() and unconditionally creating a
212
- * PerfStringConstant object initialized to the retrieved value. This
213
- * is not an exhaustive list of Java properties with corresponding string
214
- * instrumentation as the create_system_property_instrumentation() method
215
- * creates other property based instrumentation conditionally.
208
+ * Adds a constant counter of the given property. Asserts the value does not
209
+ * differ from the value retrievable from System.getProperty(name)
216
210
*/
211
+ void StatSampler::add_property_constant (CounterNS name_space, const char * name, const char * value, TRAPS) {
212
+ // the property must exist
213
+ assert (value != NULL , " property name should be have a value: %s" , name);
214
+ assert_system_property (name, value, CHECK);
215
+ if (value != NULL ) {
216
+ // create the property counter
217
+ PerfDataManager::create_string_constant (name_space, name, value, CHECK);
218
+ }
219
+ }
217
220
218
- // stable interface, supported counters
219
- static const char * property_counters_ss[] = {
220
- " java.vm.specification.version" ,
221
- " java.vm.specification.name" ,
222
- " java.vm.specification.vendor" ,
223
- " java.vm.version" ,
224
- " java.vm.name" ,
225
- " java.vm.vendor" ,
226
- " java.vm.info" ,
227
- " jdk.debug" ,
228
- " java.library.path" ,
229
- " java.class.path" ,
230
- " java.version" ,
231
- " java.home" ,
232
- NULL
233
- };
234
-
235
- // unstable interface, supported counters
236
- static const char * property_counters_us[] = {
237
- NULL
238
- };
239
-
240
- // unstable interface, unsupported counters
241
- static const char * property_counters_uu[] = {
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
-
221
+ /*
222
+ * Adds a string constant of the given property. Retrieves the value via
223
+ * Arguments::get_property() and asserts the value for the does not differ from
224
+ * the value retrievable from System.getProperty()
225
+ */
226
+ void StatSampler::add_property_constant (CounterNS name_space, const char * name, TRAPS) {
227
+ add_property_constant (name_space, name, Arguments::get_property (name), CHECK);
228
+ }
258
229
259
230
/*
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[].
231
+ * Method to create PerfStringConstants containing the values of various
232
+ * system properties. Constants are created from information known to HotSpot,
233
+ * but are initialized as-if getting the values from System.getProperty()
234
+ * during bootstrap.
235
+ *
263
236
* Property counters have a counter name space prefix prepended to the
264
- * property name as indicated in property_counters[] .
237
+ * property name.
265
238
*/
266
239
void StatSampler::create_system_property_instrumentation (TRAPS) {
267
240
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
- }
241
+ // Non-writeable, constant properties
242
+ add_property_constant (JAVA_PROPERTY, " java.vm.specification.name " , " Java Virtual Machine Specification " , CHECK);
243
+ add_property_constant (JAVA_PROPERTY, " java.version " , JDK_Version::java_version (), CHECK);
244
+ add_property_constant (JAVA_PROPERTY, " java.vm.version " , VM_Version::vm_release (), CHECK);
245
+ add_property_constant (JAVA_PROPERTY, " java.vm.name " , VM_Version::vm_name (), CHECK);
246
+ add_property_constant (JAVA_PROPERTY, " java.vm.vendor " , VM_Version::vm_vendor (), CHECK);
247
+ add_property_constant (JAVA_PROPERTY, " jdk.debug " , VM_Version::jdk_debug_level (), CHECK) ;
248
+
249
+ // Get remaining property constants via Arguments::get_property,
250
+ // which does a linear search over the internal system properties list.
251
+
252
+ // SUN_PROPERTY properties
253
+ add_property_constant (SUN_PROPERTY , " sun.boot.library.path " , CHECK );
254
+
255
+ // JAVA_PROPERTY properties
256
+ add_property_constant (JAVA_PROPERTY, " java.vm.specification.version " , CHECK);
257
+ add_property_constant (JAVA_PROPERTY, " java.vm.specification.vendor " , CHECK);
258
+ add_property_constant (JAVA_PROPERTY, " java.vm.info " , CHECK);
259
+ add_property_constant (JAVA_PROPERTY, " java.library.path " , CHECK);
260
+ add_property_constant (JAVA_PROPERTY, " java.class.path " , CHECK);
261
+ add_property_constant (JAVA_PROPERTY, " java.home " , CHECK);
289
262
}
290
263
291
264
/*
0 commit comments