changeset 12325:a07c25e4f67e

Merge
author adlertz
date Fri, 27 Sep 2013 12:43:51 -0700
parents f637d4dc21bb (current diff) c9ccd7b85f20 (diff)
children 1c3486050433
files src/share/vm/prims/jvm.cpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/globals.hpp src/share/vm/services/attachListener.cpp
diffstat 46 files changed, 1412 insertions(+), 430 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java	Thu Sep 26 08:48:15 2013 +0200
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java	Fri Sep 27 12:43:51 2013 -0700
@@ -134,15 +134,13 @@
      private String type;
      private String name;
      private Address addr;
-     private String kind;
-     private int origin;
+     private int flags;
 
-     private Flag(String type, String name, Address addr, String kind, int origin) {
+     private Flag(String type, String name, Address addr, int flags) {
         this.type = type;
         this.name = name;
         this.addr = addr;
-        this.kind = kind;
-        this.origin = origin;
+        this.flags = flags;
      }
 
      public String getType() {
@@ -157,12 +155,8 @@
         return addr;
      }
 
-     public String getKind() {
-        return kind;
-     }
-
      public int getOrigin() {
-        return origin;
+        return flags & 0xF;  // XXX can we get the mask bits from somewhere?
      }
 
      public boolean isBool() {
@@ -173,8 +167,7 @@
         if (Assert.ASSERTS_ENABLED) {
            Assert.that(isBool(), "not a bool flag!");
         }
-        return addr.getCIntegerAt(0, boolType.getSize(), boolType.isUnsigned())
-               != 0;
+        return addr.getCIntegerAt(0, boolType.getSize(), boolType.isUnsigned()) != 0;
      }
 
      public boolean isIntx() {
@@ -843,11 +836,10 @@
 
     Address flagAddr = flagType.getAddressField("flags").getValue();
 
-    AddressField typeFld = flagType.getAddressField("type");
-    AddressField nameFld = flagType.getAddressField("name");
-    AddressField addrFld = flagType.getAddressField("addr");
-    AddressField kindFld = flagType.getAddressField("kind");
-    CIntField originFld = new CIntField(flagType.getCIntegerField("origin"), 0);
+    AddressField typeFld = flagType.getAddressField("_type");
+    AddressField nameFld = flagType.getAddressField("_name");
+    AddressField addrFld = flagType.getAddressField("_addr");
+    CIntField flagsFld = new CIntField(flagType.getCIntegerField("_flags"), 0);
 
     long flagSize = flagType.getSize(); // sizeof(Flag)
 
@@ -856,9 +848,8 @@
       String type = CStringUtilities.getString(typeFld.getValue(flagAddr));
       String name = CStringUtilities.getString(nameFld.getValue(flagAddr));
       Address addr = addrFld.getValue(flagAddr);
-      String kind = CStringUtilities.getString(kindFld.getValue(flagAddr));
-      int origin = (int)originFld.getValue(flagAddr);
-      commandLineFlags[f] = new Flag(type, name, addr, kind, origin);
+      int flags = (int)flagsFld.getValue(flagAddr);
+      commandLineFlags[f] = new Flag(type, name, addr, flags);
       flagAddr = flagAddr.addOffsetTo(flagSize);
     }
 
--- a/src/cpu/sparc/vm/sparc.ad	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/cpu/sparc/vm/sparc.ad	Fri Sep 27 12:43:51 2013 -0700
@@ -2018,6 +2018,15 @@
   return L7_REGP_mask();
 }
 
+const RegMask Matcher::mathExactI_result_proj_mask() {
+  return G1_REGI_mask();
+}
+
+const RegMask Matcher::mathExactI_flags_proj_mask() {
+  return INT_FLAGS_mask();
+}
+
+
 %}
 
 
@@ -4245,12 +4254,16 @@
     greater_equal(0xB);
     less_equal(0x2);
     greater(0xA);
+    overflow(0x7);
+    no_overflow(0xF);
   %}
 %}
 
 // Comparison Op, unsigned
 operand cmpOpU() %{
   match(Bool);
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
 
   format %{ "u" %}
   interface(COND_INTER) %{
@@ -4260,12 +4273,16 @@
     greater_equal(0xD);
     less_equal(0x4);
     greater(0xC);
+    overflow(0x7);
+    no_overflow(0xF);
   %}
 %}
 
 // Comparison Op, pointer (same as unsigned)
 operand cmpOpP() %{
   match(Bool);
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
 
   format %{ "p" %}
   interface(COND_INTER) %{
@@ -4275,12 +4292,16 @@
     greater_equal(0xD);
     less_equal(0x4);
     greater(0xC);
+    overflow(0x7);
+    no_overflow(0xF);
   %}
 %}
 
 // Comparison Op, branch-register encoding
 operand cmpOp_reg() %{
   match(Bool);
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
 
   format %{ "" %}
   interface(COND_INTER) %{
@@ -4290,12 +4311,16 @@
     greater_equal(0x7);
     less_equal   (0x2);
     greater      (0x6);
+    overflow(0x7); // not supported
+    no_overflow(0xF); // not supported
   %}
 %}
 
 // Comparison Code, floating, unordered same as less
 operand cmpOpF() %{
   match(Bool);
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
 
   format %{ "fl" %}
   interface(COND_INTER) %{
@@ -4305,12 +4330,17 @@
     greater_equal(0xB);
     less_equal(0xE);
     greater(0x6);
+
+    overflow(0x7); // not supported
+    no_overflow(0xF); // not supported
   %}
 %}
 
 // Used by long compare
 operand cmpOp_commute() %{
   match(Bool);
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
 
   format %{ "" %}
   interface(COND_INTER) %{
@@ -4320,6 +4350,8 @@
     greater_equal(0x2);
     less_equal(0xB);
     greater(0x3);
+    overflow(0x7);
+    no_overflow(0xF);
   %}
 %}
 
--- a/src/cpu/x86/vm/x86_32.ad	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/cpu/x86/vm/x86_32.ad	Fri Sep 27 12:43:51 2013 -0700
@@ -1534,6 +1534,14 @@
   return EBP_REG_mask();
 }
 
+const RegMask Matcher::mathExactI_result_proj_mask() {
+  return EAX_REG_mask();
+}
+
+const RegMask Matcher::mathExactI_flags_proj_mask() {
+  return INT_FLAGS_mask();
+}
+
 // Returns true if the high 32 bits of the value is known to be zero.
 bool is_operand_hi32_zero(Node* n) {
   int opc = n->Opcode();
@@ -4922,6 +4930,8 @@
     greater_equal(0xD, "ge");
     less_equal(0xE, "le");
     greater(0xF, "g");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4939,6 +4949,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4957,6 +4969,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4974,6 +4988,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4981,6 +4997,8 @@
 operand cmpOp_fcmov() %{
   match(Bool);
 
+  predicate(n->as_Bool()->_test._test != BoolTest::overflow &&
+            n->as_Bool()->_test._test != BoolTest::no_overflow);
   format %{ "" %}
   interface(COND_INTER) %{
     equal        (0x0C8);
@@ -4989,6 +5007,8 @@
     greater_equal(0x1C0);
     less_equal   (0x0D0);
     greater      (0x1D0);
+    overflow(0x0, "o"); // not really supported by the instruction
+    no_overflow(0x1, "no"); // not really supported by the instruction
   %}
 %}
 
@@ -5004,6 +5024,8 @@
     greater_equal(0xE, "le");
     less_equal(0xD, "ge");
     greater(0xC, "l");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -7496,6 +7518,31 @@
 
 //----------Arithmetic Instructions--------------------------------------------
 //----------Addition Instructions----------------------------------------------
+
+instruct addExactI_rReg(eAXRegI dst, rRegI src, eFlagsReg cr)
+%{
+  match(AddExactI dst src);
+  effect(DEF cr);
+
+  format %{ "ADD    $dst, $src\t# addExact int" %}
+  ins_encode %{
+    __ addl($dst$$Register, $src$$Register);
+  %}
+  ins_pipe(ialu_reg_reg);
+%}
+
+instruct addExactI_rReg_imm(eAXRegI dst, immI src, eFlagsReg cr)
+%{
+  match(AddExactI dst src);
+  effect(DEF cr);
+
+  format %{ "ADD    $dst, $src\t# addExact int" %}
+  ins_encode %{
+    __ addl($dst$$Register, $src$$constant);
+  %}
+  ins_pipe(ialu_reg_reg);
+%}
+
 // Integer Addition Instructions
 instruct addI_eReg(rRegI dst, rRegI src, eFlagsReg cr) %{
   match(Set dst (AddI dst src));
--- a/src/cpu/x86/vm/x86_64.ad	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/cpu/x86/vm/x86_64.ad	Fri Sep 27 12:43:51 2013 -0700
@@ -1649,6 +1649,14 @@
   return PTR_RBP_REG_mask();
 }
 
+const RegMask Matcher::mathExactI_result_proj_mask() {
+  return INT_RAX_REG_mask();
+}
+
+const RegMask Matcher::mathExactI_flags_proj_mask() {
+  return INT_FLAGS_mask();
+}
+
 %}
 
 //----------ENCODING BLOCK-----------------------------------------------------
@@ -4133,6 +4141,8 @@
     greater_equal(0xD, "ge");
     less_equal(0xE, "le");
     greater(0xF, "g");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4151,6 +4161,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4170,6 +4182,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -4187,6 +4201,8 @@
     greater_equal(0x3, "nb");
     less_equal(0x6, "be");
     greater(0x7, "nbe");
+    overflow(0x0, "o");
+    no_overflow(0x1, "no");
   %}
 %}
 
@@ -6922,6 +6938,30 @@
 //----------Arithmetic Instructions--------------------------------------------
 //----------Addition Instructions----------------------------------------------
 
+instruct addExactI_rReg(rax_RegI dst, rRegI src, rFlagsReg cr)
+%{
+  match(AddExactI dst src);
+  effect(DEF cr);
+
+  format %{ "addl    $dst, $src\t# addExact int" %}
+  ins_encode %{
+    __ addl($dst$$Register, $src$$Register);
+  %}
+  ins_pipe(ialu_reg_reg);
+%}
+
+instruct addExactI_rReg_imm(rax_RegI dst, immI src, rFlagsReg cr)
+%{
+  match(AddExactI dst src);
+  effect(DEF cr);
+
+  format %{ "addl    $dst, $src\t# addExact int" %}
+  ins_encode %{
+    __ addl($dst$$Register, $src$$constant);
+  %}
+  ins_pipe(ialu_reg_reg);
+%}
+
 instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
 %{
   match(Set dst (AddI dst src));
--- a/src/share/vm/adlc/adlparse.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/adlc/adlparse.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -3395,12 +3395,16 @@
   char *greater_equal;
   char *less_equal;
   char *greater;
+  char *overflow;
+  char *no_overflow;
   const char *equal_format = "eq";
   const char *not_equal_format = "ne";
   const char *less_format = "lt";
   const char *greater_equal_format = "ge";
   const char *less_equal_format = "le";
   const char *greater_format = "gt";
+  const char *overflow_format = "o";
+  const char *no_overflow_format = "no";
 
   if (_curchar != '%') {
     parse_err(SYNERR, "Missing '%%{' for 'cond_interface' block.\n");
@@ -3437,6 +3441,12 @@
     else if ( strcmp(field,"greater") == 0 ) {
       greater = interface_field_parse(&greater_format);
     }
+    else if ( strcmp(field,"overflow") == 0 ) {
+      overflow = interface_field_parse(&overflow_format);
+    }
+    else if ( strcmp(field,"no_overflow") == 0 ) {
+      no_overflow = interface_field_parse(&no_overflow_format);
+    }
     else {
       parse_err(SYNERR, "Expected keyword, base|index|scale|disp,  or '%%}' ending interface.\n");
       return NULL;
@@ -3455,7 +3465,9 @@
                                        less,          less_format,
                                        greater_equal, greater_equal_format,
                                        less_equal,    less_equal_format,
-                                       greater,       greater_format);
+                                       greater,       greater_format,
+                                       overflow,      overflow_format,
+                                       no_overflow,   no_overflow_format);
   return inter;
 }
 
--- a/src/share/vm/adlc/archDesc.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/adlc/archDesc.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -1192,6 +1192,8 @@
          || strcmp(idealName,"CmpF") == 0
          || strcmp(idealName,"FastLock") == 0
          || strcmp(idealName,"FastUnlock") == 0
+         || strcmp(idealName,"AddExactI") == 0
+         || strcmp(idealName,"FlagsProj") == 0
          || strcmp(idealName,"Bool") == 0
          || strcmp(idealName,"Binary") == 0 ) {
       // Removed ConI from the must_clone list.  CPUs that cannot use
--- a/src/share/vm/adlc/formssel.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/adlc/formssel.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -2757,14 +2757,18 @@
                              const char* less,          const char* less_format,
                              const char* greater_equal, const char* greater_equal_format,
                              const char* less_equal,    const char* less_equal_format,
-                             const char* greater,       const char* greater_format)
+                             const char* greater,       const char* greater_format,
+                             const char* overflow,      const char* overflow_format,
+                             const char* no_overflow,   const char* no_overflow_format)
   : Interface("COND_INTER"),
     _equal(equal),                 _equal_format(equal_format),
     _not_equal(not_equal),         _not_equal_format(not_equal_format),
     _less(less),                   _less_format(less_format),
     _greater_equal(greater_equal), _greater_equal_format(greater_equal_format),
     _less_equal(less_equal),       _less_equal_format(less_equal_format),
