@@ -317,40 +317,29 @@ JVMFlag::Error JVMFlagAccess::ccstrAtPut(JVMFlag* flag, ccstr* value, JVMFlagOri
317317 new_value = os::strdup_check_oom (*value);
318318 }
319319 flag->set_ccstr (new_value);
320- if (flag->is_default () && old_value != NULL ) {
321- // Prior value is NOT heap allocated, but was a literal constant .
322- old_value = os::strdup_check_oom ( old_value);
320+ if (! flag->is_default () && old_value != NULL ) {
321+ // Old value is heap allocated so free it .
322+ FREE_C_HEAP_ARRAY ( char , old_value);
323323 }
324- *value = old_value;
324+ // Unlike the other APIs, the old vale is NOT returned, so the caller won't need to free it.
325+ // The callers typically don't care what the old value is.
326+ // If the caller really wants to know the old value, read it (and make a copy if necessary)
327+ // before calling this API.
328+ *value = NULL ;
325329 flag->set_origin (origin);
326330 return JVMFlag::SUCCESS;
327331}
328332
329333// This is called by the FLAG_SET_XXX macros.
330334JVMFlag::Error JVMFlagAccess::set_impl (JVMFlagsEnum flag_enum, int type_enum, void * value, JVMFlagOrigin origin) {
331- if (type_enum == JVMFlag::TYPE_ccstr || type_enum == JVMFlag::TYPE_ccstrlist) {
332- return ccstrAtPut ((JVMFlagsEnum)flag_enum, *((ccstr*)value), origin);
333- }
334-
335335 JVMFlag* flag = JVMFlag::flag_from_enum (flag_enum);
336- assert (flag->type () == type_enum, " wrong flag type" );
337- return set_impl (flag, type_enum, value, origin);
338- }
339-
340- // This is called by the FLAG_SET_XXX macros.
341- JVMFlag::Error JVMFlagAccess::ccstrAtPut (JVMFlagsEnum flag, ccstr value, JVMFlagOrigin origin) {
342- JVMFlag* faddr = JVMFlag::flag_from_enum (flag);
343- assert (faddr->is_ccstr (), " wrong flag type" );
344- ccstr old_value = faddr->get_ccstr ();
345- trace_flag_changed<ccstr, EventStringFlagChanged>(faddr, old_value, value, origin);
346- char * new_value = os::strdup_check_oom (value);
347- faddr->set_ccstr (new_value);
348- if (!faddr->is_default () && old_value != NULL ) {
349- // Prior value is heap allocated so free it.
350- FREE_C_HEAP_ARRAY (char , old_value);
336+ if (type_enum == JVMFlag::TYPE_ccstr || type_enum == JVMFlag::TYPE_ccstrlist) {
337+ assert (flag->is_ccstr (), " must be" );
338+ return ccstrAtPut (flag, (ccstr*)value, origin);
339+ } else {
340+ assert (flag->type () == type_enum, " wrong flag type" );
341+ return set_impl (flag, type_enum, value, origin);
351342 }
352- faddr->set_origin (origin);
353- return JVMFlag::SUCCESS;
354343}
355344
356345JVMFlag::Error JVMFlagAccess::check_range (const JVMFlag* flag, bool verbose) {
0 commit comments