RFR: 8159370: Add FlagGuard for easier modification of flags for unit tests

Erik Helin erik.helin at oracle.com
Tue Jun 14 10:58:57 UTC 2016


Hi all,

this patch adds a small utility class that makes it easier for TEST_VM
unit tests to safely modify flags. The class FlagGuard will store the
value of the flag in its constructor and then restore the flag in its
destructor. This is similar IntFlagSetting, UIntFlagSetting etc, but the
FlagGuard differs in two aspects:
- it does not set a new value
- it is "untyped", you can use FlagGuard for flags with any type

I have also added a macro, GUARD_FLAG, to make it more convenient to
guard a flag. A test might now look like:

  TEST_VM(G1Policy, test_calc_max_old_cset_length) {
    GUARD_FLAG(MaxGCPauseMillis);
    GUARD_FLAG(ParallelGCThreads);
  
    MaxGCPauseMillis = 500;
    ParallelGCThreads = 10;
    ASSERT_EQ(10u, G1Policy::calc_max_old_cset_length());
  
    MaxGCPauseMillis = 50;
    ParallelGCThreads = 1;
    ASSERT_EQ(2u, G1Policy::calc_max_old_cset_length());
  
    // All guarded flags are restored here
  }

Bug:
https://bugs.openjdk.java.net/browse/JDK-8159370

Webrev:
http://cr.openjdk.java.net/~ehelin/8159370/00/

Testing:
- JPRT

Thanks,
Erik


More information about the hotspot-dev mailing list