Reported by Xin Liu (xxinliu@amazon.com).
If you invoke java with the option -XX:+EnableTracing, it will crash immediately. It's because events XXXFlagChanged doesn't work in the initial thread.
class EventBooleanFlagChanged : public TraceEvent<EventBooleanFlagChanged>
EventBooleanFlagChanged(EventStartTime timing=TIMED) : TraceEvent<EventBooleanFlagChanged>(timing) {}
void writeEvent(void) {
ResourceMark rm;
if (UseLockedTracing) {
ttyLocker lock;
writeEventContent();
} else {
writeEventContent();
}
}
};
The ResourceMark won't work if Thread::current() is NULL.
A simple patch for OpenJDK follows, but won't work for OracleJDK.
diff --git a/src/hotspot/src/share/vm/runtime/globals.cpp b/src/hotspot/src/share/vm/runtime/globals.cpp
index 310fc2ea..6f89c275 100644
--- a/src/hotspot/src/share/vm/runtime/globals.cpp
+++ b/src/hotspot/src/share/vm/runtime/globals.cpp
@@ -608,12 +608,12 @@ bool CommandLineFlags::wasSetOnCmdline(const char* name, bool* value) {
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();
+ //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(const char* name, size_t len, bool* value) {