8143958: CDS Shared flags need constraint function
authorgziemski
Wed, 30 Mar 2016 11:28:51 -0500
changeset 37212 eee5234b860e
parent 37206 639ad21e6fad
child 37213 44ada89d5ba3
8143958: CDS Shared flags need constraint function Summary: Implement range constraints for CDS flags. Reviewed-by: iklam, jiangli
hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.cpp
hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.hpp
hotspot/src/share/vm/runtime/globals.hpp
hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.cpp	Tue Mar 29 16:21:16 2016 -0400
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.cpp	Wed Mar 30 11:28:51 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016 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
@@ -130,3 +130,36 @@
     return Flag::SUCCESS;
   }
 }
+
+static inline Flag::Error sharedConstraintFunc(const char *name, size_t value, size_t taken, bool verbose) {
+  size_t available = (MAX_SHARED_DELTA-(taken+SHARED_PAGE));
+  if (value > available) {
+    CommandLineError::print(verbose,
+                            "%s (" SIZE_FORMAT ") must be "
+                            "smaller than or equal to (" SIZE_FORMAT ")\n",
+                            name, value, available);
+    return Flag::VIOLATES_CONSTRAINT;
+  } else {
+    return Flag::SUCCESS;
+  }
+}
+
+Flag::Error SharedReadWriteSizeConstraintFunc(size_t value, bool verbose) {
+  size_t taken = (SharedReadOnlySize+SharedMiscDataSize+SharedMiscCodeSize);
+  return sharedConstraintFunc("SharedReadWriteSize", value, taken, verbose);
+}
+
+Flag::Error SharedReadOnlySizeConstraintFunc(size_t value, bool verbose) {
+  size_t taken = (SharedReadWriteSize+SharedMiscDataSize+SharedMiscCodeSize);
+  return sharedConstraintFunc("SharedReadOnlySize", value, taken, verbose);
+}
+
+Flag::Error SharedMiscDataSizeConstraintFunc(size_t value, bool verbose) {
+  size_t taken = (SharedReadWriteSize+SharedReadOnlySize+SharedMiscCodeSize);
+  return sharedConstraintFunc("SharedMiscDataSize", value, taken, verbose);
+}
+
+Flag::Error SharedMiscCodeSizeConstraintFunc(size_t value, bool verbose) {
+  size_t taken = (SharedReadWriteSize+SharedReadOnlySize+SharedMiscDataSize);
+  return sharedConstraintFunc("SharedMiscCodeSize", value, taken, verbose);
+}
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.hpp	Tue Mar 29 16:21:16 2016 -0400
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintsRuntime.hpp	Wed Mar 30 11:28:51 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016 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
@@ -45,4 +45,9 @@
 
 Flag::Error PerfDataSamplingIntervalFunc(intx value, bool verbose);
 
+Flag::Error SharedReadWriteSizeConstraintFunc(size_t value, bool verbose);
+Flag::Error SharedReadOnlySizeConstraintFunc(size_t value, bool verbose);
+Flag::Error SharedMiscDataSizeConstraintFunc(size_t value, bool verbose);
+Flag::Error SharedMiscCodeSizeConstraintFunc(size_t value, bool verbose);
+
 #endif /* SHARE_VM_RUNTIME_COMMANDLINEFLAGCONSTRAINTSRUNTIME_HPP */
--- a/hotspot/src/share/vm/runtime/globals.hpp	Tue Mar 29 16:21:16 2016 -0400
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Wed Mar 30 11:28:51 2016 -0500
@@ -3961,18 +3961,22 @@
   product(size_t, SharedReadWriteSize, DEFAULT_SHARED_READ_WRITE_SIZE,      \
           "Size of read-write space for metadata (in bytes)")               \
           range(MIN_SHARED_READ_WRITE_SIZE, MAX_SHARED_READ_WRITE_SIZE)     \
+          constraint(SharedReadWriteSizeConstraintFunc,AfterErgo)           \
                                                                             \
   product(size_t, SharedReadOnlySize, DEFAULT_SHARED_READ_ONLY_SIZE,        \
           "Size of read-only space for metadata (in bytes)")                \
           range(MIN_SHARED_READ_ONLY_SIZE, MAX_SHARED_READ_ONLY_SIZE)       \
+          constraint(SharedReadOnlySizeConstraintFunc,AfterErgo)            \
                                                                             \
   product(size_t, SharedMiscDataSize, DEFAULT_SHARED_MISC_DATA_SIZE,        \
           "Size of the shared miscellaneous data area (in bytes)")          \
           range(MIN_SHARED_MISC_DATA_SIZE, MAX_SHARED_MISC_DATA_SIZE)       \
+          constraint(SharedMiscDataSizeConstraintFunc,AfterErgo)            \
                                                                             \
   product(size_t, SharedMiscCodeSize, DEFAULT_SHARED_MISC_CODE_SIZE,        \
           "Size of the shared miscellaneous code area (in bytes)")          \
           range(MIN_SHARED_MISC_CODE_SIZE, MAX_SHARED_MISC_CODE_SIZE)       \
+          constraint(SharedMiscCodeSizeConstraintFunc,AfterErgo)            \
                                                                             \
   product(size_t, SharedBaseAddress, LP64_ONLY(32*G)                        \
           NOT_LP64(LINUX_ONLY(2*G) NOT_LINUX(0)),                           \
--- a/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Tue Mar 29 16:21:16 2016 -0400
+++ b/hotspot/test/runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java	Wed Mar 30 11:28:51 2016 -0500
@@ -97,15 +97,6 @@
         excludeTestRange("ThreadStackSize");
 
         /*
-         * JDK-8143958
-         * Temporarily exclude testing of max range for Shared* flags
-         */
-        excludeTestMaxRange("SharedReadWriteSize");
-        excludeTestMaxRange("SharedReadOnlySize");
-        excludeTestMaxRange("SharedMiscDataSize");
-        excludeTestMaxRange("SharedMiscCodeSize");
-
-        /*
          * Remove the flag controlling the size of the stack because the
          * flag has direct influence on the physical memory usage of
          * the VM.