author | gziemski |
Tue, 29 May 2018 12:57:39 -0500 | |
changeset 50292 | 43d41f780a5b |
parent 49857 | 31e07291ae29 |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
49857
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
1 |
/* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
4 |
* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
8 |
* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
13 |
* accompanied this code). |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
14 |
* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
18 |
* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
21 |
* questions. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
22 |
* |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
23 |
*/ |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
24 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
25 |
#ifndef SHARE_VM_RUNTIME_FLAGS_FLAGSETTING_HPP |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
26 |
#define SHARE_VM_RUNTIME_FLAGS_FLAGSETTING_HPP |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
27 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
29 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
30 |
// debug flags control various aspects of the VM and are global accessible |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
31 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
32 |
// use FlagSetting to temporarily change some debug flag |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
33 |
// e.g. FlagSetting fs(DebugThisAndThat, true); |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
34 |
// restored to previous value upon leaving scope |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
35 |
class FlagSetting : public StackObj { |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
36 |
bool val; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
37 |
bool* flag; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
38 |
public: |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
39 |
FlagSetting(bool& fl, bool newValue) { flag = &fl; val = fl; fl = newValue; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
40 |
~FlagSetting() { *flag = val; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
41 |
}; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
42 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
43 |
class UIntFlagSetting : public StackObj { |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
44 |
uint val; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
45 |
uint* flag; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
46 |
public: |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
47 |
UIntFlagSetting(uint& fl, uint newValue) { flag = &fl; val = fl; fl = newValue; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
48 |
~UIntFlagSetting() { *flag = val; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
49 |
}; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
50 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
51 |
class SizeTFlagSetting : public StackObj { |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
52 |
size_t val; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
53 |
size_t* flag; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
54 |
public: |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
55 |
SizeTFlagSetting(size_t& fl, size_t newValue) { flag = &fl; val = fl; fl = newValue; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
56 |
~SizeTFlagSetting() { *flag = val; } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
57 |
}; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
58 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
59 |
// Helper class for temporarily saving the value of a flag during a scope. |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
60 |
template <size_t SIZE> |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
61 |
class FlagGuard { |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
62 |
unsigned char _value[SIZE]; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
63 |
void* const _addr; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
64 |
public: |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
65 |
FlagGuard(void* flag_addr) : _addr(flag_addr) { memcpy(_value, _addr, SIZE); } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
66 |
~FlagGuard() { memcpy(_addr, _value, SIZE); } |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
67 |
}; |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
68 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
69 |
#define FLAG_GUARD(f) FlagGuard<sizeof(f)> f ## _guard(&f) |
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
70 |
|
31e07291ae29
8081519: Split globals.hpp to factor out the Flag class
gziemski
parents:
diff
changeset
|
71 |
#endif // SHARE_VM_RUNTIME_FLAGS_FLAGSETTING_HPP |