RFR: 8264285: Do not support FLAG_SET_XXX for VM flags of string type

Ioi Lam iklam at openjdk.java.net
Fri Mar 26 17:01:34 UTC 2021


We have two versions of `JVMFlagAccess::ccstrAtPut()` that are slightly different.

The following version is supposed to be used only by the `FLAG_SET_{CMDLINE,ERGO,MGMT}` macros. However, it's not used anywhere in the HotSpot source code:

JVMFlag::Error JVMFlagAccess::ccstrAtPut(JVMFlagsEnum flag, ccstr value, JVMFlagOrigin origin) {
  JVMFlag* faddr = JVMFlag::flag_from_enum(flag);
  assert(faddr->is_ccstr(), "wrong flag type");
  ccstr old_value = faddr->get_ccstr();
  trace_flag_changed<ccstr, EventStringFlagChanged>(faddr, old_value, value, origin);
  char* new_value = os::strdup_check_oom(value);
  faddr->set_ccstr(new_value);
  if (!faddr->is_default() && old_value != NULL) {
    // Prior value is heap allocated so free it.
    FREE_C_HEAP_ARRAY(char, old_value);
  }
  faddr->set_origin(origin);
  return JVMFlag::SUCCESS;
}

It's not clear whether this unused version is actually correct since the last JVMFlag rewrite in [JDK-8081833](https://bugs.openjdk.java.net/browse/JDK-8081833), due to complete lack of testing. Let's remove this version to simplify code maintenance.

If you need to modify flags of the string type, do not use `FLAG_SET_{CMDLINE,ERGO,MGMT}`. (A `static_assert` is added to prevent this). Instead, use the remaining version of `JVMFlagAccess::ccstrAtPut()`.

-------------

Commit messages:
 - 8264285: Do not support FLAG_SET_XXX for VM flags of string type

Changes: https://git.openjdk.java.net/jdk/pull/3219/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3219&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8264285
  Stats: 33 lines in 3 files changed: 7 ins; 17 del; 9 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3219.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3219/head:pull/3219

PR: https://git.openjdk.java.net/jdk/pull/3219


More information about the hotspot-dev mailing list