Sat, 30 Mar 2013 08:01:05 -0700
8011009: Use do-while(0) instead of while(0) in EC_TRACE and RC_TRACE* macros
Summary: Improve EC_TRACE and RC_TRACE* to use the do-while(0) trick for statement-like macro
Reviewed-by: sspitsyn, dcubed
src/share/vm/prims/jvmtiEventController.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/prims/jvmtiRedefineClassesTrace.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/prims/jvmtiEventController.cpp Fri Mar 29 20:52:01 2013 -0700 1.2 +++ b/src/share/vm/prims/jvmtiEventController.cpp Sat Mar 30 08:01:05 2013 -0700 1.3 @@ -39,7 +39,12 @@ 1.4 #include "runtime/vm_operations.hpp" 1.5 1.6 #ifdef JVMTI_TRACE 1.7 -#define EC_TRACE(out) if (JvmtiTrace::trace_event_controller()) { SafeResourceMark rm; tty->print_cr out; } while (0) 1.8 +#define EC_TRACE(out) do { \ 1.9 + if (JvmtiTrace::trace_event_controller()) { \ 1.10 + SafeResourceMark rm; \ 1.11 + tty->print_cr out; \ 1.12 + } \ 1.13 +} while (0) 1.14 #else 1.15 #define EC_TRACE(out) 1.16 #endif /*JVMTI_TRACE */
2.1 --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Fri Mar 29 20:52:01 2013 -0700 2.2 +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Sat Mar 30 08:01:05 2013 -0700 2.3 @@ -72,36 +72,6 @@ 2.4 // 0x20000000 | 536870912 - unused 2.5 // 0x40000000 | 1073741824 - unused 2.6 // 0x80000000 | 2147483648 - unused 2.7 -// 2.8 -// Note: The ResourceMark is to cleanup resource allocated args. 2.9 -// The "while (0)" is so we can use semi-colon at end of RC_TRACE(). 2.10 -#define RC_TRACE(level, args) \ 2.11 - if ((TraceRedefineClasses & level) != 0) { \ 2.12 - ResourceMark rm; \ 2.13 - tty->print("RedefineClasses-0x%x: ", level); \ 2.14 - tty->print_cr args; \ 2.15 - } while (0) 2.16 - 2.17 -#define RC_TRACE_NO_CR(level, args) \ 2.18 - if ((TraceRedefineClasses & level) != 0) { \ 2.19 - ResourceMark rm; \ 2.20 - tty->print("RedefineClasses-0x%x: ", level); \ 2.21 - tty->print args; \ 2.22 - } while (0) 2.23 - 2.24 -#define RC_TRACE_WITH_THREAD(level, thread, args) \ 2.25 - if ((TraceRedefineClasses & level) != 0) { \ 2.26 - ResourceMark rm(thread); \ 2.27 - tty->print("RedefineClasses-0x%x: ", level); \ 2.28 - tty->print_cr args; \ 2.29 - } while (0) 2.30 - 2.31 -#define RC_TRACE_MESG(args) \ 2.32 - { \ 2.33 - ResourceMark rm; \ 2.34 - tty->print("RedefineClasses: "); \ 2.35 - tty->print_cr args; \ 2.36 - } while (0) 2.37 2.38 // Macro for checking if TraceRedefineClasses has a specific bit 2.39 // enabled. Returns true if the bit specified by level is set. 2.40 @@ -120,16 +90,49 @@ 2.41 #define RC_TRACE_IN_RANGE(low, high) \ 2.42 (((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0) 2.43 2.44 -// Timer support macros. Only do timer operations if timer tracing 2.45 -// is enabled. The "while (0)" is so we can use semi-colon at end of 2.46 -// the macro. 2.47 -#define RC_TIMER_START(t) \ 2.48 +// Note: The ResourceMark is to cleanup resource allocated args. 2.49 +// The "do {...} while (0)" is so we can use semi-colon at end of RC_TRACE(). 2.50 +#define RC_TRACE(level, args) do { \ 2.51 + if (RC_TRACE_ENABLED(level)) { \ 2.52 + ResourceMark rm; \ 2.53 + tty->print("RedefineClasses-0x%x: ", level); \ 2.54 + tty->print_cr args; \ 2.55 + } \ 2.56 +} while (0) 2.57 + 2.58 +#define RC_TRACE_NO_CR(level, args) do { \ 2.59 + if (RC_TRACE_ENABLED(level)) { \ 2.60 + ResourceMark rm; \ 2.61 + tty->print("RedefineClasses-0x%x: ", level); \ 2.62 + tty->print args; \ 2.63 + } \ 2.64 +} while (0) 2.65 + 2.66 +#define RC_TRACE_WITH_THREAD(level, thread, args) do { \ 2.67 + if (RC_TRACE_ENABLED(level)) { \ 2.68 + ResourceMark rm(thread); \ 2.69 + tty->print("RedefineClasses-0x%x: ", level); \ 2.70 + tty->print_cr args; \ 2.71 + } \ 2.72 +} while (0) 2.73 + 2.74 +#define RC_TRACE_MESG(args) do { \ 2.75 + ResourceMark rm; \ 2.76 + tty->print("RedefineClasses: "); \ 2.77 + tty->print_cr args; \ 2.78 +} while (0) 2.79 + 2.80 +// Timer support macros. Only do timer operations if timer tracing is enabled. 2.81 +// The "do {...} while (0)" is so we can use semi-colon at end of the macro. 2.82 +#define RC_TIMER_START(t) do { \ 2.83 if (RC_TRACE_ENABLED(0x00000004)) { \ 2.84 t.start(); \ 2.85 - } while (0) 2.86 -#define RC_TIMER_STOP(t) \ 2.87 + } \ 2.88 +} while (0) 2.89 +#define RC_TIMER_STOP(t) do { \ 2.90 if (RC_TRACE_ENABLED(0x00000004)) { \ 2.91 t.stop(); \ 2.92 - } while (0) 2.93 + } \ 2.94 +} while (0) 2.95 2.96 #endif // SHARE_VM_PRIMS_JVMTIREDEFINECLASSESTRACE_HPP