-    _greater(greater),             _greater_format(greater_format) {
+    _greater(greater),             _greater_format(greater_format),
+    _overflow(overflow),           _overflow_format(overflow_format),
+    _no_overflow(no_overflow),     _no_overflow_format(no_overflow_format) {
 }
 CondInterface::~CondInterface() {
   // not owner of any character arrays
@@ -2777,12 +2781,14 @@
 // Write info to output files
 void CondInterface::output(FILE *fp) {
   Interface::output(fp);
-  if ( _equal  != NULL )     fprintf(fp," equal       == %s\n", _equal);
-  if ( _not_equal  != NULL ) fprintf(fp," not_equal   == %s\n", _not_equal);
-  if ( _less  != NULL )      fprintf(fp," less        == %s\n", _less);
-  if ( _greater_equal  != NULL ) fprintf(fp," greater_equal   == %s\n", _greater_equal);
-  if ( _less_equal  != NULL ) fprintf(fp," less_equal  == %s\n", _less_equal);
-  if ( _greater  != NULL )    fprintf(fp," greater     == %s\n", _greater);
+  if ( _equal  != NULL )     fprintf(fp," equal        == %s\n", _equal);
+  if ( _not_equal  != NULL ) fprintf(fp," not_equal    == %s\n", _not_equal);
+  if ( _less  != NULL )      fprintf(fp," less         == %s\n", _less);
+  if ( _greater_equal  != NULL ) fprintf(fp," greater_equal    == %s\n", _greater_equal);
+  if ( _less_equal  != NULL ) fprintf(fp," less_equal   == %s\n", _less_equal);
+  if ( _greater  != NULL )    fprintf(fp," greater      == %s\n", _greater);
+  if ( _overflow != NULL )    fprintf(fp," overflow     == %s\n", _overflow);
+  if ( _no_overflow != NULL ) fprintf(fp," no_overflow  == %s\n", _no_overflow);
   // fprintf(fp,"\n");
 }
 
--- a/src/share/vm/adlc/formssel.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/adlc/formssel.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -798,12 +798,16 @@
   const char *_greater_equal;
   const char *_less_equal;
   const char *_greater;
+  const char *_overflow;
+  const char *_no_overflow;
   const char *_equal_format;
   const char *_not_equal_format;
   const char *_less_format;
   const char *_greater_equal_format;
   const char *_less_equal_format;
   const char *_greater_format;
+  const char *_overflow_format;
+  const char *_no_overflow_format;
 
   // Public Methods
   CondInterface(const char* equal,         const char* equal_format,
@@ -811,7 +815,9 @@
                 const char* less,          const char* less_format,
                 const char* greater_equal, const char* greater_equal_format,
                 const char* less_equal,    const char* less_equal_format,
-                const char* greater,       const char* greater_format);
+                const char* greater,       const char* greater_format,
+                const char* overflow,      const char* overflow_format,
+                const char* no_overflow,   const char* no_overflow_format);
   ~CondInterface();
 
   void dump();
--- a/src/share/vm/adlc/output_h.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/adlc/output_h.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -388,6 +388,8 @@
   fprintf(fp, "  else if( _c%d == BoolTest::ge ) st->print(\"%s\");\n",i,cond->_greater_equal_format);
   fprintf(fp, "  else if( _c%d == BoolTest::lt ) st->print(\"%s\");\n",i,cond->_less_format);
   fprintf(fp, "  else if( _c%d == BoolTest::gt ) st->print(\"%s\");\n",i,cond->_greater_format);
+  fprintf(fp, "  else if( _c%d == BoolTest::overflow ) st->print(\"%s\");\n",i,cond->_overflow_format);
+  fprintf(fp, "  else if( _c%d == BoolTest::no_overflow ) st->print(\"%s\");\n",i,cond->_no_overflow_format);
 }
 
 // Output code that dumps constant values, increment "i" if type is constant
@@ -1208,6 +1210,8 @@
       fprintf(fp,"    case  BoolTest::ne : return not_equal();\n");
       fprintf(fp,"    case  BoolTest::le : return less_equal();\n");
       fprintf(fp,"    case  BoolTest::ge : return greater_equal();\n");
+      fprintf(fp,"    case  BoolTest::overflow : return overflow();\n");
+      fprintf(fp,"    case  BoolTest::no_overflow: return no_overflow();\n");
       fprintf(fp,"    default : ShouldNotReachHere(); return 0;\n");
       fprintf(fp,"    }\n");
       fprintf(fp,"  };\n");
@@ -1373,6 +1377,14 @@
         if( greater != NULL ) {
           define_oper_interface(fp, *oper, _globalNames, "greater", greater);
         }
+        const char *overflow = cInterface->_overflow;
+        if( overflow != NULL ) {
+          define_oper_interface(fp, *oper, _globalNames, "overflow", overflow);
+        }
+        const char *no_overflow = cInterface->_no_overflow;
+        if( no_overflow != NULL ) {
+          define_oper_interface(fp, *oper, _globalNames, "no_overflow", no_overflow);
+        }
       } // end Conditional Interface
       // Check if it is a Constant Interface
       else if (oper->_interface->is_ConstInterface() != NULL ) {
--- a/src/share/vm/classfile/vmSymbols.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/classfile/vmSymbols.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -631,6 +631,10 @@
   do_name(log_name,"log")       do_name(log10_name,"log10")     do_name(pow_name,"pow")                                 \
   do_name(exp_name,"exp")       do_name(min_name,"min")         do_name(max_name,"max")                                 \
                                                                                                                         \
+  do_name(addExact_name,"addExact")                                                                                     \
+  do_name(subtractExact_name,"subtractExact")                                                                           \
+  do_name(multiplyExact_name,"multiplyExact")                                                                           \
+                                                                                                                        \
   do_intrinsic(_dabs,                     java_lang_Math,         abs_name,   double_double_signature,           F_S)   \
   do_intrinsic(_dsin,                     java_lang_Math,         sin_name,   double_double_signature,           F_S)   \
   do_intrinsic(_dcos,                     java_lang_Math,         cos_name,   double_double_signature,           F_S)   \
@@ -643,6 +647,7 @@
   do_intrinsic(_dexp,                     java_lang_Math,         exp_name,   double_double_signature,           F_S)   \
   do_intrinsic(_min,                      java_lang_Math,         min_name,   int2_int_signature,                F_S)   \
   do_intrinsic(_max,                      java_lang_Math,         max_name,   int2_int_signature,                F_S)   \
+  do_intrinsic(_addExact,                 java_lang_Math,         addExact_name, int2_int_signature,             F_S)   \
                                                                                                                         \
   do_intrinsic(_floatToRawIntBits,        java_lang_Float,        floatToRawIntBits_name,   float_int_signature, F_S)   \
    do_name(     floatToRawIntBits_name,                          "floatToRawIntBits")                                   \
--- a/src/share/vm/opto/c2_globals.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/c2_globals.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -636,7 +636,9 @@
                                                                             \
   diagnostic(bool, OptimizeExpensiveOps, true,                              \
           "Find best control for expensive operations")                     \
-
+                                                                            \
+  product(bool, UseMathExactIntrinsics, true,                               \
+          "Enables intrinsification of various java.lang.Math funcitons")
 
 C2_FLAGS(DECLARE_DEVELOPER_FLAG, DECLARE_PD_DEVELOPER_FLAG, DECLARE_PRODUCT_FLAG, DECLARE_PD_PRODUCT_FLAG, DECLARE_DIAGNOSTIC_FLAG, DECLARE_EXPERIMENTAL_FLAG, DECLARE_NOTPRODUCT_FLAG)
 
--- a/src/share/vm/opto/classes.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/classes.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -32,6 +32,7 @@
 #include "opto/loopnode.hpp"
 #include "opto/machnode.hpp"
 #include "opto/memnode.hpp"
+#include "opto/mathexactnode.hpp"
 #include "opto/mulnode.hpp"
 #include "opto/multnode.hpp"
 #include "opto/node.hpp"
--- a/src/share/vm/opto/classes.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/classes.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -29,6 +29,7 @@
 macro(AbsF)
 macro(AbsI)
 macro(AddD)
+macro(AddExactI)
 macro(AddF)
 macro(AddI)
 macro(AddL)
@@ -133,6 +134,7 @@
 macro(ExpD)
 macro(FastLock)
 macro(FastUnlock)
+macro(FlagsProj)
 macro(Goto)
 macro(Halt)
 macro(If)
@@ -167,6 +169,7 @@
 macro(LoopLimit)
 macro(Mach)
 macro(MachProj)
+macro(MathExact)
 macro(MaxI)
 macro(MemBarAcquire)
 macro(MemBarAcquireLock)
--- a/src/share/vm/opto/ifnode.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/ifnode.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -76,6 +76,7 @@
   if( !i1->is_Bool() ) return NULL;
   BoolNode *b = i1->as_Bool();
   Node *cmp = b->in(1);
+  if( cmp->is_FlagsProj() ) return NULL;
   if( !cmp->is_Cmp() ) return NULL;
   i1 = cmp->in(1);
   if( i1 == NULL || !i1->is_Phi() ) return NULL;
--- a/src/share/vm/opto/lcm.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/lcm.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -472,6 +472,13 @@
           break;
         }
 
+        // For nodes that produce a FlagsProj, make the node adjacent to the
+        // use of the FlagsProj
+        if (use->is_FlagsProj() && get_block_for_node(use) == block) {
+          found_machif = true;
+          break;
+        }
+
         // More than this instruction pending for successor to be ready,
         // don't choose this if other opportunities are ready
         if (ready_cnt.at(use->_idx) > 1)
--- a/src/share/vm/opto/library_call.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/library_call.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -32,6 +32,7 @@
 #include "opto/callGenerator.hpp"
 #include "opto/cfgnode.hpp"
 #include "opto/idealKit.hpp"
+#include "opto/mathexactnode.hpp"
 #include "opto/mulnode.hpp"
 #include "opto/parse.hpp"
 #include "opto/runtime.hpp"
@@ -199,6 +200,8 @@
   bool inline_math_native(vmIntrinsics::ID id);
   bool inline_trig(vmIntrinsics::ID id);
   bool inline_math(vmIntrinsics::ID id);
+  bool inline_math_mathExact(Node* math);
+  bool inline_math_addExact();
   bool inline_exp();
   bool inline_pow();
   void finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName);
@@ -498,6 +501,15 @@
     if (!UseCRC32Intrinsics) return NULL;
     break;
 
+  case vmIntrinsics::_addExact:
+    if (!Matcher::match_rule_supported(Op_AddExactI)) {
+      return NULL;
+    }
+    if (!UseMathExactIntrinsics) {
+      return NULL;
+    }
+    break;
+
  default:
     assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
     assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
@@ -668,6 +680,8 @@
   case vmIntrinsics::_min:
   case vmIntrinsics::_max:                      return inline_min_max(intrinsic_id());
 
+  case vmIntrinsics::_addExact:                 return inline_math_addExact();
+
   case vmIntrinsics::_arraycopy:                return inline_arraycopy();
 
   case vmIntrinsics::_compareTo:                return inline_string_compareTo();
@@ -1911,6 +1925,45 @@
   return true;
 }
 
+bool LibraryCallKit::inline_math_mathExact(Node* math) {
+  Node* result = _gvn.transform( new(C) ProjNode(math, MathExactNode::result_proj_node));
+  Node* flags = _gvn.transform( new(C) FlagsProjNode(math, MathExactNode::flags_proj_node));
+
+  Node* bol = _gvn.transform( new (C) BoolNode(flags, BoolTest::overflow) );
+  IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
+  Node* fast_path = _gvn.transform( new (C) IfFalseNode(check));
+  Node* slow_path = _gvn.transform( new (C) IfTrueNode(check) );
+
+  {
+    PreserveJVMState pjvms(this);
+    PreserveReexecuteState preexecs(this);
+    jvms()->set_should_reexecute(true);
+
+    set_control(slow_path);
+    set_i_o(i_o());
+
+    uncommon_trap(Deoptimization::Reason_intrinsic,
+                  Deoptimization::Action_none);
+  }
+
+  set_control(fast_path);
+  set_result(result);
+  return true;
+}
+
+bool LibraryCallKit::inline_math_addExact() {
+  Node* arg1 = argument(0);
+  Node* arg2 = argument(1);
+
+  Node* add = _gvn.transform( new(C) AddExactINode(NULL, arg1, arg2) );
+  if (add->Opcode() == Op_AddExactI) {
+    return inline_math_mathExact(add);
+  } else {
+    set_result(add);
+  }
+  return true;
+}
+
 Node*
 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
   // These are the candidate return value:
--- a/src/share/vm/opto/loopTransform.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/loopTransform.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -776,6 +776,9 @@
         continue; // not RC
 
       Node *cmp = bol->in(1);
+      if (cmp->is_FlagsProj()) {
+        continue;
+      }
 
       Node *rc_exp = cmp->in(1);
       Node *limit = cmp->in(2);
--- a/src/share/vm/opto/loopopts.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/loopopts.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -2355,7 +2355,8 @@
         opc == Op_Catch     ||
         opc == Op_CatchProj ||
         opc == Op_Jump      ||
