RFR: 8022899: SunStudio compiler can not handle EXCEPTION_MARK and inlining

Erik Helin erik.helin at oracle.com
Tue Aug 13 07:45:56 PDT 2013


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