8245226: Clean-up FlagSetting and remove misuse
Reviewed-by: neliasso, dholmes
This commit is contained in:
parent
30bc2b7ca1
commit
195c45a0e1
src/hotspot/share
gc
memory
runtime
utilities
test/hotspot/gtest
@ -95,13 +95,13 @@
|
||||
#include "oops/compressedOops.inline.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/flags/flagSetting.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/init.hpp"
|
||||
#include "runtime/orderAccess.hpp"
|
||||
#include "runtime/threadSMR.hpp"
|
||||
#include "runtime/vmThread.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/autoRestore.hpp"
|
||||
#include "utilities/bitMap.inline.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/stack.inline.hpp"
|
||||
@ -1940,7 +1940,7 @@ void G1CollectedHeap::allocate_dummy_regions() {
|
||||
|
||||
// _filler_array_max_size is set to humongous object threshold
|
||||
// but temporarily change it to use CollectedHeap::fill_with_object().
|
||||
SizeTFlagSetting fs(_filler_array_max_size, word_size);
|
||||
AutoModifyRestore<size_t> temporarily(_filler_array_max_size, word_size);
|
||||
|
||||
for (uintx i = 0; i < G1DummyRegionsPerGC; ++i) {
|
||||
// Let's use the existing mechanism for the allocation
|
||||
|
@ -63,13 +63,13 @@
|
||||
#include "memory/universe.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "runtime/biasedLocking.hpp"
|
||||
#include "runtime/flags/flagSetting.hpp"
|
||||
#include "runtime/handles.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/java.hpp"
|
||||
#include "runtime/vmThread.hpp"
|
||||
#include "services/management.hpp"
|
||||
#include "services/memoryService.hpp"
|
||||
#include "utilities/autoRestore.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/formatBuffer.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
@ -566,7 +566,7 @@ void GenCollectedHeap::do_collection(bool full,
|
||||
|
||||
ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());
|
||||
|
||||
FlagSetting fl(_is_gc_active, true);
|
||||
AutoModifyRestore<bool> temporarily(_is_gc_active, true);
|
||||
|
||||
bool complete = full && (max_generation == OldGen);
|
||||
bool old_collects_young = complete && !ScavengeBeforeFullGC;
|
||||
|
@ -64,7 +64,6 @@
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/deoptimization.hpp"
|
||||
#include "runtime/flags/flagSetting.hpp"
|
||||
#include "runtime/flags/jvmFlagConstraintList.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/init.hpp"
|
||||
@ -77,6 +76,7 @@
|
||||
#include "runtime/vmOperations.hpp"
|
||||
#include "services/memoryService.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/autoRestore.hpp"
|
||||
#include "utilities/copy.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/events.hpp"
|
||||
@ -298,7 +298,7 @@ void initialize_basic_type_klass(Klass* k, TRAPS) {
|
||||
void Universe::genesis(TRAPS) {
|
||||
ResourceMark rm(THREAD);
|
||||
|
||||
{ FlagSetting fs(_bootstrapping, true);
|
||||
{ AutoModifyRestore<bool> temporarily(_bootstrapping, true);
|
||||
|
||||
{ MutexLocker mc(THREAD, Compile_lock);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,47 +25,25 @@
|
||||
#ifndef SHARE_RUNTIME_FLAGS_FLAGSETTING_HPP
|
||||
#define SHARE_RUNTIME_FLAGS_FLAGSETTING_HPP
|
||||
|
||||
#include "memory/allocation.hpp"
|
||||
#include "utilities/autoRestore.hpp"
|
||||
|
||||
// debug flags control various aspects of the VM and are global accessible
|
||||
// Legacy use of FlagSetting and UIntFlagSetting to temporarily change a debug
|
||||
// flag/option in the current (local) scope.
|
||||
//
|
||||
// Example:
|
||||
// {
|
||||
// FlagSetting temporarily(DebugThisAndThat, true);
|
||||
// . . .
|
||||
// }
|
||||
//
|
||||
// The previous/original value is restored when leaving the scope.
|
||||
|
||||
// use FlagSetting to temporarily change some debug flag
|
||||
// e.g. FlagSetting fs(DebugThisAndThat, true);
|
||||
// restored to previous value upon leaving scope
|
||||
class FlagSetting : public StackObj {
|
||||
bool val;
|
||||
bool* flag;
|
||||
public:
|
||||
FlagSetting(bool& fl, bool newValue) { flag = &fl; val = fl; fl = newValue; }
|
||||
~FlagSetting() { *flag = val; }
|
||||
};
|
||||
typedef AutoModifyRestore<bool> FlagSetting;
|
||||
typedef AutoModifyRestore<uint> UIntFlagSetting;
|
||||
|
||||
class UIntFlagSetting : public StackObj {
|
||||
uint val;
|
||||
uint* flag;
|
||||
public:
|
||||
UIntFlagSetting(uint& fl, uint newValue) { flag = &fl; val = fl; fl = newValue; }
|
||||
~UIntFlagSetting() { *flag = val; }
|
||||
};
|
||||
// Legacy use of FLAG_GUARD. Retained in the code to help identify use-cases
|
||||
// that should be addressed when this file is removed.
|
||||
|
||||
class SizeTFlagSetting : public StackObj {
|
||||
size_t val;
|
||||
size_t* flag;
|
||||
public:
|
||||
SizeTFlagSetting(size_t& fl, size_t newValue) { flag = &fl; val = fl; fl = newValue; }
|
||||
~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;
|
||||
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)
|
||||
#define FLAG_GUARD(f) f ## _guard(f)
|
||||
|
||||
#endif // SHARE_RUNTIME_FLAGS_FLAGSETTING_HPP
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
#include "memory/allocation.hpp"
|
||||
#include "memory/iterator.hpp"
|
||||
#include "runtime/flags/flagSetting.hpp"
|
||||
#include "runtime/semaphore.hpp"
|
||||
#include "utilities/autoRestore.hpp"
|
||||
|
||||
class HandshakeOperation;
|
||||
class JavaThread;
|
||||
@ -92,7 +92,7 @@ public:
|
||||
|
||||
void process_by_self() {
|
||||
if (!_thread_in_process_handshake) {
|
||||
FlagSetting fs(_thread_in_process_handshake, true);
|
||||
AutoModifyRestore<bool> temporarily(_thread_in_process_handshake, true);
|
||||
process_self_inner();
|
||||
}
|
||||
}
|
||||
|
56
src/hotspot/share/utilities/autoRestore.hpp
Normal file
56
src/hotspot/share/utilities/autoRestore.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_UTILITIES_AUTORESTORE_HPP
|
||||
#define SHARE_UTILITIES_AUTORESTORE_HPP
|
||||
|
||||
#include "memory/allocation.hpp"
|
||||
|
||||
// A simplistic template providing a general save-restore pattern through a
|
||||
// local auto/stack object (scope).
|
||||
//
|
||||
template<typename T> class AutoSaveRestore : public StackObj {
|
||||
public:
|
||||
AutoSaveRestore(T &loc) : _loc(loc) {
|
||||
_value = loc;
|
||||
}
|
||||
~AutoSaveRestore() {
|
||||
_loc = _value;
|
||||
}
|
||||
private:
|
||||
T &_loc;
|
||||
T _value;
|
||||
};
|
||||
|
||||
// A simplistic template providing a general modify-restore pattern through a
|
||||
// local auto/stack object (scope).
|
||||
//
|
||||
template<typename T> class AutoModifyRestore : private AutoSaveRestore<T> {
|
||||
public:
|
||||
AutoModifyRestore(T &loc, T value) : AutoSaveRestore<T>(loc) {
|
||||
loc = value;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SHARE_UTILITIES_AUTORESTORE_HPP
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -57,13 +57,13 @@ class TestGenCollectorPolicy {
|
||||
class TestWrapper {
|
||||
public:
|
||||
static void test(Executor* setter1, Executor* setter2, Executor* checker) {
|
||||
FLAG_GUARD(MinHeapSize);
|
||||
FLAG_GUARD(InitialHeapSize);
|
||||
FLAG_GUARD(MaxHeapSize);
|
||||
FLAG_GUARD(MaxNewSize);
|
||||
FLAG_GUARD(MinHeapDeltaBytes);
|
||||
FLAG_GUARD(NewSize);
|
||||
FLAG_GUARD(OldSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(MinHeapSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(InitialHeapSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(MaxHeapSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(MaxNewSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(MinHeapDeltaBytes);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(NewSize);
|
||||
AutoSaveRestore<size_t> FLAG_GUARD(OldSize);
|
||||
|
||||
MinHeapSize = 40 * M;
|
||||
FLAG_SET_ERGO(InitialHeapSize, 100 * M);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,7 +32,7 @@
|
||||
ASSERT_TRUE(JVMFlag::find_flag(#f)->is_ ## type()); \
|
||||
type original_value = f; \
|
||||
{ \
|
||||
FLAG_GUARD(f); \
|
||||
AutoSaveRestore<type> FLAG_GUARD(f); \
|
||||
f = value; \
|
||||
} \
|
||||
ASSERT_EQ(original_value, f); \
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -57,8 +57,8 @@ TEST_VM(os_windows, reserve_memory_special) {
|
||||
}
|
||||
|
||||
// set globals to make sure we hit the correct code path
|
||||
FLAG_GUARD(UseLargePagesIndividualAllocation);
|
||||
FLAG_GUARD(UseNUMAInterleaving);
|
||||
AutoSaveRestore<bool> FLAG_GUARD(UseLargePagesIndividualAllocation);
|
||||
AutoSaveRestore<bool> FLAG_GUARD(UseNUMAInterleaving);
|
||||
FLAG_SET_CMDLINE(UseLargePagesIndividualAllocation, false);
|
||||
FLAG_SET_CMDLINE(UseNUMAInterleaving, false);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user