-        opc == Op_JumpProj) {
+        opc == Op_JumpProj  ||
+        opc == Op_FlagsProj) {
 #if !defined(PRODUCT)
       if (TracePartialPeeling) {
         tty->print_cr("\nExit control too complex: lp: %d", head->_idx);
--- a/src/share/vm/opto/matcher.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/matcher.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -1964,6 +1964,7 @@
       case Op_Catch:
       case Op_CatchProj:
       case Op_CProj:
+      case Op_FlagsProj:
       case Op_JumpProj:
       case Op_JProj:
       case Op_NeverBranch:
--- a/src/share/vm/opto/matcher.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/matcher.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -337,6 +337,9 @@
   // Register for MODL projection of divmodL
   static RegMask modL_proj_mask();
 
+  static const RegMask mathExactI_result_proj_mask();
+  static const RegMask mathExactI_flags_proj_mask();
+
   // Use hardware DIV instruction when it is faster than
   // a code which use multiply for division by constant.
   static bool use_asm_for_ldiv_by_con( jlong divisor );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/opto/mathexactnode.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2013, 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.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "memory/allocation.inline.hpp"
+#include "opto/addnode.hpp"
+#include "opto/machnode.hpp"
+#include "opto/mathexactnode.hpp"
+#include "opto/matcher.hpp"
+#include "opto/subnode.hpp"
+
+MathExactNode::MathExactNode(Node* ctrl, Node* n1, Node* n2) : MultiNode(3) {
+  init_req(0, ctrl);
+  init_req(1, n1);
+  init_req(2, n2);
+}
+
+Node* AddExactINode::match(const ProjNode* proj, const Matcher* m) {
+  uint ideal_reg = proj->ideal_reg();
+  RegMask rm;
+  if (proj->_con == result_proj_node) {
+    rm = m->mathExactI_result_proj_mask();
+  } else {
+    assert(proj->_con == flags_proj_node, "must be result or flags");
+    assert(ideal_reg == Op_RegFlags, "sanity");
+    rm = m->mathExactI_flags_proj_mask();
+  }
+  return new (m->C) MachProjNode(this, proj->_con, rm, ideal_reg);
+}
+
+// If the MathExactNode won't overflow we have to replace the
+// FlagsProjNode and ProjNode that is generated by the MathExactNode
+Node* MathExactNode::no_overflow(PhaseGVN *phase, Node* new_result) {
+  PhaseIterGVN *igvn = phase->is_IterGVN();
+  if (igvn) {
+    ProjNode* result = result_node();
+    ProjNode* flags = flags_node();
+
+    if (result != NULL) {
+      igvn->replace_node(result, new_result);
+    }
+
+    if (flags != NULL) {
+      BoolNode* bolnode = (BoolNode *) flags->unique_out();
+      switch (bolnode->_test._test) {
+        case BoolTest::overflow:
+          // if the check is for overflow - never taken
+          igvn->replace_node(bolnode, phase->intcon(0));
+          break;
+        case BoolTest::no_overflow:
+          // if the check is for no overflow - always taken
+          igvn->replace_node(bolnode, phase->intcon(1));
+          break;
+        default:
+          fatal("Unexpected value of BoolTest");
+          break;
+      }
+      flags->del_req(0);
+    }
+  }
+  return new_result;
+}
+
+Node *AddExactINode::Ideal(PhaseGVN *phase, bool can_reshape) {
+  Node *arg1 = in(1);
+  Node *arg2 = in(2);
+
+  const Type* type1 = phase->type(arg1);
+  const Type* type2 = phase->type(arg2);
+
+  if (type1 != Type::TOP && type1->singleton() &&
+      type2 != Type::TOP && type2->singleton()) {
+    jint val1 = arg1->get_int();
+    jint val2 = arg2->get_int();
+    jint result = val1 + val2;
+    // Hacker's Delight 2-12 Overflow if both arguments have the opposite sign of the result
+    if ( (((val1 ^ result) & (val2 ^ result)) >= 0)) {
+      Node* con_result = ConINode::make(phase->C, result);
+      return no_overflow(phase, con_result);
+    }
+    return NULL;
+  }
+
+  if (type1 == TypeInt::ZERO) { // (Add 0 x) == x
+    Node* add_result = new (phase->C) AddINode(arg1, arg2);
+    return no_overflow(phase, add_result);
+  }
+
+  if (type2 == TypeInt::ZERO) { // (Add x 0) == x
+    Node* add_result = new (phase->C) AddINode(arg1, arg2);
+    return no_overflow(phase, add_result);
+  }
+
+  if (type2->singleton()) {
+    return NULL; // no change - keep constant on the right
+  }
+
+  if (type1->singleton()) {
+    // Make it x + Constant - move constant to the right
+    swap_edges(1, 2);
+    return this;
+  }
+
+  if (arg2->is_Load()) {
+    return NULL; // no change - keep load on the right
+  }
+
+  if (arg1->is_Load()) {
+    // Make it x + Load - move load to the right
+    swap_edges(1, 2);
+    return this;
+  }
+
+  if (arg1->_idx > arg2->_idx) {
+    // Sort the edges
+    swap_edges(1, 2);
+    return this;
+  }
+
+  return NULL;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/vm/opto/mathexactnode.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013, 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_VM_OPTO_MATHEXACTNODE_HPP
+#define SHARE_VM_OPTO_MATHEXACTNODE_HPP
+
+#include "opto/multnode.hpp"
+#include "opto/node.hpp"
+#include "opto/type.hpp"
+
+class Node;
+
+class PhaseGVN;
+class PhaseTransform;
+
+class MathExactNode : public MultiNode {
+public:
+  MathExactNode(Node* ctrl, Node* in1, Node* in2);
+  enum {
+    result_proj_node = 0,
+    flags_proj_node = 1
+  };
+  virtual int Opcode() const;
+  virtual Node* Identity(PhaseTransform* phase) { return this; }
+  virtual Node* Ideal(PhaseGVN* phase, bool can_reshape) { return NULL; }
+  virtual const Type* Value(PhaseTransform* phase) const { return bottom_type(); }
+  virtual uint hash() const { return Node::hash(); }
+  virtual bool is_CFG() const { return false; }
+  virtual uint ideal_reg() const { return NotAMachineReg; }
+
+  ProjNode* result_node() { return proj_out(result_proj_node); }
+  ProjNode* flags_node() { return proj_out(flags_proj_node); }
+protected:
+  Node* no_overflow(PhaseGVN *phase, Node* new_result);
+};
+
+class AddExactINode : public MathExactNode {
+public:
+  AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
+  virtual int Opcode() const;
+  virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; }
+  virtual Node* match(const ProjNode* proj, const Matcher* m);
+  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
+};
+
+class FlagsProjNode : public ProjNode {
+public:
+  FlagsProjNode(Node* src, uint con) : ProjNode(src, con) {
+    init_class_id(Class_FlagsProj);
+  }
+
+  virtual int Opcode() const;
+  virtual bool is_CFG() const { return false; }
+  virtual const Type* bottom_type() const { return TypeInt::CC; }
+  virtual uint ideal_reg() const { return Op_RegFlags; }
+};
+
+
+#endif
+
--- a/src/share/vm/opto/multnode.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/multnode.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "opto/callnode.hpp"
 #include "opto/matcher.hpp"
+#include "opto/mathexactnode.hpp"
 #include "opto/multnode.hpp"
 #include "opto/opcodes.hpp"
 #include "opto/phaseX.hpp"
@@ -46,15 +47,21 @@
   assert(Opcode() != Op_If || outcnt() == 2, "bad if #1");
   for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
     Node *p = fast_out(i);
-    if( !p->is_Proj() ) {
+    if (p->is_Proj()) {
+      ProjNode *proj = p->as_Proj();
+      if (proj->_con == which_proj) {
+        assert(Opcode() != Op_If || proj->Opcode() == (which_proj?Op_IfTrue:Op_IfFalse), "bad if #2");
+        return proj;
+      }
+    } else if (p->is_FlagsProj()) {
+      FlagsProjNode *proj = p->as_FlagsProj();
+      if (proj->_con == which_proj) {
+        return proj;
+      }
+    } else {
       assert(p == this && this->is_Start(), "else must be proj");
       continue;
     }
-    ProjNode *proj = p->as_Proj();
-    if( proj->_con == which_proj ) {
-      assert(Opcode() != Op_If || proj->Opcode() == (which_proj?Op_IfTrue:Op_IfFalse), "bad if #2");
-      return proj;
-    }
   }
   return NULL;
 }
--- a/src/share/vm/opto/node.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/node.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -69,6 +69,7 @@
 class EncodePKlassNode;
 class FastLockNode;
 class FastUnlockNode;
+class FlagsProjNode;
 class IfNode;
 class IfFalseNode;
 class IfTrueNode;
@@ -623,6 +624,7 @@
       DEFINE_CLASS_ID(Cmp,   Sub, 0)
         DEFINE_CLASS_ID(FastLock,   Cmp, 0)
         DEFINE_CLASS_ID(FastUnlock, Cmp, 1)
+        DEFINE_CLASS_ID(FlagsProj, Cmp, 2)
 
     DEFINE_CLASS_ID(MergeMem, Node, 7)
     DEFINE_CLASS_ID(Bool,     Node, 8)
@@ -726,6 +728,7 @@
   DEFINE_CLASS_QUERY(EncodePKlass)
   DEFINE_CLASS_QUERY(FastLock)
   DEFINE_CLASS_QUERY(FastUnlock)
+  DEFINE_CLASS_QUERY(FlagsProj)
   DEFINE_CLASS_QUERY(If)
   DEFINE_CLASS_QUERY(IfFalse)
   DEFINE_CLASS_QUERY(IfTrue)
--- a/src/share/vm/opto/subnode.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/subnode.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -1064,7 +1064,7 @@
 // Print special per-node info
 #ifndef PRODUCT
 void BoolTest::dump_on(outputStream *st) const {
-  const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
+  const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"};
   st->print(msg[_test]);
 }
 #endif
@@ -1126,7 +1126,7 @@
   Node *cmp = in(1);
   if( !cmp->is_Sub() ) return NULL;
   int cop = cmp->Opcode();
-  if( cop == Op_FastLock || cop == Op_FastUnlock ) return NULL;
+  if( cop == Op_FastLock || cop == Op_FastUnlock || cop == Op_FlagsProj) return NULL;
   Node *cmp1 = cmp->in(1);
   Node *cmp2 = cmp->in(2);
   if( !cmp1 ) return NULL;
--- a/src/share/vm/opto/subnode.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/subnode.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -263,16 +263,16 @@
 // We pick the values as 3 bits; the low order 2 bits we compare against the
 // condition codes, the high bit flips the sense of the result.
 struct BoolTest VALUE_OBJ_CLASS_SPEC {
-  enum mask { eq = 0, ne = 4, le = 5, ge = 7, lt = 3, gt = 1, illegal = 8 };
+  enum mask { eq = 0, ne = 4, le = 5, ge = 7, lt = 3, gt = 1, overflow = 2, no_overflow = 6, illegal = 8 };
   mask _test;
   BoolTest( mask btm ) : _test(btm) {}
   const Type *cc2logical( const Type *CC ) const;
   // Commute the test.  I use a small table lookup.  The table is created as
   // a simple char array where each element is the ASCII version of a 'mask'
   // enum from above.
-  mask commute( ) const { return mask("038147858"[_test]-'0'); }
+  mask commute( ) const { return mask("032147658"[_test]-'0'); }
   mask negate( ) const { return mask(_test^4); }
-  bool is_canonical( ) const { return (_test == BoolTest::ne || _test == BoolTest::lt || _test == BoolTest::le); }
+  bool is_canonical( ) const { return (_test == BoolTest::ne || _test == BoolTest::lt || _test == BoolTest::le || _test == BoolTest::overflow); }
 #ifndef PRODUCT
   void dump_on(outputStream *st) const;
 #endif
--- a/src/share/vm/opto/type.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/type.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -430,6 +430,11 @@
   longpair[1] = TypeLong::LONG;
   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 
+  const Type **intccpair = TypeTuple::fields(2);
+  intccpair[0] = TypeInt::INT;
+  intccpair[1] = TypeInt::CC;
+  TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
+
   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
@@ -1646,6 +1651,7 @@
 const TypeTuple *TypeTuple::START_I2C;
 const TypeTuple *TypeTuple::INT_PAIR;
 const TypeTuple *TypeTuple::LONG_PAIR;
+const TypeTuple *TypeTuple::INT_CC_PAIR;
 
 
 //------------------------------make-------------------------------------------
--- a/src/share/vm/opto/type.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/opto/type.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -584,6 +584,7 @@
   static const TypeTuple *START_I2C;
   static const TypeTuple *INT_PAIR;
   static const TypeTuple *LONG_PAIR;
+  static const TypeTuple *INT_CC_PAIR;
 #ifndef PRODUCT
   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 #endif
--- a/src/share/vm/prims/jvm.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/prims/jvm.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -4226,13 +4226,13 @@
 
 JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get))
   JVMWrapper("JVM_AccessBoolVMFlag");
-  return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, INTERNAL);
+  return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, Flag::INTERNAL);
 JVM_END
 
 JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get))
   JVMWrapper("JVM_AccessVMIntFlag");
   intx v;
-  jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, INTERNAL);
+  jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, Flag::INTERNAL);
   *value = (jint)v;
   return result;
 JVM_END
--- a/src/share/vm/runtime/arguments.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/arguments.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -625,11 +625,11 @@
   }
 }
 
-static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
+static bool set_bool_flag(char* name, bool value, Flag::Flags origin) {
   return CommandLineFlags::boolAtPut(name, &value, origin);
 }
 
-static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
+static bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) {
   double v;
   if (sscanf(value, "%lf", &v) != 1) {
     return false;
@@ -641,7 +641,7 @@
   return false;
 }
 
-static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
+static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
   julong v;
   intx intx_v;
   bool is_neg = false;
@@ -674,14 +674,14 @@
   return false;
 }
 
-static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
+static bool set_string_flag(char* name, const char* value, Flag::Flags origin) {
   if (!CommandLineFlags::ccstrAtPut(name, &value, origin))  return false;
   // Contract:  CommandLineFlags always returns a pointer that needs freeing.
   FREE_C_HEAP_ARRAY(char, value, mtInternal);
   return true;
 }
 
-static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
+static bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) {
   const char* old_value = "";
   if (!CommandLineFlags::ccstrAt(name, &old_value))  return false;
   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
@@ -709,7 +709,7 @@
   return true;
 }
 
-bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
+bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
 
   // range of acceptable characters spelled out for portability reasons
 #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
@@ -850,7 +850,7 @@
 }
 
 bool Arguments::process_argument(const char* arg,
-    jboolean ignore_unrecognized, FlagValueOrigin origin) {
+    jboolean ignore_unrecognized, Flag::Flags origin) {
 
   JDK_Version since = JDK_Version();
 
@@ -904,7 +904,7 @@
       jio_fprintf(defaultStream::error_stream(),
                   "Did you mean '%s%s%s'?\n",
                   (fuzzy_matched->is_bool()) ? "(+/-)" : "",
-                  fuzzy_matched->name,
+                  fuzzy_matched->_name,
                   (fuzzy_matched->is_bool()) ? "" : "=<value>");
     }
   }
@@ -952,7 +952,7 @@
         // this allows a way to include spaces in string-valued options
         token[pos] = '\0';
         logOption(token);
-        result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
+        result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE);
         build_jvm_flags(token);
         pos = 0;
         in_white_space = true;
@@ -970,7 +970,7 @@
   }
   if (pos > 0) {
     token[pos] = '\0';
-    result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
+    result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE);
     build_jvm_flags(token);
   }
   fclose(stream);
@@ -2438,7 +2438,7 @@
   }
 
   // Parse JavaVMInitArgs structure passed in
-  result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
+  result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE);
   if (result != JNI_OK) {
     return result;
   }
@@ -2510,7 +2510,7 @@
 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
                                        SysClassPath* scp_p,
                                        bool* scp_assembly_required_p,
-                                       FlagValueOrigin origin) {
+                                       Flag::Flags origin) {
   // Remaining part of option string
   const char* tail;
 
@@ -3333,7 +3333,7 @@
       }
     }
 
-    return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
+    return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR));
   }
   return JNI_OK;
 }
--- a/src/share/vm/runtime/arguments.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/arguments.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -360,15 +360,15 @@
 
   // Argument parsing
   static void do_pd_flag_adjustments();
-  static bool parse_argument(const char* arg, FlagValueOrigin origin);
-  static bool process_argument(const char* arg, jboolean ignore_unrecognized, FlagValueOrigin origin);
+  static bool parse_argument(const char* arg, Flag::Flags origin);
+  static bool process_argument(const char* arg, jboolean ignore_unrecognized, Flag::Flags origin);
   static void process_java_launcher_argument(const char*, void*);
   static void process_java_compiler_argument(char* arg);
   static jint parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p);
   static jint parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
   static jint parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p);
   static jint parse_vm_init_args(const JavaVMInitArgs* args);
-  static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, FlagValueOrigin origin);
+  static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, SysClassPath* scp_p, bool* scp_assembly_required_p, Flag::Flags origin);
   static jint finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required);
   static bool is_bad_option(const JavaVMOption* option, jboolean ignore,
     const char* option_type);
