1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
75
76 void Flag::check_writable() {
77 if (is_constant_in_binary()) {
78 fatal(err_msg("flag is constant: %s", _name));
79 }
80 }
81
82 bool Flag::is_bool() const {
83 return strcmp(_type, "bool") == 0;
84 }
85
86 bool Flag::get_bool() const {
87 return *((bool*) _addr);
88 }
89
90 void Flag::set_bool(bool value) {
91 check_writable();
92 *((bool*) _addr) = value;
93 }
94
95 bool Flag::is_intx() const {
96 return strcmp(_type, "intx") == 0;
97 }
98
99 intx Flag::get_intx() const {
100 return *((intx*) _addr);
101 }
102
103 void Flag::set_intx(intx value) {
104 check_writable();
105 *((intx*) _addr) = value;
106 }
107
108 bool Flag::is_uintx() const {
109 return strcmp(_type, "uintx") == 0;
110 }
111
112 uintx Flag::get_uintx() const {
113 return *((uintx*) _addr);
114 }
115
116 void Flag::set_uintx(uintx value) {
117 check_writable();
118 *((uintx*) _addr) = value;
119 }
120
121 bool Flag::is_uint64_t() const {
122 return strcmp(_type, "uint64_t") == 0;
123 }
124
125 uint64_t Flag::get_uint64_t() const {
126 return *((uint64_t*) _addr);
127 }
128
129 void Flag::set_uint64_t(uint64_t value) {
130 check_writable();
131 *((uint64_t*) _addr) = value;
132 }
133
134 bool Flag::is_double() const {
135 return strcmp(_type, "double") == 0;
136 }
137
138 double Flag::get_double() const {
139 return *((double*) _addr);
140 }
141
142 void Flag::set_double(double value) {
143 check_writable();
144 *((double*) _addr) = value;
145 }
146
147 bool Flag::is_ccstr() const {
148 return strcmp(_type, "ccstr") == 0 || strcmp(_type, "ccstrlist") == 0;
149 }
150
151 bool Flag::ccstr_accumulates() const {
152 return strcmp(_type, "ccstrlist") == 0;
153 }
593 }
594
595 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
596 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
597 Flag* f = &Flag::flags[flag];
598 return f->is_command_line();
599 }
600
601 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
602 Flag* result = Flag::find_flag((char*)name, strlen(name));
603 if (result == NULL) return false;
604 *value = result->is_command_line();
605 return true;
606 }
607
608 template<class E, class T>
609 static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin)
610 {
611 E e;
612 e.set_name(name);
613 e.set_old_value(old_value);
614 e.set_new_value(new_value);
615 e.set_origin(origin);
616 e.commit();
617 }
618
619 bool CommandLineFlags::boolAt(const char* name, size_t len, bool* value) {
620 Flag* result = Flag::find_flag(name, len);
621 if (result == NULL) return false;
622 if (!result->is_bool()) return false;
623 *value = result->get_bool();
624 return true;
625 }
626
627 bool CommandLineFlags::boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin) {
628 Flag* result = Flag::find_flag(name, len);
629 if (result == NULL) return false;
630 if (!result->is_bool()) return false;
631 bool old_value = result->get_bool();
632 trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin);
633 result->set_bool(*value);
634 *value = old_value;
655 bool CommandLineFlags::intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin) {
656 Flag* result = Flag::find_flag(name, len);
657 if (result == NULL) return false;
658 if (!result->is_intx()) return false;
659 intx old_value = result->get_intx();
660 trace_flag_changed<EventLongFlagChanged, s8>(name, old_value, *value, origin);
661 result->set_intx(*value);
662 *value = old_value;
663 result->set_origin(origin);
664 return true;
665 }
666
667 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) {
668 Flag* faddr = address_of_flag(flag);
669 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
670 trace_flag_changed<EventLongFlagChanged, s8>(faddr->_name, faddr->get_intx(), value, origin);
671 faddr->set_intx(value);
672 faddr->set_origin(origin);
673 }
674
675 bool CommandLineFlags::uintxAt(const char* name, size_t len, uintx* value) {
676 Flag* result = Flag::find_flag(name, len);
677 if (result == NULL) return false;
678 if (!result->is_uintx()) return false;
679 *value = result->get_uintx();
680 return true;
681 }
682
683 bool CommandLineFlags::uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin) {
684 Flag* result = Flag::find_flag(name, len);
685 if (result == NULL) return false;
686 if (!result->is_uintx()) return false;
687 uintx old_value = result->get_uintx();
688 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
689 result->set_uintx(*value);
690 *value = old_value;
691 result->set_origin(origin);
692 return true;
693 }
694
695 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) {
696 Flag* faddr = address_of_flag(flag);
|
1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
75
76 void Flag::check_writable() {
77 if (is_constant_in_binary()) {
78 fatal(err_msg("flag is constant: %s", _name));
79 }
80 }
81
82 bool Flag::is_bool() const {
83 return strcmp(_type, "bool") == 0;
84 }
85
86 bool Flag::get_bool() const {
87 return *((bool*) _addr);
88 }
89
90 void Flag::set_bool(bool value) {
91 check_writable();
92 *((bool*) _addr) = value;
93 }
94
95 bool Flag::is_int() const {
96 return strcmp(_type, "int") == 0;
97 }
98
99 int Flag::get_int() const {
100 return *((int*) _addr);
101 }
102
103 void Flag::set_int(int value) {
104 check_writable();
105 *((int*) _addr) = value;
106 }
107
108 bool Flag::is_uint() const {
109 return strcmp(_type, "uint") == 0;
110 }
111
112 uint Flag::get_uint() const {
113 return *((uint*) _addr);
114 }
115
116 void Flag::set_uint(uint value) {
117 check_writable();
118 *((uint*) _addr) = value;
119 }
120
121 bool Flag::is_intx() const {
122 return strcmp(_type, "intx") == 0;
123 }
124
125 intx Flag::get_intx() const {
126 return *((intx*) _addr);
127 }
128
129 void Flag::set_intx(intx value) {
130 check_writable();
131 *((intx*) _addr) = value;
132 }
133
134 bool Flag::is_uintx() const {
135 return strcmp(_type, "uintx") == 0;
136 }
137
138 uintx Flag::get_uintx() const {
139 return *((uintx*) _addr);
140 }
141
142 void Flag::set_uintx(uintx value) {
143 check_writable();
144 *((uintx*) _addr) = value;
145 }
146
147 bool Flag::is_uint64_t() const {
148 return strcmp(_type, "uint64_t") == 0;
149 }
150
151 uint64_t Flag::get_uint64_t() const {
152 return *((uint64_t*) _addr);
153 }
154
155 void Flag::set_uint64_t(uint64_t value) {
156 check_writable();
157 *((uint64_t*) _addr) = value;
158 }
159
160 bool Flag::is_size_t() const {
161 return strcmp(_type, "size_t") == 0;
162 }
163
164 size_t Flag::get_size_t() const {
165 return *((size_t*) _addr);
166 }
167
168 void Flag::set_size_t(size_t value) {
169 check_writable();
170 *((size_t*) _addr) = value;
171 }
172
173 bool Flag::is_double() const {
174 return strcmp(_type, "double") == 0;
175 }
176
177 double Flag::get_double() const {
178 return *((double*) _addr);
179 }
180
181 void Flag::set_double(double value) {
182 check_writable();
183 *((double*) _addr) = value;
184 }
185
186 bool Flag::is_ccstr() const {
187 return strcmp(_type, "ccstr") == 0 || strcmp(_type, "ccstrlist") == 0;
188 }
189
190 bool Flag::ccstr_accumulates() const {
191 return strcmp(_type, "ccstrlist") == 0;
192 }
632 }
633
634 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
635 assert((size_t)flag < Flag::numFlags, "bad command line flag index");
636 Flag* f = &Flag::flags[flag];
637 return f->is_command_line();
638 }
639
640 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
641 Flag* result = Flag::find_flag((char*)name, strlen(name));
642 if (result == NULL) return false;
643 *value = result->is_command_line();
644 return true;
645 }
646
647 template<class E, class T>
648 static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin)
649 {
650 E e;
651 e.set_name(name);
652 e.set_oldValue(old_value);
653 e.set_newValue(new_value);
654 e.set_origin(origin);
655 e.commit();
656 }
657
658 bool CommandLineFlags::boolAt(const char* name, size_t len, bool* value) {
659 Flag* result = Flag::find_flag(name, len);
660 if (result == NULL) return false;
661 if (!result->is_bool()) return false;
662 *value = result->get_bool();
663 return true;
664 }
665
666 bool CommandLineFlags::boolAtPut(const char* name, size_t len, bool* value, Flag::Flags origin) {
667 Flag* result = Flag::find_flag(name, len);
668 if (result == NULL) return false;
669 if (!result->is_bool()) return false;
670 bool old_value = result->get_bool();
671 trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin);
672 result->set_bool(*value);
673 *value = old_value;
694 bool CommandLineFlags::intxAtPut(const char* name, size_t len, intx* value, Flag::Flags origin) {
695 Flag* result = Flag::find_flag(name, len);
696 if (result == NULL) return false;
697 if (!result->is_intx()) return false;
698 intx old_value = result->get_intx();
699 trace_flag_changed<EventLongFlagChanged, s8>(name, old_value, *value, origin);
700 result->set_intx(*value);
701 *value = old_value;
702 result->set_origin(origin);
703 return true;
704 }
705
706 void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) {
707 Flag* faddr = address_of_flag(flag);
708 guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
709 trace_flag_changed<EventLongFlagChanged, s8>(faddr->_name, faddr->get_intx(), value, origin);
710 faddr->set_intx(value);
711 faddr->set_origin(origin);
712 }
713
714 bool CommandLineFlags::uintxAt(const char* name, size_t len, uintx* value, bool allow_locked, bool return_flag) {
715 Flag* result = Flag::find_flag(name, len, allow_locked, return_flag);
716 if (result == NULL) return false;
717 if (!result->is_uintx()) return false;
718 *value = result->get_uintx();
719 return true;
720 }
721
722 bool CommandLineFlags::uintxAtPut(const char* name, size_t len, uintx* value, Flag::Flags origin) {
723 Flag* result = Flag::find_flag(name, len);
724 if (result == NULL) return false;
725 if (!result->is_uintx()) return false;
726 uintx old_value = result->get_uintx();
727 trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
728 result->set_uintx(*value);
729 *value = old_value;
730 result->set_origin(origin);
731 return true;
732 }
733
734 void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) {
735 Flag* faddr = address_of_flag(flag);
|