United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6888954 argument formatting for assert() and friends
6888954 : argument formatting for assert() and friends

Details
Type:
Enhancement
Submit Date:
2009-10-07
Status:
Closed
Updated Date:
2012-10-13
Project Name:
JDK
Resolved Date:
2010-05-18
Component:
hotspot
OS:
generic
Sub-Component:
runtime
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
hs17
Fixed Versions:
hs18

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

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
EVALUATION

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

Attached as assert-args.patch.zip.
                                     
2010-04-29
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.).
                                     
2009-10-07



Hardware and Software, Engineered to Work Together