--- a/src/share/vm/runtime/globals.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/globals.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -62,26 +62,174 @@
 MATERIALIZE_FLAGS_EXT
 
 
+void Flag::check_writable() {
+  if (is_constant_in_binary()) {
+    fatal(err_msg("flag is constant: %s", _name));
+  }
+}
+
+bool Flag::is_bool() const {
+  return strcmp(_type, "bool") == 0;
+}
+
+bool Flag::get_bool() const {
+  return *((bool*) _addr);
+}
+
+void Flag::set_bool(bool value) {
+  check_writable();
+  *((bool*) _addr) = value;
+}
+
+bool Flag::is_intx() const {
+  return strcmp(_type, "intx")  == 0;
+}
+
+intx Flag::get_intx() const {
+  return *((intx*) _addr);
+}
+
+void Flag::set_intx(intx value) {
+  check_writable();
+  *((intx*) _addr) = value;
+}
+
+bool Flag::is_uintx() const {
+  return strcmp(_type, "uintx") == 0;
+}
+
+uintx Flag::get_uintx() const {
+  return *((uintx*) _addr);
+}
+
+void Flag::set_uintx(uintx value) {
+  check_writable();
+  *((uintx*) _addr) = value;
+}
+
+bool Flag::is_uint64_t() const {
+  return strcmp(_type, "uint64_t") == 0;
+}
+
+uint64_t Flag::get_uint64_t() const {
+  return *((uint64_t*) _addr);
+}
+
+void Flag::set_uint64_t(uint64_t value) {
+  check_writable();
+  *((uint64_t*) _addr) = value;
+}
+
+bool Flag::is_double() const {
+  return strcmp(_type, "double") == 0;
+}
+
+double Flag::get_double() const {
+  return *((double*) _addr);
+}
+
+void Flag::set_double(double value) {
+  check_writable();
+  *((double*) _addr) = value;
+}
+
+bool Flag::is_ccstr() const {
+  return strcmp(_type, "ccstr") == 0 || strcmp(_type, "ccstrlist") == 0;
+}
+
+bool Flag::ccstr_accumulates() const {
+  return strcmp(_type, "ccstrlist") == 0;
+}
+
+ccstr Flag::get_ccstr() const {
+  return *((ccstr*) _addr);
+}
+
+void Flag::set_ccstr(ccstr value) {
+  check_writable();
+  *((ccstr*) _addr) = value;
+}
+
+
+Flag::Flags Flag::get_origin() {
+  return Flags(_flags & VALUE_ORIGIN_MASK);
+}
+
+void Flag::set_origin(Flags origin) {
+  assert((origin & VALUE_ORIGIN_MASK) == origin, "sanity");
+  _flags = Flags((_flags & ~VALUE_ORIGIN_MASK) | origin);
+}
+
+bool Flag::is_default() {
+  return (get_origin() == DEFAULT);
+}
+
+bool Flag::is_ergonomic() {
+  return (get_origin() == ERGONOMIC);
+}
+
+bool Flag::is_command_line() {
+  return (get_origin() == COMMAND_LINE);
+}
+
+bool Flag::is_product() const {
+  return (_flags & KIND_PRODUCT) != 0;
+}
+
+bool Flag::is_manageable() const {
+  return (_flags & KIND_MANAGEABLE) != 0;
+}
+
+bool Flag::is_diagnostic() const {
+  return (_flags & KIND_DIAGNOSTIC) != 0;
+}
+
+bool Flag::is_experimental() const {
+  return (_flags & KIND_EXPERIMENTAL) != 0;
+}
+
+bool Flag::is_notproduct() const {
+  return (_flags & KIND_NOT_PRODUCT) != 0;
+}
+
+bool Flag::is_develop() const {
+  return (_flags & KIND_DEVELOP) != 0;
+}
+
+bool Flag::is_read_write() const {
+  return (_flags & KIND_READ_WRITE) != 0;
+}
+
+bool Flag::is_commercial() const {
+  return (_flags & KIND_COMMERCIAL) != 0;
+}
+
+/**
+ * Returns if this flag is a constant in the binary.  Right now this is
+ * true for notproduct and develop flags in product builds.
+ */
+bool Flag::is_constant_in_binary() const {
+#ifdef PRODUCT
+    return is_notproduct() || is_develop();
+#else
+    return false;
+#endif
+}
+
 bool Flag::is_unlocker() const {
-  return strcmp(name, "UnlockDiagnosticVMOptions") == 0     ||
-         strcmp(name, "UnlockExperimentalVMOptions") == 0   ||
+  return strcmp(_name, "UnlockDiagnosticVMOptions") == 0     ||
+         strcmp(_name, "UnlockExperimentalVMOptions") == 0   ||
          is_unlocker_ext();
 }
 
 bool Flag::is_unlocked() const {
-  if (strcmp(kind, "{diagnostic}") == 0 ||
-      strcmp(kind, "{C2 diagnostic}") == 0 ||
-      strcmp(kind, "{ARCH diagnostic}") == 0 ||
-      strcmp(kind, "{Shark diagnostic}") == 0) {
+  if (is_diagnostic()) {
     return UnlockDiagnosticVMOptions;
-  } else if (strcmp(kind, "{experimental}") == 0 ||
-             strcmp(kind, "{C2 experimental}") == 0 ||
-             strcmp(kind, "{ARCH experimental}") == 0 ||
-             strcmp(kind, "{Shark experimental}") == 0) {
+  }
+  if (is_experimental()) {
     return UnlockExperimentalVMOptions;
-  } else {
-    return is_unlocked_ext();
   }
+  return is_unlocked_ext();
 }
 
 // Get custom message for this locked flag, or return NULL if
@@ -91,16 +239,14 @@
 }
 
 bool Flag::is_writeable() const {
-  return strcmp(kind, "{manageable}") == 0 ||
-         strcmp(kind, "{product rw}") == 0 ||
-         is_writeable_ext();
+  return is_manageable() || (is_product() && is_read_write()) || is_writeable_ext();
 }
 
 // All flags except "manageable" are assumed to be internal flags.
 // Long term, we need to define a mechanism to specify which flags
 // are external/stable and change this function accordingly.
 bool Flag::is_external() const {
-  return strcmp(kind, "{manageable}") == 0 || is_external_ext();
+  return is_manageable() || is_external_ext();
 }
 
 
@@ -108,53 +254,113 @@
 #define FORMAT_BUFFER_LEN 16
 
 void Flag::print_on(outputStream* st, bool withComments) {
-  st->print("%9s %-40s %c= ", type, name, (origin != DEFAULT ? ':' : ' '));
-  if (is_bool())     st->print("%-16s", get_bool() ? "true" : "false");
-  if (is_intx())     st->print("%-16ld", get_intx());
-  if (is_uintx())    st->print("%-16lu", get_uintx());
-  if (is_uint64_t()) st->print("%-16lu", get_uint64_t());
-  if (is_double())   st->print("%-16f", get_double());
+  // Don't print notproduct and develop flags in a product build.
+  if (is_constant_in_binary()) {
+    return;
+  }
+
+  st->print("%9s %-40s %c= ", _type, _name, (!is_default() ? ':' : ' '));
 
+  if (is_bool()) {
+    st->print("%-16s", get_bool() ? "true" : "false");
+  }
+  if (is_intx()) {
+    st->print("%-16ld", get_intx());
+  }
+  if (is_uintx()) {
+    st->print("%-16lu", get_uintx());
+  }
+  if (is_uint64_t()) {
+    st->print("%-16lu", get_uint64_t());
+  }
+  if (is_double()) {
+    st->print("%-16f", get_double());
+  }
   if (is_ccstr()) {
-     const char* cp = get_ccstr();
-     if (cp != NULL) {
-       const char* eol;
-       while ((eol = strchr(cp, '\n')) != NULL) {
-         char format_buffer[FORMAT_BUFFER_LEN];
-         size_t llen = pointer_delta(eol, cp, sizeof(char));
-         jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
-                     "%%." SIZE_FORMAT "s", llen);
-         st->print(format_buffer, cp);
-         st->cr();
-         cp = eol+1;
-         st->print("%5s %-35s += ", "", name);
-       }
-       st->print("%-16s", cp);
-     }
-     else st->print("%-16s", "");
+    const char* cp = get_ccstr();
+    if (cp != NULL) {
+      const char* eol;
+      while ((eol = strchr(cp, '\n')) != NULL) {
+        char format_buffer[FORMAT_BUFFER_LEN];
+        size_t llen = pointer_delta(eol, cp, sizeof(char));
+        jio_snprintf(format_buffer, FORMAT_BUFFER_LEN,
+            "%%." SIZE_FORMAT "s", llen);
+        st->print(format_buffer, cp);
+        st->cr();
+        cp = eol+1;
+        st->print("%5s %-35s += ", "", _name);
+      }
+      st->print("%-16s", cp);
+    }
+    else st->print("%-16s", "");
   }
-  st->print("%-20s", kind);
+
+  st->print("%-20");
+  print_kind(st);
+
   if (withComments) {
 #ifndef PRODUCT
-    st->print("%s", doc );
+    st->print("%s", _doc);
 #endif
   }
   st->cr();
 }
 
+void Flag::print_kind(outputStream* st) {
+  struct Data {
+    int flag;
+    const char* name;
+  };
+
+  Data data[] = {
+      { KIND_C1, "C1" },
+      { KIND_C2, "C2" },
+      { KIND_ARCH, "ARCH" },
+      { KIND_SHARK, "SHARK" },
+      { KIND_PLATFORM_DEPENDENT, "pd" },
+      { KIND_PRODUCT, "product" },
+      { KIND_MANAGEABLE, "manageable" },
+      { KIND_DIAGNOSTIC, "diagnostic" },
+      { KIND_NOT_PRODUCT, "notproduct" },
+      { KIND_DEVELOP, "develop" },
+      { KIND_LP64_PRODUCT, "lp64_product" },
+      { KIND_READ_WRITE, "rw" },
+      { -1, "" }
+  };
+
+  if ((_flags & KIND_MASK) != 0) {
+    st->print("{");
+    bool is_first = true;
+
+    for (int i = 0; data[i].flag != -1; i++) {
+      Data d = data[i];
+      if ((_flags & d.flag) != 0) {
+        if (is_first) {
+          is_first = false;
+        } else {
+          st->print(" ");
+        }
+        st->print(d.name);
+      }
+    }
+
+    st->print("}");
+  }
+}
+
 void Flag::print_as_flag(outputStream* st) {
   if (is_bool()) {
-    st->print("-XX:%s%s", get_bool() ? "+" : "-", name);
+    st->print("-XX:%s%s", get_bool() ? "+" : "-", _name);
   } else if (is_intx()) {
-    st->print("-XX:%s=" INTX_FORMAT, name, get_intx());
+    st->print("-XX:%s=" INTX_FORMAT, _name, get_intx());
   } else if (is_uintx()) {
-    st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx());
+    st->print("-XX:%s=" UINTX_FORMAT, _name, get_uintx());
   } else if (is_uint64_t()) {
-    st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t());
+    st->print("-XX:%s=" UINT64_FORMAT, _name, get_uint64_t());
   } else if (is_double()) {
-    st->print("-XX:%s=%f", name, get_double());
+    st->print("-XX:%s=%f", _name, get_double());
   } else if (is_ccstr()) {
-    st->print("-XX:%s=", name);
+    st->print("-XX:%s=", _name);
     const char* cp = get_ccstr();
     if (cp != NULL) {
       // Need to turn embedded '\n's back into separate arguments
@@ -167,7 +373,7 @@
             st->print("%c", *cp);
             break;
           case '\n':
-            st->print(" -XX:%s=", name);
+            st->print(" -XX:%s=", _name);
             break;
         }
       }
@@ -180,79 +386,51 @@
 // 4991491 do not "optimize out" the was_set false values: omitting them
 // tickles a Microsoft compiler bug causing flagTable to be malformed
 
-#define RUNTIME_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product}", DEFAULT },
-#define RUNTIME_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{pd product}", DEFAULT },
-#define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{diagnostic}", DEFAULT },
-#define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{experimental}", DEFAULT },
-#define RUNTIME_MANAGEABLE_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{manageable}", DEFAULT },
-#define RUNTIME_PRODUCT_RW_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{product rw}", DEFAULT },
+#define NAME(name) NOT_PRODUCT(&name) PRODUCT_ONLY(&CONST_##name)
 
-#ifdef PRODUCT
-  #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
-  #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
-  #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
-#else
-  #define RUNTIME_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "", DEFAULT },
-  #define RUNTIME_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{pd}", DEFAULT },
-  #define RUNTIME_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{notproduct}", DEFAULT },
-#endif
+#define RUNTIME_PRODUCT_FLAG_STRUCT(     type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT) },
+#define RUNTIME_PD_PRODUCT_FLAG_STRUCT(  type, name,        doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
+#define RUNTIME_DIAGNOSTIC_FLAG_STRUCT(  type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DIAGNOSTIC) },
+#define RUNTIME_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_EXPERIMENTAL) },
+#define RUNTIME_MANAGEABLE_FLAG_STRUCT(  type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_MANAGEABLE) },
+#define RUNTIME_PRODUCT_RW_FLAG_STRUCT(  type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_PRODUCT | Flag::KIND_READ_WRITE) },
+#define RUNTIME_DEVELOP_FLAG_STRUCT(     type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DEVELOP) },
+#define RUNTIME_PD_DEVELOP_FLAG_STRUCT(  type, name,        doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
+#define RUNTIME_NOTPRODUCT_FLAG_STRUCT(  type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_NOT_PRODUCT) },
 
 #ifdef _LP64
-  #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{lp64_product}", DEFAULT },
+#define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_LP64_PRODUCT) },
 #else
-  #define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
+#define RUNTIME_LP64_PRODUCT_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
 #endif // _LP64
 
-#define C1_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 product}", DEFAULT },
-#define C1_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 pd product}", DEFAULT },
-#define C1_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C1 diagnostic}", DEFAULT },
-#ifdef PRODUCT
-  #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
-  #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
-  #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
-#else
-  #define C1_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1}", DEFAULT },
-  #define C1_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{C1 pd}", DEFAULT },
-  #define C1_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C1 notproduct}", DEFAULT },
-#endif
+#define C1_PRODUCT_FLAG_STRUCT(          type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_PRODUCT) },
+#define C1_PD_PRODUCT_FLAG_STRUCT(       type, name,        doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
+#define C1_DIAGNOSTIC_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DIAGNOSTIC) },
+#define C1_DEVELOP_FLAG_STRUCT(          type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DEVELOP) },
+#define C1_PD_DEVELOP_FLAG_STRUCT(       type, name,        doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
+#define C1_NOTPRODUCT_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C1 | Flag::KIND_NOT_PRODUCT) },
 
