< prev index next >

src/hotspot/share/runtime/stubCodeGenerator.hpp

Print this page
rev 51308 : 8206267: Unsafe publication of StubCodeDesc leads to crashes
Reviewed-by: kvn


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
  26 #define SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
  27 
  28 #include "asm/assembler.hpp"
  29 #include "memory/allocation.hpp"

  30 
  31 // All the basic framework for stub code generation/debugging/printing.
  32 
  33 
  34 // A StubCodeDesc describes a piece of generated code (usually stubs).
  35 // This information is mainly useful for debugging and printing.
  36 // Currently, code descriptors are simply chained in a linked list,
  37 // this may have to change if searching becomes too slow.
  38 
  39 class StubCodeDesc: public CHeapObj<mtCode> {
  40  private:
  41   static StubCodeDesc* _list;                  // the list of all descriptors
  42   static bool          _frozen;                // determines whether _list modifications are allowed
  43 
  44   StubCodeDesc*        _next;                  // the next element in the linked list
  45   const char*          _group;                 // the group to which the stub code belongs
  46   const char*          _name;                  // the name assigned to the stub code
  47   address              _begin;                 // points to the first byte of the stub code    (included)
  48   address              _end;                   // points to the first byte after the stub code (excluded)
  49 
  50   void set_end(address end) {
  51     assert(_begin <= end, "begin & end not properly ordered");
  52     _end = end;
  53   }
  54 
  55   void set_begin(address begin) {
  56     assert(begin >= _begin, "begin may not decrease");
  57     assert(_end == NULL || begin <= _end, "begin & end not properly ordered");
  58     _begin = begin;
  59   }
  60 
  61   friend class StubCodeMark;
  62   friend class StubCodeGenerator;
  63 
  64  public:
  65   static StubCodeDesc* first() { return _list; }
  66   static StubCodeDesc* next(StubCodeDesc* desc)  { return desc->_next; }
  67 
  68   static StubCodeDesc* desc_for(address pc);     // returns the code descriptor for the code containing pc or NULL
  69   static const char*   name_for(address pc);     // returns the name of the code containing pc or NULL
  70 
  71   StubCodeDesc(const char* group, const char* name, address begin, address end = NULL) {
  72     assert(!_frozen, "no modifications allowed");
  73     assert(name != NULL, "no name specified");
  74     _next           = _list;
  75     _group          = group;
  76     _name           = name;
  77     _begin          = begin;
  78     _end            = end;
  79     _list           = this;
  80   };
  81 
  82   static void freeze();
  83 
  84   const char* group() const                      { return _group; }
  85   const char* name() const                       { return _name; }
  86   address     begin() const                      { return _begin; }
  87   address     end() const                        { return _end; }
  88   int         size_in_bytes() const              { return _end - _begin; }
  89   bool        contains(address pc) const         { return _begin <= pc && pc < _end; }
  90   void        print_on(outputStream* st) const;
  91   void        print() const                      { print_on(tty); }
  92 };
  93 
  94 // The base class for all stub-generating code generators.
  95 // Provides utility functions.
  96 
  97 class StubCodeGenerator: public StackObj {
  98  private:
  99   bool _print_code;




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
  26 #define SHARE_VM_RUNTIME_STUBCODEGENERATOR_HPP
  27 
  28 #include "asm/assembler.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "runtime/orderAccess.hpp"
  31 
  32 // All the basic framework for stub code generation/debugging/printing.
  33 
  34 
  35 // A StubCodeDesc describes a piece of generated code (usually stubs).
  36 // This information is mainly useful for debugging and printing.
  37 // Currently, code descriptors are simply chained in a linked list,
  38 // this may have to change if searching becomes too slow.
  39 
  40 class StubCodeDesc: public CHeapObj<mtCode> {
  41  private:
  42   static StubCodeDesc *volatile _list;         // the list of all descriptors
  43   static bool                   _frozen;       // determines whether _list modifications are allowed
  44 
  45   StubCodeDesc*                 _next;         // the next element in the linked list
  46   const char*                   _group;        // the group to which the stub code belongs
  47   const char*                   _name;         // the name assigned to the stub code
  48   address                       _begin;        // points to the first byte of the stub code    (included)
  49   address                       _end;          // points to the first byte after the stub code (excluded)
  50 
  51   void set_end(address end) {
  52     assert(_begin <= end, "begin & end not properly ordered");
  53     _end = end;
  54   }
  55 
  56   void set_begin(address begin) {
  57     assert(begin >= _begin, "begin may not decrease");
  58     assert(_end == NULL || begin <= _end, "begin & end not properly ordered");
  59     _begin = begin;
  60   }
  61 
  62   friend class StubCodeMark;
  63   friend class StubCodeGenerator;
  64 
  65  public:
  66   static StubCodeDesc* first() { return _list; }
  67   static StubCodeDesc* next(StubCodeDesc* desc)  { return desc->_next; }
  68 
  69   static StubCodeDesc* desc_for(address pc);     // returns the code descriptor for the code containing pc or NULL
  70   static const char*   name_for(address pc);     // returns the name of the code containing pc or NULL
  71 
  72   StubCodeDesc(const char* group, const char* name, address begin, address end = NULL) {
  73     assert(!_frozen, "no modifications allowed");
  74     assert(name != NULL, "no name specified");
  75     _next           = _list;
  76     _group          = group;
  77     _name           = name;
  78     _begin          = begin;
  79     _end            = end;
  80     OrderAccess::release_store(&_list, this);
  81   };
  82 
  83   static void freeze();
  84 
  85   const char* group() const                      { return _group; }
  86   const char* name() const                       { return _name; }
  87   address     begin() const                      { return _begin; }
  88   address     end() const                        { return _end; }
  89   int         size_in_bytes() const              { return _end - _begin; }
  90   bool        contains(address pc) const         { return _begin <= pc && pc < _end; }
  91   void        print_on(outputStream* st) const;
  92   void        print() const                      { print_on(tty); }
  93 };
  94 
  95 // The base class for all stub-generating code generators.
  96 // Provides utility functions.
  97 
  98 class StubCodeGenerator: public StackObj {
  99  private:
 100   bool _print_code;


< prev index next >