RFR: 8022899: SunStudio compiler can not handle EXCEPTION_MARK and inlining
Coleen Phillimore
coleen.phillimore at oracle.com
Tue Aug 13 10:34:44 PDT 2013
This change is fine. The side effect of assigning THREAD from
EXCEPTION_MARK is something the code uses a lot, so it probably
shouldn't be changed.
redefining the macro to be:
#define EXCEPTION_MARK Thread* THREAD = Thread::current();
ExceptionMark em(THREAD);
would enable removing the non-const reference to ExceptionMark
constructor but it might draw in thread.inline.hpp dependencies to
exceptions.hpp, which would be bad.
So I think your change is fine.
Coleen
On 08/13/2013 10:45 AM, Erik Helin wrote:
> Hi all,
>
> this change initializes the Thread* in the EXCEPTION_MARK macro in
> utilities/exception.hpp to NULL to avoid incorrect warnings from the Sun
> Studio 12u1 compiler.
>
> Background:
> HotSpot's exception handling code make use of the EXCEPTION_MARK macro
> defined in utilities/exception.hpp:
>
> #define EXCEPTION_MARK Thread* THREAD; ExceptionMark __em(THREAD);
>
> where THREAD is defined in the same file as:
>
> #define THREAD __the_thread__
>
> The constructor for the class ExceptionMark takes a reference to Thread
> pointer and assigns it:
>
> ExceptionMark::ExceptionMark(Thread*& thread) {
> thread = Thread::current();
> // see utilities/exceptions.cpp for the rest
> }
>
> This means that the Thread pointer __the_thread__ from the
> EXCEPTION_MARK macro will be initialized by the ExceptionMark
> constructor (since it takes a pointer reference as argument).
>
> However, the Sun Studio compiler sometimes gives a warning that the
> Thread pointer __the_thread__ is uninitialized. The following code is an
> example:
>
> memory/example.cpp:
> static void print_str(const char* s, TRAPS) { // TRAPS is defined as:
> tty->print_cr(s); // #define TRAPS Thread* THREAD
> } // in utilities/exception.hpp
>
> static inline void example(const char* s) {
> EXCEPTION_MARK;
>
> print_str(s, THREAD); // line 36
> }
>
> void run_example() {
> example("This will not compile");
> }
>
> memory/example.hpp:
> void run_example();
>
> memory/universe.cpp:
> // include "runtime/example.hpp"
> // add a call to run_example() in universe_post_init
>
> Compiling this with Sun Studio 12u1 will (incorrectly) result in the warning:
> src/share/vm/memory/example.cpp", line 36:
> Warning: The variable __the_thread__ has not yet been assigned a value.
>
> Removing the "inline" keyword from "static inline void example" makes
> the code compiler without warnings.
>
> Solution:
> Change the EXCEPTION_MARK macro to:
>
> #define EXCEPTION_MARK Thread* THREAD = NULL; ExceptionMark __em(THREAD);
>
> Webrev:
> http://cr.openjdk.java.net/~ehelin/8022899/webrev.00/
>
> Testing:
> - JPRT
> - Compiling the example described above successfully
>
> Bug:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8022899
>
> Thanks,
> Erik
More information about the hotspot-dev
mailing list