-#define C2_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 product}", DEFAULT },
-#define C2_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 pd product}", DEFAULT },
-#define C2_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 diagnostic}", DEFAULT },
-#define C2_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{C2 experimental}", DEFAULT },
-#ifdef PRODUCT
-  #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
-  #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
-  #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
-#else
-  #define C2_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2}", DEFAULT },
-  #define C2_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{C2 pd}", DEFAULT },
-  #define C2_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{C2 notproduct}", DEFAULT },
-#endif
+#define C2_PRODUCT_FLAG_STRUCT(          type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_PRODUCT) },
+#define C2_PD_PRODUCT_FLAG_STRUCT(       type, name,        doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
+#define C2_DIAGNOSTIC_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DIAGNOSTIC) },
+#define C2_EXPERIMENTAL_FLAG_STRUCT(     type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_EXPERIMENTAL) },
+#define C2_DEVELOP_FLAG_STRUCT(          type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DEVELOP) },
+#define C2_PD_DEVELOP_FLAG_STRUCT(       type, name,        doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
+#define C2_NOTPRODUCT_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_C2 | Flag::KIND_NOT_PRODUCT) },
 
-#define ARCH_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{ARCH product}", DEFAULT },
-#define ARCH_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{ARCH diagnostic}", DEFAULT },
-#define ARCH_EXPERIMENTAL_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{ARCH experimental}", DEFAULT },
-#ifdef PRODUCT
-  #define ARCH_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
-  #define ARCH_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
-#else
-  #define ARCH_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{ARCH}", DEFAULT },
-  #define ARCH_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{ARCH notproduct}", DEFAULT },
-#endif
+#define ARCH_PRODUCT_FLAG_STRUCT(        type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_PRODUCT) },
+#define ARCH_DIAGNOSTIC_FLAG_STRUCT(     type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_DIAGNOSTIC) },
+#define ARCH_EXPERIMENTAL_FLAG_STRUCT(   type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_EXPERIMENTAL) },
+#define ARCH_DEVELOP_FLAG_STRUCT(        type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_DEVELOP) },
+#define ARCH_NOTPRODUCT_FLAG_STRUCT(     type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_ARCH | Flag::KIND_NOT_PRODUCT) },
 
-#define SHARK_PRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark product}", DEFAULT },
-#define SHARK_PD_PRODUCT_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark pd product}", DEFAULT },
-#define SHARK_DIAGNOSTIC_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, NOT_PRODUCT_ARG(doc) "{Shark diagnostic}", DEFAULT },
-#ifdef PRODUCT
-  #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) /* flag is constant */
-  #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     /* flag is constant */
-  #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc)
-#else
-  #define SHARK_DEVELOP_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark}", DEFAULT },
-  #define SHARK_PD_DEVELOP_FLAG_STRUCT(type, name, doc)     { #type, XSTR(name), &name, doc, "{Shark pd}", DEFAULT },
-  #define SHARK_NOTPRODUCT_FLAG_STRUCT(type, name, value, doc) { #type, XSTR(name), &name, doc, "{Shark notproduct}", DEFAULT },
-#endif
+#define SHARK_PRODUCT_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_PRODUCT) },
+#define SHARK_PD_PRODUCT_FLAG_STRUCT(    type, name,        doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_PRODUCT | Flag::KIND_PLATFORM_DEPENDENT) },
+#define SHARK_DIAGNOSTIC_FLAG_STRUCT(    type, name, value, doc) { #type, XSTR(name), &name,      NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DIAGNOSTIC) },
+#define SHARK_DEVELOP_FLAG_STRUCT(       type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DEVELOP) },
+#define SHARK_PD_DEVELOP_FLAG_STRUCT(    type, name,        doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_DEVELOP | Flag::KIND_PLATFORM_DEPENDENT) },
+#define SHARK_NOTPRODUCT_FLAG_STRUCT(    type, name, value, doc) { #type, XSTR(name), NAME(name), NOT_PRODUCT_ARG(doc) Flag::Flags(Flag::DEFAULT | Flag::KIND_SHARK | Flag::KIND_NOT_PRODUCT) },
 
 static Flag flagTable[] = {
  RUNTIME_FLAGS(RUNTIME_DEVELOP_FLAG_STRUCT, RUNTIME_PD_DEVELOP_FLAG_STRUCT, RUNTIME_PRODUCT_FLAG_STRUCT, RUNTIME_PD_PRODUCT_FLAG_STRUCT, RUNTIME_DIAGNOSTIC_FLAG_STRUCT, RUNTIME_EXPERIMENTAL_FLAG_STRUCT, RUNTIME_NOTPRODUCT_FLAG_STRUCT, RUNTIME_MANAGEABLE_FLAG_STRUCT, RUNTIME_PRODUCT_RW_FLAG_STRUCT, RUNTIME_LP64_PRODUCT_FLAG_STRUCT)
@@ -285,9 +463,14 @@
 
 // Search the flag table for a named flag
 Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked) {
-  for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
-    if (str_equal(current->name, name, length)) {
-      // Found a matching entry.  Report locked flags only if allowed.
+  for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
+    if (str_equal(current->_name, name, length)) {
+      // Found a matching entry.
+      // Don't report notproduct and develop flags in product builds.
+      if (current->is_constant_in_binary()) {
+        return NULL;
+      }
+      // Report locked flags only if allowed.
       if (!(current->is_unlocked() || current->is_unlocker())) {
         if (!allow_locked) {
           // disable use of locked flags, e.g. diagnostic, experimental,
@@ -327,8 +510,8 @@
   float score;
   float max_score = -1;
 
-  for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
-    score = str_similar(current->name, name, length);
+  for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
+    score = str_similar(current->_name, name, length);
     if (score > max_score) {
       max_score = score;
       match = current;
@@ -357,25 +540,25 @@
 bool CommandLineFlagsEx::is_default(CommandLineFlag flag) {
   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   Flag* f = &Flag::flags[flag];
-  return (f->origin == DEFAULT);
+  return f->is_default();
 }
 
 bool CommandLineFlagsEx::is_ergo(CommandLineFlag flag) {
   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   Flag* f = &Flag::flags[flag];
-  return (f->origin == ERGONOMIC);
+  return f->is_ergonomic();
 }
 
 bool CommandLineFlagsEx::is_cmdline(CommandLineFlag flag) {
   assert((size_t)flag < Flag::numFlags, "bad command line flag index");
   Flag* f = &Flag::flags[flag];
-  return (f->origin == COMMAND_LINE);
+  return f->is_command_line();
 }
 
 bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
   Flag* result = Flag::find_flag((char*)name, strlen(name));
   if (result == NULL) return false;
-  *value = (result->origin == COMMAND_LINE);
+  *value = result->is_command_line();
   return true;
 }
 
@@ -387,22 +570,22 @@
   return true;
 }
 
-bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin) {
+bool CommandLineFlags::boolAtPut(char* name, size_t len, bool* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_bool()) return false;
   bool old_value = result->get_bool();
   result->set_bool(*value);
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
-void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_bool(), "wrong flag type");
   faddr->set_bool(value);
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 bool CommandLineFlags::intxAt(char* name, size_t len, intx* value) {
@@ -413,22 +596,22 @@
   return true;
 }
 
-bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin) {
+bool CommandLineFlags::intxAtPut(char* name, size_t len, intx* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_intx()) return false;
   intx old_value = result->get_intx();
   result->set_intx(*value);
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
-void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_intx(), "wrong flag type");
   faddr->set_intx(value);
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 bool CommandLineFlags::uintxAt(char* name, size_t len, uintx* value) {
@@ -439,22 +622,22 @@
   return true;
 }
 
-bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin) {
+bool CommandLineFlags::uintxAtPut(char* name, size_t len, uintx* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_uintx()) return false;
   uintx old_value = result->get_uintx();
   result->set_uintx(*value);
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
-void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_uintx(), "wrong flag type");
   faddr->set_uintx(value);
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 bool CommandLineFlags::uint64_tAt(char* name, size_t len, uint64_t* value) {
@@ -465,22 +648,22 @@
   return true;
 }
 
-bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin) {
+bool CommandLineFlags::uint64_tAtPut(char* name, size_t len, uint64_t* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_uint64_t()) return false;
   uint64_t old_value = result->get_uint64_t();
   result->set_uint64_t(*value);
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
-void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_uint64_t(), "wrong flag type");
   faddr->set_uint64_t(value);
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 bool CommandLineFlags::doubleAt(char* name, size_t len, double* value) {
@@ -491,22 +674,22 @@
   return true;
 }
 
-bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin) {
+bool CommandLineFlags::doubleAtPut(char* name, size_t len, double* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_double()) return false;
   double old_value = result->get_double();
   result->set_double(*value);
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
-void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_double(), "wrong flag type");
   faddr->set_double(value);
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 bool CommandLineFlags::ccstrAt(char* name, size_t len, ccstr* value) {
@@ -519,7 +702,7 @@
 
 // Contract:  Flag will make private copy of the incoming value.
 // Outgoing value is always malloc-ed, and caller MUST call free.
-bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin) {
+bool CommandLineFlags::ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
   if (!result->is_ccstr()) return false;
@@ -530,35 +713,35 @@
     strcpy(new_value, *value);
   }
   result->set_ccstr(new_value);
-  if (result->origin == DEFAULT && old_value != NULL) {
+  if (result->is_default() && old_value != NULL) {
     // Prior value is NOT heap allocated, but was a literal constant.
     char* old_value_to_free = NEW_C_HEAP_ARRAY(char, strlen(old_value)+1, mtInternal);
     strcpy(old_value_to_free, old_value);
     old_value = old_value_to_free;
   }
   *value = old_value;
-  result->origin = origin;
+  result->set_origin(origin);
   return true;
 }
 
 // Contract:  Flag will make private copy of the incoming value.
-void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin) {
+void CommandLineFlagsEx::ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin) {
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
   ccstr old_value = faddr->get_ccstr();
   char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal);
   strcpy(new_value, value);
   faddr->set_ccstr(new_value);
-  if (faddr->origin != DEFAULT && old_value != NULL) {
+  if (!faddr->is_default() && old_value != NULL) {
     // Prior value is heap allocated so free it.
     FREE_C_HEAP_ARRAY(char, old_value, mtInternal);
   }
-  faddr->origin = origin;
+  faddr->set_origin(origin);
 }
 
 extern "C" {
   static int compare_flags(const void* void_a, const void* void_b) {
-    return strcmp((*((Flag**) void_a))->name, (*((Flag**) void_b))->name);
+    return strcmp((*((Flag**) void_a))->_name, (*((Flag**) void_b))->_name);
   }
 }
 
@@ -567,20 +750,19 @@
   // note: this method is called before the thread structure is in place
   //       which means resource allocation cannot be used.
 
-  // Compute size
-  int length= 0;
-  while (flagTable[length].name != NULL) length++;
+  // The last entry is the null entry.
+  const size_t length = Flag::numFlags - 1;
 
   // Sort
   Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
