mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8159370: Add FlagGuard for easier modification of flags for unit tests
Reviewed-by: kbarrett, jwilhelm
This commit is contained in:
parent
161976b05f
commit
3895ad9e00
2 changed files with 97 additions and 0 deletions
|
@ -463,6 +463,29 @@ class SizeTFlagSetting {
|
|||
~SizeTFlagSetting() { *flag = val; }
|
||||
};
|
||||
|
||||
// Helper class for temporarily saving the value of a flag during a scope.
|
||||
template <size_t SIZE>
|
||||
class FlagGuard {
|
||||
unsigned char _value[SIZE];
|
||||
void* const _addr;
|
||||
|
||||
// Hide operator new, this class should only be allocated on the stack.
|
||||
// NOTE: Cannot include memory/allocation.hpp here due to circular
|
||||
// dependencies.
|
||||
void* operator new(size_t size) throw();
|
||||
void* operator new [](size_t size) throw();
|
||||
|
||||
public:
|
||||
FlagGuard(void* flag_addr) : _addr(flag_addr) {
|
||||
memcpy(_value, _addr, SIZE);
|
||||
}
|
||||
|
||||
~FlagGuard() {
|
||||
memcpy(_addr, _value, SIZE);
|
||||
}
|
||||
};
|
||||
|
||||
#define FLAG_GUARD(f) FlagGuard<sizeof(f)> f ## _guard(&f)
|
||||
|
||||
class CommandLineFlags {
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue