8032250: Add trace event for VM flag changes
authorsla
Thu, 23 Jan 2014 08:12:12 +0100
changeset 22527 a5de5537d8a6
parent 22526 a04e9851fb0a
child 22528 bd3821442010
8032250: Add trace event for VM flag changes Reviewed-by: coleenp, ehelin, egahlin, mgronlun
hotspot/src/share/vm/runtime/globals.cpp
hotspot/src/share/vm/trace/trace.xml
hotspot/src/share/vm/trace/tracetypes.xml
--- a/hotspot/src/share/vm/runtime/globals.cpp	Mon Jan 20 09:56:47 2014 +0000
+++ b/hotspot/src/share/vm/runtime/globals.cpp	Thu Jan 23 08:12:12 2014 +0100
@@ -31,6 +31,7 @@
 #include "utilities/ostream.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/top.hpp"
+#include "trace/tracing.hpp"
 #if INCLUDE_ALL_GCS
 #include "gc_implementation/g1/g1_globals.hpp"
 #endif // INCLUDE_ALL_GCS
@@ -593,6 +594,17 @@
   return true;
 }
 
+template<class E, class T>
+static void trace_flag_changed(const char* name, const T old_value, const T new_value, const Flag::Flags origin)
+{
+  E e;
+  e.set_name(name);
+  e.set_old_value(old_value);
+  e.set_new_value(new_value);
+  e.set_origin(origin);
+  e.commit();
+}
+
 bool CommandLineFlags::boolAt(char* name, size_t len, bool* value) {
   Flag* result = Flag::find_flag(name, len);
   if (result == NULL) return false;
@@ -606,6 +618,7 @@
   if (result == NULL) return false;
   if (!result->is_bool()) return false;
   bool old_value = result->get_bool();
+  trace_flag_changed<EventBooleanFlagChanged, bool>(name, old_value, *value, origin);
   result->set_bool(*value);
   *value = old_value;
   result->set_origin(origin);
@@ -615,6 +628,7 @@
 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");
+  trace_flag_changed<EventBooleanFlagChanged, bool>(faddr->_name, faddr->get_bool(), value, origin);
   faddr->set_bool(value);
   faddr->set_origin(origin);
 }
@@ -632,6 +646,7 @@
   if (result == NULL) return false;
   if (!result->is_intx()) return false;
   intx old_value = result->get_intx();
+  trace_flag_changed<EventLongFlagChanged, s8>(name, old_value, *value, origin);
   result->set_intx(*value);
   *value = old_value;
   result->set_origin(origin);
@@ -641,6 +656,7 @@
 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");
+  trace_flag_changed<EventLongFlagChanged, s8>(faddr->_name, faddr->get_intx(), value, origin);
   faddr->set_intx(value);
   faddr->set_origin(origin);
 }
@@ -658,6 +674,7 @@
   if (result == NULL) return false;
   if (!result->is_uintx()) return false;
   uintx old_value = result->get_uintx();
+  trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
   result->set_uintx(*value);
   *value = old_value;
   result->set_origin(origin);
@@ -667,6 +684,7 @@
 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");
+  trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uintx(), value, origin);
   faddr->set_uintx(value);
   faddr->set_origin(origin);
 }
@@ -684,6 +702,7 @@
   if (result == NULL) return false;
   if (!result->is_uint64_t()) return false;
   uint64_t old_value = result->get_uint64_t();
+  trace_flag_changed<EventUnsignedLongFlagChanged, u8>(name, old_value, *value, origin);
   result->set_uint64_t(*value);
   *value = old_value;
   result->set_origin(origin);
@@ -693,6 +712,7 @@
 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");
+  trace_flag_changed<EventUnsignedLongFlagChanged, u8>(faddr->_name, faddr->get_uint64_t(), value, origin);
   faddr->set_uint64_t(value);
   faddr->set_origin(origin);
 }
@@ -710,6 +730,7 @@
   if (result == NULL) return false;
   if (!result->is_double()) return false;
   double old_value = result->get_double();
+  trace_flag_changed<EventDoubleFlagChanged, double>(name, old_value, *value, origin);
   result->set_double(*value);
   *value = old_value;
   result->set_origin(origin);
@@ -719,6 +740,7 @@
 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");
+  trace_flag_changed<EventDoubleFlagChanged, double>(faddr->_name, faddr->get_double(), value, origin);
   faddr->set_double(value);
   faddr->set_origin(origin);
 }
@@ -736,6 +758,7 @@
   if (result == NULL) return false;
   if (!result->is_ccstr()) return false;
   ccstr old_value = result->get_ccstr();