-  for (int index = 0; index < length; index++) {
-    array[index] = &flagTable[index];
+  for (size_t i = 0; i < length; i++) {
+    array[i] = &flagTable[i];
   }
   qsort(array, length, sizeof(Flag*), compare_flags);
 
   // Print
-  for (int i = 0; i < length; i++) {
-    if (array[i]->origin /* naked field! */) {
+  for (size_t i = 0; i < length; i++) {
+    if (array[i]->get_origin() /* naked field! */) {
       array[i]->print_as_flag(out);
       out->print(" ");
     }
@@ -603,20 +785,19 @@
   // note: this method is called before the thread structure is in place
   //       which means resource allocation cannot be used.
 
-  // Compute size
-  int length= 0;
-  while (flagTable[length].name != NULL) length++;
+  // The last entry is the null entry.
+  const size_t length = Flag::numFlags - 1;
 
   // Sort
   Flag** array = NEW_C_HEAP_ARRAY(Flag*, length, mtInternal);
-  for (int index = 0; index < length; index++) {
-    array[index] = &flagTable[index];
+  for (size_t i = 0; i < length; i++) {
+    array[i] = &flagTable[i];
   }
   qsort(array, length, sizeof(Flag*), compare_flags);
 
   // Print
   out->print_cr("[Global flags]");
-  for (int i = 0; i < length; i++) {
+  for (size_t i = 0; i < length; i++) {
     if (array[i]->is_unlocked()) {
       array[i]->print_on(out, withComments);
     }
--- a/src/share/vm/runtime/globals.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/globals.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -194,29 +194,49 @@
 typedef const char* ccstr;
 typedef const char* ccstrlist;   // represents string arguments which accumulate
 
-enum FlagValueOrigin {
-  DEFAULT          = 0,
-  COMMAND_LINE     = 1,
-  ENVIRON_VAR      = 2,
-  CONFIG_FILE      = 3,
-  MANAGEMENT       = 4,
-  ERGONOMIC        = 5,
-  ATTACH_ON_DEMAND = 6,
-  INTERNAL         = 99
-};
+struct Flag {
+  enum Flags {
+    // value origin
+    DEFAULT          = 0,
+    COMMAND_LINE     = 1,
+    ENVIRON_VAR      = 2,
+    CONFIG_FILE      = 3,
+    MANAGEMENT       = 4,
+    ERGONOMIC        = 5,
+    ATTACH_ON_DEMAND = 6,
+    INTERNAL         = 7,
+
+    LAST_VALUE_ORIGIN = INTERNAL,
+    VALUE_ORIGIN_BITS = 4,
+    VALUE_ORIGIN_MASK = right_n_bits(VALUE_ORIGIN_BITS),
 
-struct Flag {
-  const char *type;
-  const char *name;
-  void*       addr;
+    // flag kind
+    KIND_PRODUCT            = 1 << 4,
+    KIND_MANAGEABLE         = 1 << 5,
+    KIND_DIAGNOSTIC         = 1 << 6,
+    KIND_EXPERIMENTAL       = 1 << 7,
+    KIND_NOT_PRODUCT        = 1 << 8,
+    KIND_DEVELOP            = 1 << 9,
+    KIND_PLATFORM_DEPENDENT = 1 << 10,
+    KIND_READ_WRITE         = 1 << 11,
+    KIND_C1                 = 1 << 12,
+    KIND_C2                 = 1 << 13,
+    KIND_ARCH               = 1 << 14,
+    KIND_SHARK              = 1 << 15,
+    KIND_LP64_PRODUCT       = 1 << 16,
+    KIND_COMMERCIAL         = 1 << 17,
 
-  NOT_PRODUCT(const char *doc;)
+    KIND_MASK = ~VALUE_ORIGIN_MASK
+  };
 
-  const char *kind;
-  FlagValueOrigin origin;
+  const char* _type;
+  const char* _name;
+  void* _addr;
+  NOT_PRODUCT(const char* _doc;)
+  Flags _flags;
 
   // points to all Flags static array
-  static Flag *flags;
+  static Flag* flags;
 
   // number of flags
   static size_t numFlags;
@@ -224,30 +244,50 @@
   static Flag* find_flag(const char* name, size_t length, bool allow_locked = false);
   static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
 
-  bool is_bool() const        { return strcmp(type, "bool") == 0; }
-  bool get_bool() const       { return *((bool*) addr); }
-  void set_bool(bool value)   { *((bool*) addr) = value; }
+  void check_writable();
+
+  bool is_bool() const;
+  bool get_bool() const;
+  void set_bool(bool value);
+
+  bool is_intx() const;
+  intx get_intx() const;
+  void set_intx(intx value);
 
-  bool is_intx()  const       { return strcmp(type, "intx")  == 0; }
-  intx get_intx() const       { return *((intx*) addr); }
-  void set_intx(intx value)   { *((intx*) addr) = value; }
+  bool is_uintx() const;
+  uintx get_uintx() const;
+  void set_uintx(uintx value);
 
-  bool is_uintx() const       { return strcmp(type, "uintx") == 0; }
-  uintx get_uintx() const     { return *((uintx*) addr); }
-  void set_uintx(uintx value) { *((uintx*) addr) = value; }
+  bool is_uint64_t() const;
+  uint64_t get_uint64_t() const;
+  void set_uint64_t(uint64_t value);
+
+  bool is_double() const;
+  double get_double() const;
+  void set_double(double value);
 
-  bool is_uint64_t() const          { return strcmp(type, "uint64_t") == 0; }
-  uint64_t get_uint64_t() const     { return *((uint64_t*) addr); }
-  void set_uint64_t(uint64_t value) { *((uint64_t*) addr) = value; }
+  bool is_ccstr() const;
+  bool ccstr_accumulates() const;
+  ccstr get_ccstr() const;
+  void set_ccstr(ccstr value);
+
+  Flags get_origin();
+  void set_origin(Flags origin);
 
-  bool is_double() const        { return strcmp(type, "double") == 0; }
-  double get_double() const     { return *((double*) addr); }
-  void set_double(double value) { *((double*) addr) = value; }
+  bool is_default();
+  bool is_ergonomic();
+  bool is_command_line();
 
-  bool is_ccstr() const          { return strcmp(type, "ccstr") == 0 || strcmp(type, "ccstrlist") == 0; }
-  bool ccstr_accumulates() const { return strcmp(type, "ccstrlist") == 0; }
-  ccstr get_ccstr() const     { return *((ccstr*) addr); }
-  void set_ccstr(ccstr value) { *((ccstr*) addr) = value; }
+  bool is_product() const;
+  bool is_manageable() const;
+  bool is_diagnostic() const;
+  bool is_experimental() const;
+  bool is_notproduct() const;
+  bool is_develop() const;
+  bool is_read_write() const;
+  bool is_commercial() const;
+
+  bool is_constant_in_binary() const;
 
   bool is_unlocker() const;
   bool is_unlocked() const;
@@ -263,6 +303,7 @@
   void get_locked_message_ext(char*, int) const;
 
   void print_on(outputStream* st, bool withComments = false );
+  void print_kind(outputStream* st);
   void print_as_flag(outputStream* st);
 };
 
@@ -310,33 +351,33 @@
  public:
   static bool boolAt(char* name, size_t len, bool* value);
   static bool boolAt(char* name, bool* value)      { return boolAt(name, strlen(name), value); }
-  static bool boolAtPut(char* name, size_t len, bool* value, FlagValueOrigin origin);
-  static bool boolAtPut(char* name, bool* value, FlagValueOrigin origin)   { return boolAtPut(name, strlen(name), value, origin); }
+  static bool boolAtPut(char* name, size_t len, bool* value, Flag::Flags origin);
+  static bool boolAtPut(char* name, bool* value, Flag::Flags origin)   { return boolAtPut(name, strlen(name), value, origin); }
 
   static bool intxAt(char* name, size_t len, intx* value);
   static bool intxAt(char* name, intx* value)      { return intxAt(name, strlen(name), value); }
-  static bool intxAtPut(char* name, size_t len, intx* value, FlagValueOrigin origin);
-  static bool intxAtPut(char* name, intx* value, FlagValueOrigin origin)   { return intxAtPut(name, strlen(name), value, origin); }
+  static bool intxAtPut(char* name, size_t len, intx* value, Flag::Flags origin);
+  static bool intxAtPut(char* name, intx* value, Flag::Flags origin)   { return intxAtPut(name, strlen(name), value, origin); }
 
   static bool uintxAt(char* name, size_t len, uintx* value);
   static bool uintxAt(char* name, uintx* value)    { return uintxAt(name, strlen(name), value); }
-  static bool uintxAtPut(char* name, size_t len, uintx* value, FlagValueOrigin origin);
-  static bool uintxAtPut(char* name, uintx* value, FlagValueOrigin origin) { return uintxAtPut(name, strlen(name), value, origin); }
+  static bool uintxAtPut(char* name, size_t len, uintx* value, Flag::Flags origin);
+  static bool uintxAtPut(char* name, uintx* value, Flag::Flags origin) { return uintxAtPut(name, strlen(name), value, origin); }
 
   static bool uint64_tAt(char* name, size_t len, uint64_t* value);
   static bool uint64_tAt(char* name, uint64_t* value) { return uint64_tAt(name, strlen(name), value); }
-  static bool uint64_tAtPut(char* name, size_t len, uint64_t* value, FlagValueOrigin origin);
-  static bool uint64_tAtPut(char* name, uint64_t* value, FlagValueOrigin origin) { return uint64_tAtPut(name, strlen(name), value, origin); }
+  static bool uint64_tAtPut(char* name, size_t len, uint64_t* value, Flag::Flags origin);
+  static bool uint64_tAtPut(char* name, uint64_t* value, Flag::Flags origin) { return uint64_tAtPut(name, strlen(name), value, origin); }
 
   static bool doubleAt(char* name, size_t len, double* value);
   static bool doubleAt(char* name, double* value)    { return doubleAt(name, strlen(name), value); }
-  static bool doubleAtPut(char* name, size_t len, double* value, FlagValueOrigin origin);
-  static bool doubleAtPut(char* name, double* value, FlagValueOrigin origin) { return doubleAtPut(name, strlen(name), value, origin); }
+  static bool doubleAtPut(char* name, size_t len, double* value, Flag::Flags origin);
+  static bool doubleAtPut(char* name, double* value, Flag::Flags origin) { return doubleAtPut(name, strlen(name), value, origin); }
 
   static bool ccstrAt(char* name, size_t len, ccstr* value);
   static bool ccstrAt(char* name, ccstr* value)    { return ccstrAt(name, strlen(name), value); }
-  static bool ccstrAtPut(char* name, size_t len, ccstr* value, FlagValueOrigin origin);
-  static bool ccstrAtPut(char* name, ccstr* value, FlagValueOrigin origin) { return ccstrAtPut(name, strlen(name), value, origin); }
+  static bool ccstrAtPut(char* name, size_t len, ccstr* value, Flag::Flags origin);
+  static bool ccstrAtPut(char* name, ccstr* value, Flag::Flags origin) { return ccstrAtPut(name, strlen(name), value, origin); }
 
   // Returns false if name is not a command line flag.
   static bool wasSetOnCmdline(const char* name, bool* value);
@@ -3730,20 +3771,20 @@
  */
 
 // Interface macros
-#define DECLARE_PRODUCT_FLAG(type, name, value, doc)    extern "C" type name;
-#define DECLARE_PD_PRODUCT_FLAG(type, name, doc)        extern "C" type name;
-#define DECLARE_DIAGNOSTIC_FLAG(type, name, value, doc) extern "C" type name;
+#define DECLARE_PRODUCT_FLAG(type, name, value, doc)      extern "C" type name;
+#define DECLARE_PD_PRODUCT_FLAG(type, name, doc)          extern "C" type name;
+#define DECLARE_DIAGNOSTIC_FLAG(type, name, value, doc)   extern "C" type name;
 #define DECLARE_EXPERIMENTAL_FLAG(type, name, value, doc) extern "C" type name;
-#define DECLARE_MANAGEABLE_FLAG(type, name, value, doc) extern "C" type name;
-#define DECLARE_PRODUCT_RW_FLAG(type, name, value, doc) extern "C" type name;
+#define DECLARE_MANAGEABLE_FLAG(type, name, value, doc)   extern "C" type name;
+#define DECLARE_PRODUCT_RW_FLAG(type, name, value, doc)   extern "C" type name;
 #ifdef PRODUCT
-#define DECLARE_DEVELOPER_FLAG(type, name, value, doc)  const type name = value;
-#define DECLARE_PD_DEVELOPER_FLAG(type, name, doc)      const type name = pd_##name;
-#define DECLARE_NOTPRODUCT_FLAG(type, name, value, doc)
+#define DECLARE_DEVELOPER_FLAG(type, name, value, doc)    extern "C" type CONST_##name; const type name = value;
+#define DECLARE_PD_DEVELOPER_FLAG(type, name, doc)        extern "C" type CONST_##name; const type name = pd_##name;
+#define DECLARE_NOTPRODUCT_FLAG(type, name, value, doc)   extern "C" type CONST_##name;
 #else
-#define DECLARE_DEVELOPER_FLAG(type, name, value, doc)  extern "C" type name;
-#define DECLARE_PD_DEVELOPER_FLAG(type, name, doc)      extern "C" type name;
-#define DECLARE_NOTPRODUCT_FLAG(type, name, value, doc)  extern "C" type name;
+#define DECLARE_DEVELOPER_FLAG(type, name, value, doc)    extern "C" type name;
+#define DECLARE_PD_DEVELOPER_FLAG(type, name, doc)        extern "C" type name;
+#define DECLARE_NOTPRODUCT_FLAG(type, name, value, doc)   extern "C" type name;
 #endif
 // Special LP64 flags, product only needed for now.
 #ifdef _LP64
@@ -3753,23 +3794,23 @@
 #endif // _LP64
 
 // Implementation macros
-#define MATERIALIZE_PRODUCT_FLAG(type, name, value, doc)   type name = value;
-#define MATERIALIZE_PD_PRODUCT_FLAG(type, name, doc)       type name = pd_##name;
-#define MATERIALIZE_DIAGNOSTIC_FLAG(type, name, value, doc) type name = value;
+#define MATERIALIZE_PRODUCT_FLAG(type, name, value, doc)      type name = value;
+#define MATERIALIZE_PD_PRODUCT_FLAG(type, name, doc)          type name = pd_##name;
+#define MATERIALIZE_DIAGNOSTIC_FLAG(type, name, value, doc)   type name = value;
 #define MATERIALIZE_EXPERIMENTAL_FLAG(type, name, value, doc) type name = value;
-#define MATERIALIZE_MANAGEABLE_FLAG(type, name, value, doc) type name = value;
-#define MATERIALIZE_PRODUCT_RW_FLAG(type, name, value, doc) type name = value;
+#define MATERIALIZE_MANAGEABLE_FLAG(type, name, value, doc)   type name = value;
+#define MATERIALIZE_PRODUCT_RW_FLAG(type, name, value, doc)   type name = value;
 #ifdef PRODUCT
-#define MATERIALIZE_DEVELOPER_FLAG(type, name, value, doc) /* flag name is constant */
-#define MATERIALIZE_PD_DEVELOPER_FLAG(type, name, doc)     /* flag name is constant */
-#define MATERIALIZE_NOTPRODUCT_FLAG(type, name, value, doc)
+#define MATERIALIZE_DEVELOPER_FLAG(type, name, value, doc)    type CONST_##name = value;
+#define MATERIALIZE_PD_DEVELOPER_FLAG(type, name, doc)        type CONST_##name = pd_##name;
+#define MATERIALIZE_NOTPRODUCT_FLAG(type, name, value, doc)   type CONST_##name = value;
 #else
-#define MATERIALIZE_DEVELOPER_FLAG(type, name, value, doc) type name = value;
-#define MATERIALIZE_PD_DEVELOPER_FLAG(type, name, doc)     type name = pd_##name;
-#define MATERIALIZE_NOTPRODUCT_FLAG(type, name, value, doc) type name = value;
+#define MATERIALIZE_DEVELOPER_FLAG(type, name, value, doc)    type name = value;
+#define MATERIALIZE_PD_DEVELOPER_FLAG(type, name, doc)        type name = pd_##name;
+#define MATERIALIZE_NOTPRODUCT_FLAG(type, name, value, doc)   type name = value;
 #endif
 #ifdef _LP64
-#define MATERIALIZE_LP64_PRODUCT_FLAG(type, name, value, doc)   type name = value;
+#define MATERIALIZE_LP64_PRODUCT_FLAG(type, name, value, doc) type name = value;
 #else
 #define MATERIALIZE_LP64_PRODUCT_FLAG(type, name, value, doc) /* flag is constant */
 #endif // _LP64
--- a/src/share/vm/runtime/globals_extension.hpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/globals_extension.hpp	Fri Sep 27 12:43:51 2013 -0700
@@ -34,64 +34,42 @@
 // Parens left off in the following for the enum decl below.
 #define FLAG_MEMBER(flag) Flag_##flag
 
-#define RUNTIME_PRODUCT_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#define RUNTIME_PD_PRODUCT_FLAG_MEMBER(type, name, doc)        FLAG_MEMBER(name),
-#define RUNTIME_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
+#define RUNTIME_PRODUCT_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
+#define RUNTIME_PD_PRODUCT_FLAG_MEMBER(type, name, doc)          FLAG_MEMBER(name),
+#define RUNTIME_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)   FLAG_MEMBER(name),
 #define RUNTIME_EXPERIMENTAL_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
-#define RUNTIME_MANAGEABLE_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
-#define RUNTIME_PRODUCT_RW_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
-#ifdef PRODUCT
-  #define RUNTIME_DEVELOP_FLAG_MEMBER(type, name, value, doc)  /* flag is constant */
-  #define RUNTIME_PD_DEVELOP_FLAG_MEMBER(type, name, doc)      /* flag is constant */
-  #define RUNTIME_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)
+#define RUNTIME_MANAGEABLE_FLAG_MEMBER(type, name, value, doc)   FLAG_MEMBER(name),
+#define RUNTIME_PRODUCT_RW_FLAG_MEMBER(type, name, value, doc)   FLAG_MEMBER(name),
+#define RUNTIME_DEVELOP_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
+#define RUNTIME_PD_DEVELOP_FLAG_MEMBER(type, name, doc)          FLAG_MEMBER(name),
+#define RUNTIME_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)   FLAG_MEMBER(name),
+
+#ifdef _LP64
+#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
 #else
-  #define RUNTIME_DEVELOP_FLAG_MEMBER(type, name, value, doc)  FLAG_MEMBER(name),
-  #define RUNTIME_PD_DEVELOP_FLAG_MEMBER(type, name, doc)      FLAG_MEMBER(name),
-  #define RUNTIME_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc) FLAG_MEMBER(name),
-#endif
-#ifdef _LP64
-#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#else
-#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER(type, name, value, doc)    /* flag is constant */
+#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER(type, name, value, doc) /* flag is constant */
 #endif // _LP64
 
-#define C1_PRODUCT_FLAG_MEMBER(type, name, value, doc)         FLAG_MEMBER(name),
-#define C1_PD_PRODUCT_FLAG_MEMBER(type, name, doc)             FLAG_MEMBER(name),
-#define C1_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
-#ifdef PRODUCT
-  #define C1_DEVELOP_FLAG_MEMBER(type, name, value, doc)       /* flag is constant */
-  #define C1_PD_DEVELOP_FLAG_MEMBER(type, name, doc)           /* flag is constant */
-  #define C1_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)
-#else
-  #define C1_DEVELOP_FLAG_MEMBER(type, name, value, doc)       FLAG_MEMBER(name),
-  #define C1_PD_DEVELOP_FLAG_MEMBER(type, name, doc)           FLAG_MEMBER(name),
-  #define C1_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#endif
+#define C1_PRODUCT_FLAG_MEMBER(type, name, value, doc)           FLAG_MEMBER(name),
+#define C1_PD_PRODUCT_FLAG_MEMBER(type, name, doc)               FLAG_MEMBER(name),
+#define C1_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)        FLAG_MEMBER(name),
+#define C1_DEVELOP_FLAG_MEMBER(type, name, value, doc)           FLAG_MEMBER(name),
+#define C1_PD_DEVELOP_FLAG_MEMBER(type, name, doc)               FLAG_MEMBER(name),
+#define C1_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)        FLAG_MEMBER(name),
 
-#define C2_PRODUCT_FLAG_MEMBER(type, name, value, doc)         FLAG_MEMBER(name),
-#define C2_PD_PRODUCT_FLAG_MEMBER(type, name, doc)             FLAG_MEMBER(name),
-#define C2_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
-#define C2_EXPERIMENTAL_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#ifdef PRODUCT
-  #define C2_DEVELOP_FLAG_MEMBER(type, name, value, doc)       /* flag is constant */
-  #define C2_PD_DEVELOP_FLAG_MEMBER(type, name, doc)           /* flag is constant */
-  #define C2_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)
-#else
-  #define C2_DEVELOP_FLAG_MEMBER(type, name, value, doc)       FLAG_MEMBER(name),
-  #define C2_PD_DEVELOP_FLAG_MEMBER(type, name, doc)           FLAG_MEMBER(name),
-  #define C2_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#endif
+#define C2_PRODUCT_FLAG_MEMBER(type, name, value, doc)           FLAG_MEMBER(name),
+#define C2_PD_PRODUCT_FLAG_MEMBER(type, name, doc)               FLAG_MEMBER(name),
+#define C2_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)        FLAG_MEMBER(name),
+#define C2_EXPERIMENTAL_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
+#define C2_DEVELOP_FLAG_MEMBER(type, name, value, doc)           FLAG_MEMBER(name),
+#define C2_PD_DEVELOP_FLAG_MEMBER(type, name, doc)               FLAG_MEMBER(name),
+#define C2_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)        FLAG_MEMBER(name),
 
 #define ARCH_PRODUCT_FLAG_MEMBER(type, name, value, doc)         FLAG_MEMBER(name),
 #define ARCH_DIAGNOSTIC_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
 #define ARCH_EXPERIMENTAL_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#ifdef PRODUCT
-  #define ARCH_DEVELOP_FLAG_MEMBER(type, name, value, doc)       /* flag is constant */
-  #define ARCH_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)
-#else
-  #define ARCH_DEVELOP_FLAG_MEMBER(type, name, value, doc)       FLAG_MEMBER(name),
-  #define ARCH_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)    FLAG_MEMBER(name),
-#endif
+#define ARCH_DEVELOP_FLAG_MEMBER(type, name, value, doc)         FLAG_MEMBER(name),
+#define ARCH_NOTPRODUCT_FLAG_MEMBER(type, name, value, doc)      FLAG_MEMBER(name),
 
 typedef enum {
  RUNTIME_FLAGS(RUNTIME_DEVELOP_FLAG_MEMBER, RUNTIME_PD_DEVELOP_FLAG_MEMBER, RUNTIME_PRODUCT_FLAG_MEMBER, RUNTIME_PD_PRODUCT_FLAG_MEMBER, RUNTIME_DIAGNOSTIC_FLAG_MEMBER, RUNTIME_EXPERIMENTAL_FLAG_MEMBER, RUNTIME_NOTPRODUCT_FLAG_MEMBER, RUNTIME_MANAGEABLE_FLAG_MEMBER, RUNTIME_PRODUCT_RW_FLAG_MEMBER, RUNTIME_LP64_PRODUCT_FLAG_MEMBER)
@@ -114,64 +92,42 @@
 
 #define FLAG_MEMBER_WITH_TYPE(flag,type) Flag_##flag##_##type
 
-#define RUNTIME_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
-#define RUNTIME_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)        FLAG_MEMBER_WITH_TYPE(name,type),
-#define RUNTIME_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)          FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)   FLAG_MEMBER_WITH_TYPE(name,type),
 #define RUNTIME_EXPERIMENTAL_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) FLAG_MEMBER_WITH_TYPE(name,type),
-#define RUNTIME_MANAGEABLE_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) FLAG_MEMBER_WITH_TYPE(name,type),
-#define RUNTIME_PRODUCT_RW_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) FLAG_MEMBER_WITH_TYPE(name,type),
-#ifdef PRODUCT
-  #define RUNTIME_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)     /* flag is constant */
-  #define RUNTIME_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)         /* flag is constant */
-  #define RUNTIME_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)
-#else
-  #define RUNTIME_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)     FLAG_MEMBER_WITH_TYPE(name,type),
-  #define RUNTIME_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)         FLAG_MEMBER_WITH_TYPE(name,type),
-  #define RUNTIME_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)  FLAG_MEMBER_WITH_TYPE(name,type),
-#endif
+#define RUNTIME_MANAGEABLE_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)   FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_PRODUCT_RW_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)   FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)          FLAG_MEMBER_WITH_TYPE(name,type),
+#define RUNTIME_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)   FLAG_MEMBER_WITH_TYPE(name,type),
 
-#define C1_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)         FLAG_MEMBER_WITH_TYPE(name,type),
-#define C1_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)             FLAG_MEMBER_WITH_TYPE(name,type),
-#define C1_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
-#ifdef PRODUCT
-  #define C1_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       /* flag is constant */
-  #define C1_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)           /* flag is constant */
-  #define C1_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)
+#define C1_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
+#define C1_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)               FLAG_MEMBER_WITH_TYPE(name,type),
+#define C1_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)        FLAG_MEMBER_WITH_TYPE(name,type),
+#define C1_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
+#define C1_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)               FLAG_MEMBER_WITH_TYPE(name,type),
+#define C1_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)        FLAG_MEMBER_WITH_TYPE(name,type),
+
+#ifdef _LP64
+#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) FLAG_MEMBER_WITH_TYPE(name,type),
 #else
-  #define C1_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       FLAG_MEMBER_WITH_TYPE(name,type),
-  #define C1_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
-  #define C1_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
-#endif
-#ifdef _LP64
-#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
-#else
-#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    /* flag is constant */
+#define RUNTIME_LP64_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc) /* flag is constant */
 #endif // _LP64
 
-#define C2_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)         FLAG_MEMBER_WITH_TYPE(name,type),
-#define C2_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)             FLAG_MEMBER_WITH_TYPE(name,type),
-#define C2_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
+#define C2_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
+#define C2_PD_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, doc)               FLAG_MEMBER_WITH_TYPE(name,type),
+#define C2_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)        FLAG_MEMBER_WITH_TYPE(name,type),
 #define C2_EXPERIMENTAL_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
-#ifdef PRODUCT
-  #define C2_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       /* flag is constant */
-  #define C2_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)           /* flag is constant */
-  #define C2_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)
-#else
-  #define C2_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       FLAG_MEMBER_WITH_TYPE(name,type),
-  #define C2_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
-  #define C2_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
-#endif
+#define C2_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)           FLAG_MEMBER_WITH_TYPE(name,type),
+#define C2_PD_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, doc)               FLAG_MEMBER_WITH_TYPE(name,type),
+#define C2_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)        FLAG_MEMBER_WITH_TYPE(name,type),
 
 #define ARCH_PRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)         FLAG_MEMBER_WITH_TYPE(name,type),
 #define ARCH_DIAGNOSTIC_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
-#define ARCH_EXPERIMENTAL_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
-#ifdef PRODUCT
-  #define ARCH_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       /* flag is constant */
-  #define ARCH_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)
-#else
-  #define ARCH_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)       FLAG_MEMBER_WITH_TYPE(name,type),
-  #define ARCH_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
-#endif
+#define ARCH_EXPERIMENTAL_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)    FLAG_MEMBER_WITH_TYPE(name,type),
+#define ARCH_DEVELOP_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)         FLAG_MEMBER_WITH_TYPE(name,type),
+#define ARCH_NOTPRODUCT_FLAG_MEMBER_WITH_TYPE(type, name, value, doc)      FLAG_MEMBER_WITH_TYPE(name,type),
 
 typedef enum {
  RUNTIME_FLAGS(RUNTIME_DEVELOP_FLAG_MEMBER_WITH_TYPE,
@@ -233,19 +189,19 @@
 
 #define FLAG_SET_DEFAULT(name, value) ((name) = (value))
 
-#define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), COMMAND_LINE))
-#define FLAG_SET_ERGO(type, name, value)    (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), ERGONOMIC))
+#define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::COMMAND_LINE))
+#define FLAG_SET_ERGO(type, name, value)    (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::ERGONOMIC))
 
 // Can't put the following in CommandLineFlags because
 // of a circular dependency on the enum definition.
 class CommandLineFlagsEx : CommandLineFlags {
  public:
-  static void boolAtPut(CommandLineFlagWithType flag, bool value, FlagValueOrigin origin);
-  static void intxAtPut(CommandLineFlagWithType flag, intx value, FlagValueOrigin origin);
-  static void uintxAtPut(CommandLineFlagWithType flag, uintx value, FlagValueOrigin origin);
-  static void uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, FlagValueOrigin origin);
-  static void doubleAtPut(CommandLineFlagWithType flag, double value, FlagValueOrigin origin);
-  static void ccstrAtPut(CommandLineFlagWithType flag, ccstr value, FlagValueOrigin origin);
+  static void boolAtPut(CommandLineFlagWithType flag, bool value, Flag::Flags origin);
+  static void intxAtPut(CommandLineFlagWithType flag, intx value, Flag::Flags origin);
+  static void uintxAtPut(CommandLineFlagWithType flag, uintx value, Flag::Flags origin);
+  static void uint64_tAtPut(CommandLineFlagWithType flag, uint64_t value, Flag::Flags origin);
+  static void doubleAtPut(CommandLineFlagWithType flag, double value, Flag::Flags origin);
+  static void ccstrAtPut(CommandLineFlagWithType flag, ccstr value, Flag::Flags origin);
 
   static bool is_default(CommandLineFlag flag);
   static bool is_ergo(CommandLineFlag flag);
--- a/src/share/vm/runtime/vmStructs.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/runtime/vmStructs.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -176,6 +176,7 @@
 #include "opto/loopnode.hpp"
 #include "opto/machnode.hpp"
 #include "opto/matcher.hpp"
+#include "opto/mathexactnode.hpp"
 #include "opto/mulnode.hpp"
 #include "opto/phaseX.hpp"
 #include "opto/parse.hpp"
@@ -1185,11 +1186,10 @@
   /* -XX flags         */                                                                                                            \
   /*********************/                                                                                                            \
                                                                                                                                      \
-  nonstatic_field(Flag,                        type,                                          const char*)                           \
-  nonstatic_field(Flag,                        name,                                          const char*)                           \
-  unchecked_nonstatic_field(Flag,              addr,                                          sizeof(void*)) /* NOTE: no type */     \
-  nonstatic_field(Flag,                        kind,                                          const char*)                           \
-  nonstatic_field(Flag,                        origin,                                        FlagValueOrigin)                       \
+  nonstatic_field(Flag,                        _type,                                         const char*)                           \
+  nonstatic_field(Flag,                        _name,                                         const char*)                           \
+  unchecked_nonstatic_field(Flag,              _addr,                                         sizeof(void*)) /* NOTE: no type */     \
+  nonstatic_field(Flag,                        _flags,                                        Flag::Flags)                           \
   static_field(Flag,                           flags,                                         Flag*)                                 \
   static_field(Flag,                           numFlags,                                      size_t)                                \
                                                                                                                                      \
@@ -1928,6 +1928,9 @@
   declare_c2_type(CmpF3Node, CmpFNode)                                    \
   declare_c2_type(CmpDNode, CmpNode)                                      \
   declare_c2_type(CmpD3Node, CmpDNode)                                    \
+  declare_c2_type(MathExactNode, MultiNode)                               \
+  declare_c2_type(AddExactINode, MathExactNode)                           \
+  declare_c2_type(FlagsProjNode, ProjNode)                                \
   declare_c2_type(BoolNode, Node)                                         \
   declare_c2_type(AbsNode, Node)                                          \
   declare_c2_type(AbsINode, AbsNode)                                      \
@@ -2074,7 +2077,7 @@
    declare_integer_type(JavaThreadState)                                  \
    declare_integer_type(Location::Type)                                   \
    declare_integer_type(Location::Where)                                  \
-   declare_integer_type(FlagValueOrigin)                                  \
+   declare_integer_type(Flag::Flags)                                      \
    COMPILER2_PRESENT(declare_integer_type(OptoReg::Name))                 \
                                                                           \
    declare_toplevel_type(CHeapObj<mtInternal>)                            \
@@ -2082,7 +2085,7 @@
             declare_type(Array<u1>, MetaspaceObj)                         \
             declare_type(Array<u2>, MetaspaceObj)                         \
             declare_type(Array<Klass*>, MetaspaceObj)                     \
-            declare_type(Array<Method*>, MetaspaceObj)             \
+            declare_type(Array<Method*>, MetaspaceObj)                    \
                                                                           \
    declare_integer_type(AccessFlags)  /* FIXME: wrong type (not integer) */\
   declare_toplevel_type(address)      /* FIXME: should this be an integer type? */\
--- a/src/share/vm/services/attachListener.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/services/attachListener.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -245,7 +245,7 @@
     }
     value = (tmp != 0);
   }
-  bool res = CommandLineFlags::boolAtPut((char*)name, &value, ATTACH_ON_DEMAND);
+  bool res = CommandLineFlags::boolAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
   if (! res) {
     out->print_cr("setting flag %s failed", name);
   }
@@ -263,7 +263,7 @@
       return JNI_ERR;
     }
   }
-  bool res = CommandLineFlags::intxAtPut((char*)name, &value, ATTACH_ON_DEMAND);
+  bool res = CommandLineFlags::intxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
   if (! res) {
     out->print_cr("setting flag %s failed", name);
   }
@@ -282,7 +282,7 @@
       return JNI_ERR;
     }
   }
-  bool res = CommandLineFlags::uintxAtPut((char*)name, &value, ATTACH_ON_DEMAND);
+  bool res = CommandLineFlags::uintxAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
   if (! res) {
     out->print_cr("setting flag %s failed", name);
   }
@@ -301,7 +301,7 @@
       return JNI_ERR;
     }
   }
-  bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, ATTACH_ON_DEMAND);
+  bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
   if (! res) {
     out->print_cr("setting flag %s failed", name);
   }
@@ -316,7 +316,7 @@
     out->print_cr("flag value must be a string");
     return JNI_ERR;
   }
-  bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, ATTACH_ON_DEMAND);
+  bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, Flag::ATTACH_ON_DEMAND);
   if (res) {
     FREE_C_HEAP_ARRAY(char, value, mtInternal);
   } else {
--- a/src/share/vm/services/classLoadingService.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/services/classLoadingService.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -202,7 +202,7 @@
   MutexLocker m(Management_lock);
 
   // verbose will be set to the previous value
-  bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, MANAGEMENT);
+  bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassLoading", &verbose, Flag::MANAGEMENT);
   assert(succeed, "Setting TraceClassLoading flag fails");
   reset_trace_class_unloading();
 
