JDK-6888954 : argument formatting for assert() and friends
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: hs17
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-10-07
  • Updated: 2012-10-13
  • Resolved: 2010-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u21pFixed 7Fixed hs18Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The HotSpot assert(), guarantee(), etc., macros require a message argument which is printed if the condition does not hold, e.g.:

   assert(referent->is_oop(), "bad referent");

As currently implemented the message must be a string literal.  It would be much more useful if multiple arguments could be used with format strings to provide more information, e.g.:

   assert(referent->is_oop(), "bad referent %p", referent);

Comments
SUGGESTED FIX Attached as assert-args.patch.zip.
29-04-2010

EVALUATION http://hg.openjdk.java.net/jdk7/hotspot-gc/hotspot/rev/f03d0a26bf83
29-04-2010

EVALUATION The easiest solution, variadic macros from C99, is not an option for HotSpot because they are not supported by Visual Studio 2003 which is used for Windows jdk6 builds. Could instead use a c++ temporary object to format the arguments and return the result via an operator const char*. Sample usage would be: assert(referent->is_oop(), err_msg("bad referent %p", referent)); where err_msg() constructs a temporary object with an internal buffer and formats the arguments. This allows existing, non-formatted asserts to remain unchanged and eliminates the need for numbered macros (assert1, assert2, etc.).
07-10-2009