+  trace_flag_changed<EventStringFlagChanged, const char*>(name, old_value, *value, origin);
   char* new_value = NULL;
   if (*value != NULL) {
     new_value = NEW_C_HEAP_ARRAY(char, strlen(*value)+1, mtInternal);
@@ -757,6 +780,7 @@
   Flag* faddr = address_of_flag(flag);
   guarantee(faddr != NULL && faddr->is_ccstr(), "wrong flag type");
   ccstr old_value = faddr->get_ccstr();
+  trace_flag_changed<EventStringFlagChanged, const char*>(faddr->_name, old_value, value, origin);
   char* new_value = NEW_C_HEAP_ARRAY(char, strlen(value)+1, mtInternal);
   strcpy(new_value, value);
   faddr->set_ccstr(new_value);
--- a/hotspot/src/share/vm/trace/trace.xml	Mon Jan 20 09:56:47 2014 +0000
+++ b/hotspot/src/share/vm/trace/trace.xml	Thu Jan 23 08:12:12 2014 +0100
@@ -122,6 +122,46 @@
       <value type="CLASS" field="definingClassLoader" label="Defining Class Loader"/>
     </event>
 
+    <event id="LongFlagChanged" path="vm/flag/long_changed" label="Long Flag Changed"
+          is_instant="true">
+      <value type="UTF8" field="name" label="Name" />
+      <value type="LONG" field="old_value" label="Old Value" />
+      <value type="LONG" field="new_value" label="New Value" />
+      <value type="FLAGVALUEORIGIN" field="origin" label="Origin" />
+    </event>
+
+    <event id="UnsignedLongFlagChanged" path="vm/flag/ulong_changed" label="Unsigned Long Flag Changed"
+          is_instant="true">
+      <value type="UTF8" field="name" label="Name" />
+      <value type="ULONG" field="old_value" label="Old Value" />
+      <value type="ULONG" field="new_value" label="New Value" />
+      <value type="FLAGVALUEORIGIN" field="origin" label="Origin" />
+    </event>
+
+    <event id="DoubleFlagChanged" path="vm/flag/double_changed" label="Double Flag Changed"
+         is_instant="true">
+      <value type="UTF8" field="name" label="Name" />
+      <value type="DOUBLE" field="old_value" label="Old Value" />
+      <value type="DOUBLE" field="new_value" label="New Value" />
+      <value type="FLAGVALUEORIGIN" field="origin" label="Origin" />
+    </event>
+
+    <event id="BooleanFlagChanged" path="vm/flag/boolean_changed" label="Boolean Flag Changed"
+         is_instant="true">
+      <value type="UTF8" field="name" label="Name" />
+      <value type="BOOLEAN" field="old_value" label="Old Value" />
+      <value type="BOOLEAN" field="new_value" label="New Value" />
+      <value type="FLAGVALUEORIGIN" field="origin" label="Origin" />
+    </event>
+
+    <event id="StringFlagChanged" path="vm/flag/string_changed" label="String Flag Changed"
+         is_instant="true">
+      <value type="UTF8" field="name" label="Name" />
+      <value type="UTF8" field="old_value" label="Old Value" />
+      <value type="UTF8" field="new_value" label="New Value" />
+      <value type="FLAGVALUEORIGIN" field="origin" label="Origin" />
+    </event>
+
     <struct id="VirtualSpace">
       <value type="ADDRESS" field="start" label="Start Address" description="Start address of the virtual space" />
       <value type="ADDRESS" field="committedEnd" label="Committed End Address" description="End address of the committed memory for the virtual space" />
--- a/hotspot/src/share/vm/trace/tracetypes.xml	Mon Jan 20 09:56:47 2014 +0000
+++ b/hotspot/src/share/vm/trace/tracetypes.xml	Thu Jan 23 08:12:12 2014 +0100
@@ -150,6 +150,11 @@
       <value type="UTF8" field="phase" label="phase" />
     </content_type>
 
+    <content_type id="FlagValueOrigin" hr_name="Flag Value Origin"
+                  type="U1" jvm_type="FLAGVALUEORIGIN">
+      <value type="UTF8" field="origin" label="origin" />
+    </content_type>
+
   </content_types>
 
 
@@ -334,6 +339,10 @@
     <!-- VMOPERATIONTYPE -->
     <primary_type symbol="VMOPERATIONTYPE" datatype="U2" contenttype="VMOPERATIONTYPE"
                   type="u2" sizeop="sizeof(u2)" />
+                  
+    <!-- FLAGVALUEORIGIN -->
+    <primary_type symbol="FLAGVALUEORIGIN" datatype="U1"
+                  contenttype="FLAGVALUEORIGIN" type="u1" sizeop="sizeof(u1)" />
 
   </primary_types>
 </types>