@@ -213,7 +213,7 @@
 void ClassLoadingService::reset_trace_class_unloading() {
   assert(Management_lock->owned_by_self(), "Must own the Management_lock");
   bool value = MemoryService::get_verbose() || ClassLoadingService::get_verbose();
-  bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, MANAGEMENT);
+  bool succeed = CommandLineFlags::boolAtPut((char*)"TraceClassUnloading", &value, Flag::MANAGEMENT);
   assert(succeed, "Setting TraceClassUnLoading flag fails");
 }
 
--- a/src/share/vm/services/dtraceAttacher.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/services/dtraceAttacher.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -51,7 +51,7 @@
 
 static void set_bool_flag(const char* flag, bool value) {
   CommandLineFlags::boolAtPut((char*)flag, strlen(flag), &value,
-                              ATTACH_ON_DEMAND);
+                              Flag::ATTACH_ON_DEMAND);
 }
 
 // Enable only the "fine grained" flags. Do *not* touch
--- a/src/share/vm/services/management.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/services/management.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -1643,9 +1643,13 @@
   int num_entries = 0;
   for (int i = 0; i < nFlags; i++) {
     Flag* flag = &Flag::flags[i];
+    // Exclude notproduct and develop flags in product builds.
+    if (flag->is_constant_in_binary()) {
+      continue;
+    }
     // Exclude the locked (experimental, diagnostic) flags
     if (flag->is_unlocked() || flag->is_unlocker()) {
-      Handle s = java_lang_String::create_from_str(flag->name, CHECK_0);
+      Handle s = java_lang_String::create_from_str(flag->_name, CHECK_0);
       flags_ah->obj_at_put(num_entries, s());
       num_entries++;
     }
@@ -1669,7 +1673,7 @@
 bool add_global_entry(JNIEnv* env, Handle name, jmmVMGlobal *global, Flag *flag, TRAPS) {
   Handle flag_name;
   if (name() == NULL) {
-    flag_name = java_lang_String::create_from_str(flag->name, CHECK_false);
+    flag_name = java_lang_String::create_from_str(flag->_name, CHECK_false);
   } else {
     flag_name = name;
   }
@@ -1698,23 +1702,23 @@
 
   global->writeable = flag->is_writeable();
   global->external = flag->is_external();
-  switch (flag->origin) {
-    case DEFAULT:
+  switch (flag->get_origin()) {
+    case Flag::DEFAULT:
       global->origin = JMM_VMGLOBAL_ORIGIN_DEFAULT;
       break;
-    case COMMAND_LINE:
+    case Flag::COMMAND_LINE:
       global->origin = JMM_VMGLOBAL_ORIGIN_COMMAND_LINE;
       break;
-    case ENVIRON_VAR:
+    case Flag::ENVIRON_VAR:
       global->origin = JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR;
       break;
-    case CONFIG_FILE:
+    case Flag::CONFIG_FILE:
       global->origin = JMM_VMGLOBAL_ORIGIN_CONFIG_FILE;
       break;
-    case MANAGEMENT:
+    case Flag::MANAGEMENT:
       global->origin = JMM_VMGLOBAL_ORIGIN_MANAGEMENT;
       break;
-    case ERGONOMIC:
+    case Flag::ERGONOMIC:
       global->origin = JMM_VMGLOBAL_ORIGIN_ERGONOMIC;
       break;
     default:
@@ -1781,6 +1785,10 @@
     int num_entries = 0;
     for (int i = 0; i < nFlags && num_entries < count;  i++) {
       Flag* flag = &Flag::flags[i];
+      // Exclude notproduct and develop flags in product builds.
+      if (flag->is_constant_in_binary()) {
+        continue;
+      }
       // Exclude the locked (diagnostic, experimental) flags
       if ((flag->is_unlocked() || flag->is_unlocker()) &&
           add_global_entry(env, null_h, &globals[num_entries], flag, THREAD)) {
@@ -1813,23 +1821,23 @@
   bool succeed;
   if (flag->is_bool()) {
     bool bvalue = (new_value.z == JNI_TRUE ? true : false);
-    succeed = CommandLineFlags::boolAtPut(name, &bvalue, MANAGEMENT);
+    succeed = CommandLineFlags::boolAtPut(name, &bvalue, Flag::MANAGEMENT);
   } else if (flag->is_intx()) {
     intx ivalue = (intx)new_value.j;
-    succeed = CommandLineFlags::intxAtPut(name, &ivalue, MANAGEMENT);
+    succeed = CommandLineFlags::intxAtPut(name, &ivalue, Flag::MANAGEMENT);
   } else if (flag->is_uintx()) {
     uintx uvalue = (uintx)new_value.j;
-    succeed = CommandLineFlags::uintxAtPut(name, &uvalue, MANAGEMENT);
+    succeed = CommandLineFlags::uintxAtPut(name, &uvalue, Flag::MANAGEMENT);
   } else if (flag->is_uint64_t()) {
     uint64_t uvalue = (uint64_t)new_value.j;
-    succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, MANAGEMENT);
+    succeed = CommandLineFlags::uint64_tAtPut(name, &uvalue, Flag::MANAGEMENT);
   } else if (flag->is_ccstr()) {
     oop str = JNIHandles::resolve_external_guard(new_value.l);
     if (str == NULL) {
       THROW(vmSymbols::java_lang_NullPointerException());
     }
     ccstr svalue = java_lang_String::as_utf8_string(str);
-    succeed = CommandLineFlags::ccstrAtPut(name, &svalue, MANAGEMENT);
+    succeed = CommandLineFlags::ccstrAtPut(name, &svalue, Flag::MANAGEMENT);
   }
   assert(succeed, "Setting flag should succeed");
 JVM_END
--- a/src/share/vm/services/memoryService.cpp	Thu Sep 26 08:48:15 2013 +0200
+++ b/src/share/vm/services/memoryService.cpp	Fri Sep 27 12:43:51 2013 -0700
@@ -515,7 +515,7 @@
 bool MemoryService::set_verbose(bool verbose) {
   MutexLocker m(Management_lock);
   // verbose will be set to the previous value
-  bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, MANAGEMENT);
+  bool succeed = CommandLineFlags::boolAtPut((char*)"PrintGC", &verbose, Flag::MANAGEMENT);
   assert(succeed, "Setting PrintGC flag fails");
   ClassLoadingService::reset_trace_class_unloading();
 
@@ -618,4 +618,3 @@
   MemoryService::gc_end(_fullGC, _recordPostGCUsage, _recordAccumulatedGCTime,
                         _recordGCEndTime, _countCollection, _cause);
 }
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/CondTest.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+/*
+ * @test
+ * @bug 8024924
+ * @summary Test non constant addExact
+ * @compile CondTest.java Verify.java
+ * @run main CondTest
+ *
+ */
+
+import java.lang.ArithmeticException;
+
+public class CondTest {
+  public static int result = 0;
+
+  public static void main(String[] args) {
+    for (int i = 0; i < 50000; ++i) {
+      runTest();
+    }
+  }
+
+  public static void runTest() {
+    int i = 7;
+    while (java.lang.Math.addExact(i, result) < 89361) {
+        if ((java.lang.Math.addExact(i, i) & 1) == 1) {
+            i += 3;
+        } else if ((i & 5) == 4) {
+            i += 7;
+        } else if ((i & 0xf) == 6) {
+            i += 2;
+        } else {
+            i += 1;
+        }
+        result += 2;
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/ConstantTest.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+/*
+ * @test
+ * @bug 8024924
+ * @summary Test constant addExact
+ * @compile ConstantTest.java Verify.java
+ * @run main ConstantTest
+ *
+ */
+
+import java.lang.ArithmeticException;
+
+public class ConstantTest {
+  public static void main(String[] args) {
+    for (int i = 0; i < 50000; ++i) {
+      Verify.verify(5, 7);
+      Verify.verify(Integer.MAX_VALUE, 1);
+      Verify.verify(Integer.MIN_VALUE, -1);
+      Verify.verify(Integer.MAX_VALUE, -1);
+      Verify.verify(Integer.MIN_VALUE, 1);
+      Verify.verify(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2);
+      Verify.verify(Integer.MAX_VALUE / 2, (Integer.MAX_VALUE / 2) + 3);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/LoadTest.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+/*
+ * @test
+ * @bug 8024924
+ * @summary Test non constant addExact
+ * @compile LoadTest.java Verify.java
+ * @run main LoadTest
+ *
+ */
+
+import java.lang.ArithmeticException;
+
+public class LoadTest {
+  public static java.util.Random rnd = new java.util.Random();
+  public static int[] values = new int[256];
+
+  public static void main(String[] args) {
+    for (int i = 0; i < values.length; ++i) {
+        values[i] = rnd.nextInt();
+    }
+
+    for (int i = 0; i < 50000; ++i) {
+      Verify.verify(values[i & 255], values[i & 255] - i);
+      Verify.verify(values[i & 255] + i, values[i & 255] - i);
+      Verify.verify(values[i & 255], values[i & 255]);
+      if ((i & 1) == 1 && i > 5) {
+          Verify.verify(values[i & 255] + i, values[i & 255] - i);
+      } else {
+          Verify.verify(values[i & 255] - i, values[i & 255] + i);
+      }
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/LoopDependentTest.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+/*
+ * @test
+ * @bug 8024924
+ * @summary Test non constant addExact
+ * @compile LoopDependentTest.java Verify.java
+ * @run main LoopDependentTest
+ *
+ */
+
+import java.lang.ArithmeticException;
+
+public class LoopDependentTest {
+  public static java.util.Random rnd = new java.util.Random();
+
+  public static void main(String[] args) {
+    int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt();
+    for (int i = 0; i < 50000; ++i) {
+      Verify.verify(rnd1 + i, rnd2 + i);
+      Verify.verify(rnd1 + i, rnd2 + (i & 0xff));
+      Verify.verify(rnd1 - i, rnd2 - (i & 0xff));
+      Verify.verify(rnd1 + i + 1, rnd2 + i + 2);
+      Verify.verify(rnd1 + i * 2, rnd2 + i);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/NonConstantTest.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+/*
+ * @test
+ * @bug 8024924
+ * @summary Test non constant addExact
+ * @compile NonConstantTest.java Verify.java
+ * @run main NonConstantTest
+ *
+ */
+
+import java.lang.ArithmeticException;
+
+public class NonConstantTest {
+  public static java.util.Random rnd = new java.util.Random();
+
+  public static void main(String[] args) {
+    for (int i = 0; i < 50000; ++i) {
+      int rnd1 = rnd.nextInt(), rnd2 = rnd.nextInt();
+      Verify.verify(rnd1, rnd2);
+      Verify.verify(rnd1, rnd2 + 1);
+      Verify.verify(rnd1 + 1, rnd2);
+      Verify.verify(rnd1 - 1, rnd2);
+      Verify.verify(rnd1, rnd2 - 1);
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/intrinsics/mathexact/Verify.java	Fri Sep 27 12:43:51 2013 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+public class Verify {
+  public static String throwWord(boolean threw) {
+    return (threw ? "threw" : "didn't throw");
+  }
+
+  public static void verify(int a, int b) {
+    boolean exception1 = false, exception2 = false;
+    int result1 = 0, result2 = 0;
+    try {
+      result1 = testIntrinsic(a, b);
+    } catch (ArithmeticException e) {
+      exception1 = true;
+    }
+    try {
+      result2 = testNonIntrinsic(a, b);
+    } catch (ArithmeticException e) {
+      exception2 = true;
+    }
+
+    if (exception1 != exception2) {
+      throw new RuntimeException("Intrinsic version " + throwWord(exception1) + " exception, NonIntrinsic version " + throwWord(exception2) + " for: " + a + " + " + b);
+    }
+    if (result1 != result2) {
+      throw new RuntimeException("Intrinsic version returned: " + a + " while NonIntrinsic version returned: " + b);
+    }
+  }
+
+  public static int testIntrinsic(int a, int b) {
+    return java.lang.Math.addExact(a, b);
+  }
+
+  public static int testNonIntrinsic(int a, int b) {
+    return safeAddExact(a, b);
+  }
+
+  // Copied java.lang.Math.addExact to avoid intrinsification
+  public static int safeAddExact(int x, int y) {
+    int r = x + y;
+    // HD 2-12 Overflow iff both arguments have the opposite sign of the result
+    if (((x ^ r) & (y ^ r)) < 0) {
+      throw new ArithmeticException("integer overflow");
+    }
+    return r;
+  }
+}