-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8264285: Clean the modification of ccstr JVM flags #3254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4fe5df9
7eca234
673aaaf
2a5e2b1
5f91222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright (c) 2021, 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_RUNTIME_DEBUG_GLOBALS_HPP | ||
| #define SHARE_RUNTIME_DEBUG_GLOBALS_HPP | ||
|
|
||
| #include "runtime/globals_shared.hpp" | ||
| #include "utilities/macros.hpp" | ||
|
|
||
| // | ||
| // These flags are needed for testing the implementation of various flag access | ||
| // APIs. | ||
| // | ||
| // For example, DummyManageableStringFlag is needed because we don't | ||
| // have any MANAGEABLE flags of the ccstr type, but we really need to | ||
| // make sure the implementation is correct (in terms of memory allocation) | ||
| // just in case someone may add such a flag in the future. | ||
| // | ||
|
|
||
| #ifndef ASSERT | ||
|
|
||
| #define DEBUG_RUNTIME_FLAGS(develop, \ | ||
| develop_pd, \ | ||
| product, \ | ||
| product_pd, \ | ||
| notproduct, \ | ||
| range, \ | ||
| constraint) \ | ||
| \ | ||
|
|
||
| #else | ||
|
|
||
| #define DEBUG_RUNTIME_FLAGS(develop, \ | ||
| develop_pd, \ | ||
| product, \ | ||
| product_pd, \ | ||
| notproduct, \ | ||
| range, \ | ||
| constraint) \ | ||
| \ | ||
| product(ccstr, DummyManageableStringFlag, NULL, MANAGEABLE, \ | ||
| "Dummy flag for testing string handling in WriteableFlags") \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is in essence a product/manageable flag in debug only mode, which doesn't make sense at all, necessitating another macro that looks honestly bizarre. So I think that means a non-product manageable flag or even a develop manageable flag is something that we want, we want to be able to write a develop flag by the management interface. I agree diagnostic and experimental flags only seem to make sense as product flags. The doc could simply be updated. Also the doc at the top of this file refers to CCC which is no longer -> CSR. // MANAGEABLE flags are writeable external product flags. I'm not going to spend time typing about this minor point. The improvement is good and should be checked in. |
||
| \ | ||
|
|
||
| // end of DEBUG_RUNTIME_FLAGS | ||
|
|
||
| #endif // ASSERT | ||
|
|
||
| DECLARE_FLAGS(DEBUG_RUNTIME_FLAGS) | ||
|
|
||
| #endif // SHARE_RUNTIME_DEBUG_GLOBALS_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,40 +317,29 @@ JVMFlag::Error JVMFlagAccess::ccstrAtPut(JVMFlag* flag, ccstr* value, JVMFlagOri | |
| new_value = os::strdup_check_oom(*value); | ||
| } | ||
| flag->set_ccstr(new_value); | ||
| if (flag->is_default() && old_value != NULL) { | ||
| // Prior value is NOT heap allocated, but was a literal constant. | ||
| old_value = os::strdup_check_oom(old_value); | ||
| if (!flag->is_default() && old_value != NULL) { | ||
| // Old value is heap allocated so free it. | ||
| FREE_C_HEAP_ARRAY(char, old_value); | ||
| } | ||
| *value = old_value; | ||
| // Unlike the other APIs, the old vale is NOT returned, so the caller won't need to free it. | ||
| // The callers typically don't care what the old value is. | ||
| // If the caller really wants to know the old value, read it (and make a copy if necessary) | ||
| // before calling this API. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good comment! |
||
| *value = NULL; | ||
| flag->set_origin(origin); | ||
| return JVMFlag::SUCCESS; | ||
| } | ||
|
|
||
| // This is called by the FLAG_SET_XXX macros. | ||
| JVMFlag::Error JVMFlagAccess::set_impl(JVMFlagsEnum flag_enum, int type_enum, void* value, JVMFlagOrigin origin) { | ||
| if (type_enum == JVMFlag::TYPE_ccstr || type_enum == JVMFlag::TYPE_ccstrlist) { | ||
| return ccstrAtPut((JVMFlagsEnum)flag_enum, *((ccstr*)value), origin); | ||
| } | ||
|
|
||
| JVMFlag* flag = JVMFlag::flag_from_enum(flag_enum); | ||
| assert(flag->type() == type_enum, "wrong flag type"); | ||
| return set_impl(flag, type_enum, value, origin); | ||
| } | ||
|
|
||
| // This is called by the FLAG_SET_XXX macros. | ||
| JVMFlag::Error JVMFlagAccess::ccstrAtPut(JVMFlagsEnum flag, ccstr value, JVMFlagOrigin origin) { | ||
| JVMFlag* faddr = JVMFlag::flag_from_enum(flag); | ||
| assert(faddr->is_ccstr(), "wrong flag type"); | ||
| ccstr old_value = faddr->get_ccstr(); | ||
| trace_flag_changed<ccstr, EventStringFlagChanged>(faddr, old_value, value, origin); | ||
| char* new_value = os::strdup_check_oom(value); | ||
| faddr->set_ccstr(new_value); | ||
| if (!faddr->is_default() && old_value != NULL) { | ||
| // Prior value is heap allocated so free it. | ||
| FREE_C_HEAP_ARRAY(char, old_value); | ||
| if (type_enum == JVMFlag::TYPE_ccstr || type_enum == JVMFlag::TYPE_ccstrlist) { | ||
| assert(flag->is_ccstr(), "must be"); | ||
| return ccstrAtPut(flag, (ccstr*)value, origin); | ||
| } else { | ||
| assert(flag->type() == type_enum, "wrong flag type"); | ||
| return set_impl(flag, type_enum, value, origin); | ||
| } | ||
| faddr->set_origin(origin); | ||
| return JVMFlag::SUCCESS; | ||
| } | ||
|
|
||
| JVMFlag::Error JVMFlagAccess::check_range(const JVMFlag* flag, bool verbose) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2015, 2021, 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,6 +25,7 @@ | |
| #include "precompiled.hpp" | ||
| #include "classfile/javaClasses.hpp" | ||
| #include "memory/allocation.inline.hpp" | ||
| #include "memory/resourceArea.hpp" | ||
| #include "runtime/arguments.hpp" | ||
| #include "runtime/flags/jvmFlag.hpp" | ||
| #include "runtime/flags/jvmFlagAccess.hpp" | ||
|
|
@@ -244,6 +245,9 @@ JVMFlag::Error WriteableFlags::set_double_flag(const char* name, double value, J | |
| JVMFlag::Error WriteableFlags::set_ccstr_flag(const char* name, const char* value, JVMFlagOrigin origin, FormatBuffer<80>& err_msg) { | ||
| JVMFlag* flag = JVMFlag::find_flag(name); | ||
| JVMFlag::Error err = JVMFlagAccess::ccstrAtPut(flag, &value, origin); | ||
| if (err == JVMFlag::SUCCESS) { | ||
| assert(value == NULL, "old value is freed automatically and not returned"); | ||
| } | ||
|
Comment on lines
+248
to
+250
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole block should be ifdef DEBUG.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this whole block can be optimized out by the C compiler in product builds, I'd rather leave out the |
||
| print_flag_error_message_if_needed(err, flag, err_msg); | ||
| return err; | ||
| } | ||
|
|
@@ -357,11 +361,9 @@ JVMFlag::Error WriteableFlags::set_flag_from_jvalue(JVMFlag* f, const void* valu | |
| err_msg.print("flag value is missing"); | ||
| return JVMFlag::MISSING_VALUE; | ||
| } | ||
| ResourceMark rm; | ||
| ccstr svalue = java_lang_String::as_utf8_string(str); | ||
| JVMFlag::Error ret = WriteableFlags::set_ccstr_flag(f->name(), svalue, origin, err_msg); | ||
| if (ret != JVMFlag::SUCCESS) { | ||
| FREE_C_HEAP_ARRAY(char, svalue); | ||
| } | ||
| return ret; | ||
| } else { | ||
| ShouldNotReachHere(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you have just added a develop flag to the manageable flags instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to use a
productflag due to the following code, which should have been removed as part of JDK-8243208, but I was afraid to do so because I didn't have a test case. I.e., all of our diagnostic/manageable/experimental flags wereproductflags.With this PR, now I have a test case -- I changed
DummyManageableStringFlagto anotproductflag, and removed the following code. I am re-running tiers1-4 now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between notproduct and develop again? Do we run tests with the optimized build and why would this flag be available in that build? ie. why not develop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the top of globals.hpp:
developflags are settable / visible only during development and are constant in the PRODUCT versionnotproductflags are settable / visible only during development and are not declared in the PRODUCT versionSince this flag is only used in test cases, and specifically for modifying its value, it doesn't make sense to expose this flag to the PRODUCT version at all. So I chose
notproduct, so we can save a few bytes for the PRODUCT as well.