src/share/vm/code/codeBlob.hpp

Thu, 22 Jul 2010 15:29:22 -0700

author
never
date
Thu, 22 Jul 2010 15:29:22 -0700
changeset 2018
7139e81efd2d
parent 1934
e9ff18c4ace7
child 2036
126ea7725993
permissions
-rw-r--r--

6970566: runThese fails with SIGSEGV
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    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  */
    25 // CodeBlob - superclass for all entries in the CodeCache.
    26 //
    27 // Suptypes are:
    28 //   nmethod            : Compiled Java methods (include method that calls to native code)
    29 //   RuntimeStub        : Call to VM runtime methods
    30 //   DeoptimizationBlob : Used for deoptimizatation
    31 //   ExceptionBlob      : Used for stack unrolling
    32 //   SafepointBlob      : Used to handle illegal instruction exceptions
    33 //
    34 //
    35 // Layout:
    36 //   - header
    37 //   - relocation
    38 //   - instruction space
    39 //   - data space
    40 class DeoptimizationBlob;
    42 class CodeBlob VALUE_OBJ_CLASS_SPEC {
    44   friend class VMStructs;
    46  private:
    47   const char* _name;
    48   int        _size;                              // total size of CodeBlob in bytes
    49   int        _header_size;                       // size of header (depends on subclass)
    50   int        _relocation_size;                   // size of relocation
    51   int        _instructions_offset;               // offset to where instructions region begins
    52   int        _frame_complete_offset;             // instruction offsets in [0.._frame_complete_offset) have
    53                                                  // not finished setting up their frame. Beware of pc's in
    54                                                  // that range. There is a similar range(s) on returns
    55                                                  // which we don't detect.
    56   int        _data_offset;                       // offset to where data region begins
    57   int        _frame_size;                        // size of stack frame
    58   OopMapSet* _oop_maps;                          // OopMap for this CodeBlob
    59   CodeComments _comments;
    61   friend class OopRecorder;
    63  public:
    64   // Returns the space needed for CodeBlob
    65   static unsigned int allocation_size(CodeBuffer* cb, int header_size);
    67   // Creation
    68   // a) simple CodeBlob
    69   // frame_complete is the offset from the beginning of the instructions
    70   // to where the frame setup (from stackwalk viewpoint) is complete.
    71   CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size);
    73   // b) full CodeBlob
    74   CodeBlob(
    75     const char* name,
    76     CodeBuffer* cb,
    77     int         header_size,
    78     int         size,
    79     int         frame_complete,
    80     int         frame_size,
    81     OopMapSet*  oop_maps
    82   );
    84   // Deletion
    85   void flush();
    87   // Typing
    88   virtual bool is_buffer_blob() const                 { return false; }
    89   virtual bool is_nmethod() const                     { return false; }
    90   virtual bool is_runtime_stub() const                { return false; }
    91   virtual bool is_deoptimization_stub() const         { return false; }
    92   virtual bool is_uncommon_trap_stub() const          { return false; }
    93   virtual bool is_exception_stub() const              { return false; }
    94   virtual bool is_safepoint_stub() const              { return false; }
    95   virtual bool is_adapter_blob() const                { return false; }
    96   virtual bool is_method_handles_adapter_blob() const { return false; }
    98   virtual bool is_compiled_by_c2() const         { return false; }
    99   virtual bool is_compiled_by_c1() const         { return false; }
   101   // Casting
   102   nmethod* as_nmethod_or_null()                  { return is_nmethod() ? (nmethod*) this : NULL; }
   104   // Boundaries
   105   address    header_begin() const                { return (address)    this; }
   106   address    header_end() const                  { return ((address)   this) + _header_size; };
   107   relocInfo* relocation_begin() const            { return (relocInfo*) header_end(); };
   108   relocInfo* relocation_end() const              { return (relocInfo*)(header_end()   + _relocation_size); }
   109   address    instructions_begin() const          { return (address)    header_begin() + _instructions_offset;  }
   110   address    instructions_end() const            { return (address)    header_begin() + _data_offset; }
   111   address    data_begin() const                  { return (address)    header_begin() + _data_offset; }
   112   address    data_end() const                    { return (address)    header_begin() + _size; }
   114   // Offsets
   115   int relocation_offset() const                  { return _header_size; }
   116   int instructions_offset() const                { return _instructions_offset; }
   117   int data_offset() const                        { return _data_offset; }
   119   // Sizes
   120   int size() const                               { return _size; }
   121   int header_size() const                        { return _header_size; }
   122   int relocation_size() const                    { return (address) relocation_end() - (address) relocation_begin(); }
   123   int instructions_size() const                  { return instructions_end() - instructions_begin();  }
   124   int data_size() const                          { return data_end() - data_begin(); }
   126   // Containment
   127   bool blob_contains(address addr) const         { return header_begin()       <= addr && addr < data_end(); }
   128   bool relocation_contains(relocInfo* addr) const{ return relocation_begin()   <= addr && addr < relocation_end(); }
   129   bool instructions_contains(address addr) const { return instructions_begin() <= addr && addr < instructions_end(); }
   130   bool data_contains(address addr) const         { return data_begin()         <= addr && addr < data_end(); }
   131   bool contains(address addr) const              { return instructions_contains(addr); }
   132   bool is_frame_complete_at(address addr) const  { return instructions_contains(addr) &&
   133                                                           addr >= instructions_begin() + _frame_complete_offset; }
   135   // CodeCache support: really only used by the nmethods, but in order to get
   136   // asserts and certain bookkeeping to work in the CodeCache they are defined
   137   // virtual here.
   138   virtual bool is_zombie() const                 { return false; }
   139   virtual bool is_locked_by_vm() const           { return false; }
   141   virtual bool is_unloaded() const               { return false; }
   142   virtual bool is_not_entrant() const            { return false; }
   144   // GC support
   145   virtual bool is_alive() const                  = 0;
   147   // OopMap for frame
   148   OopMapSet* oop_maps() const                    { return _oop_maps; }
   149   void set_oop_maps(OopMapSet* p);
   150   OopMap* oop_map_for_return_address(address return_address);
   151   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { ShouldNotReachHere(); }
   153   // Frame support
   154   int  frame_size() const                        { return _frame_size; }
   155   void set_frame_size(int size)                  { _frame_size = size; }
   157   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
   158   virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; }
   160   // Naming
   161   const char* name() const                       { return _name; }
   162   void set_name(const char* name)                { _name = name; }
   164   // Debugging
   165   virtual void verify();
   166   virtual void print() const                     PRODUCT_RETURN;
   167   virtual void print_value_on(outputStream* st) const PRODUCT_RETURN;
   169   // Print the comment associated with offset on stream, if there is one
   170   virtual void print_block_comment(outputStream* stream, address block_begin) {
   171     intptr_t offset = (intptr_t)(block_begin - instructions_begin());
   172     _comments.print_block_comment(stream, offset);
   173   }
   175   // Transfer ownership of comments to this CodeBlob
   176   void set_comments(CodeComments& comments) {
   177     _comments.assign(comments);
   178   }
   179 };
   182 //----------------------------------------------------------------------------------------------------
   183 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
   185 class BufferBlob: public CodeBlob {
   186   friend class VMStructs;
   187   friend class AdapterBlob;
   188   friend class MethodHandlesAdapterBlob;
   190  private:
   191   // Creation support
   192   BufferBlob(const char* name, int size);
   193   BufferBlob(const char* name, int size, CodeBuffer* cb);
   195   void* operator new(size_t s, unsigned size);
   197  public:
   198   // Creation
   199   static BufferBlob* create(const char* name, int buffer_size);
   200   static BufferBlob* create(const char* name, CodeBuffer* cb);
   202   static void free(BufferBlob* buf);
   204   // Typing
   205   virtual bool is_buffer_blob() const            { return true; }
   207   // GC/Verification support
   208   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
   209   bool is_alive() const                          { return true; }
   211   void verify();
   212   void print() const                             PRODUCT_RETURN;
   213   void print_value_on(outputStream* st) const    PRODUCT_RETURN;
   214 };
   217 //----------------------------------------------------------------------------------------------------
   218 // AdapterBlob: used to hold C2I/I2C adapters
   220 class AdapterBlob: public BufferBlob {
   221 private:
   222   AdapterBlob(int size, CodeBuffer* cb);
   224 public:
   225   // Creation
   226   static AdapterBlob* create(CodeBuffer* cb);
   228   // Typing
   229   virtual bool is_adapter_blob() const { return true; }
   230 };
   233 //----------------------------------------------------------------------------------------------------
   234 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
   236 class MethodHandlesAdapterBlob: public BufferBlob {
   237 private:
   238   MethodHandlesAdapterBlob(int size)                 : BufferBlob("MethodHandles adapters", size) {}
   239   MethodHandlesAdapterBlob(int size, CodeBuffer* cb) : BufferBlob("MethodHandles adapters", size, cb) {}
   241 public:
   242   // Creation
   243   static MethodHandlesAdapterBlob* create(int buffer_size);
   245   // Typing
   246   virtual bool is_method_handles_adapter_blob() const { return true; }
   247 };
   250 //----------------------------------------------------------------------------------------------------
   251 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
   253 class RuntimeStub: public CodeBlob {
   254   friend class VMStructs;
   255  private:
   256   bool        _caller_must_gc_arguments;
   258   // Creation support
   259   RuntimeStub(
   260     const char* name,
   261     CodeBuffer* cb,
   262     int         size,
   263     int         frame_complete,
   264     int         frame_size,
   265     OopMapSet*  oop_maps,
   266     bool        caller_must_gc_arguments
   267   );
   269   void* operator new(size_t s, unsigned size);
   271  public:
   272   // Creation
   273   static RuntimeStub* new_runtime_stub(
   274     const char* stub_name,
   275     CodeBuffer* cb,
   276     int         frame_complete,
   277     int         frame_size,
   278     OopMapSet*  oop_maps,
   279     bool        caller_must_gc_arguments
   280   );
   282   // Typing
   283   bool is_runtime_stub() const                   { return true; }
   285   // GC support
   286   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
   288   address entry_point()                          { return instructions_begin(); }
   290   // GC/Verification support
   291   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
   292   bool is_alive() const                          { return true; }
   294   void verify();
   295   void print() const                             PRODUCT_RETURN;
   296   void print_value_on(outputStream* st) const    PRODUCT_RETURN;
   297 };
   300 //----------------------------------------------------------------------------------------------------
   301 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
   303 class SingletonBlob: public CodeBlob {
   304   friend class VMStructs;
   305   public:
   306    SingletonBlob(
   307      const char* name,
   308      CodeBuffer* cb,
   309      int         header_size,
   310      int         size,
   311      int         frame_size,
   312      OopMapSet*  oop_maps
   313    )
   314    : CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
   315    {};
   317    bool is_alive() const                         { return true; }
   319    void verify(); // does nothing
   320    void print() const                            PRODUCT_RETURN;
   321    void print_value_on(outputStream* st) const   PRODUCT_RETURN;
   322 };
   325 //----------------------------------------------------------------------------------------------------
   326 // DeoptimizationBlob
   328 class DeoptimizationBlob: public SingletonBlob {
   329   friend class VMStructs;
   330  private:
   331   int _unpack_offset;
   332   int _unpack_with_exception;
   333   int _unpack_with_reexecution;
   335   int _unpack_with_exception_in_tls;
   337   // Creation support
   338   DeoptimizationBlob(
   339     CodeBuffer* cb,
   340     int         size,
   341     OopMapSet*  oop_maps,
   342     int         unpack_offset,
   343     int         unpack_with_exception_offset,
   344     int         unpack_with_reexecution_offset,
   345     int         frame_size
   346   );
   348   void* operator new(size_t s, unsigned size);
   350  public:
   351   // Creation
   352   static DeoptimizationBlob* create(
   353     CodeBuffer* cb,
   354     OopMapSet*  oop_maps,
   355     int         unpack_offset,
   356     int         unpack_with_exception_offset,
   357     int         unpack_with_reexecution_offset,
   358     int         frame_size
   359   );
   361   // Typing
   362   bool is_deoptimization_stub() const { return true; }
   363   const DeoptimizationBlob *as_deoptimization_stub() const { return this; }
   364   bool exception_address_is_unpack_entry(address pc) const {
   365     address unpack_pc = unpack();
   366     return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc);
   367   }
   372   // GC for args
   373   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
   375   // Printing
   376   void print_value_on(outputStream* st) const PRODUCT_RETURN;
   378   address unpack() const                         { return instructions_begin() + _unpack_offset;           }
   379   address unpack_with_exception() const          { return instructions_begin() + _unpack_with_exception;   }
   380   address unpack_with_reexecution() const        { return instructions_begin() + _unpack_with_reexecution; }
   382   // Alternate entry point for C1 where the exception and issuing pc
   383   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
   384   // instead of being in registers.  This is needed because C1 doesn't
   385   // model exception paths in a way that keeps these registers free so
   386   // there may be live values in those registers during deopt.
   387   void set_unpack_with_exception_in_tls_offset(int offset) {
   388     _unpack_with_exception_in_tls = offset;
   389     assert(contains(instructions_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
   390   }
   391   address unpack_with_exception_in_tls() const   { return instructions_begin() + _unpack_with_exception_in_tls;   }
   392 };
   395 //----------------------------------------------------------------------------------------------------
   396 // UncommonTrapBlob (currently only used by Compiler 2)
   398 #ifdef COMPILER2
   400 class UncommonTrapBlob: public SingletonBlob {
   401   friend class VMStructs;
   402  private:
   403   // Creation support
   404   UncommonTrapBlob(
   405     CodeBuffer* cb,
   406     int         size,
   407     OopMapSet*  oop_maps,
   408     int         frame_size
   409   );
   411   void* operator new(size_t s, unsigned size);
   413  public:
   414   // Creation
   415   static UncommonTrapBlob* create(
   416     CodeBuffer* cb,
   417     OopMapSet*  oop_maps,
   418     int         frame_size
   419   );
   421   // GC for args
   422   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
   424   // Typing
   425   bool is_uncommon_trap_stub() const             { return true; }
   426 };
   429 //----------------------------------------------------------------------------------------------------
   430 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
   432 class ExceptionBlob: public SingletonBlob {
   433   friend class VMStructs;
   434  private:
   435   // Creation support
   436   ExceptionBlob(
   437     CodeBuffer* cb,
   438     int         size,
   439     OopMapSet*  oop_maps,
   440     int         frame_size
   441   );
   443   void* operator new(size_t s, unsigned size);
   445  public:
   446   // Creation
   447   static ExceptionBlob* create(
   448     CodeBuffer* cb,
   449     OopMapSet*  oop_maps,
   450     int         frame_size
   451   );
   453   // GC for args
   454   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
   456   // Typing
   457   bool is_exception_stub() const                 { return true; }
   458 };
   459 #endif // COMPILER2
   462 //----------------------------------------------------------------------------------------------------
   463 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
   465 class SafepointBlob: public SingletonBlob {
   466   friend class VMStructs;
   467  private:
   468   // Creation support
   469   SafepointBlob(
   470     CodeBuffer* cb,
   471     int         size,
   472     OopMapSet*  oop_maps,
   473     int         frame_size
   474   );
   476   void* operator new(size_t s, unsigned size);
   478  public:
   479   // Creation
   480   static SafepointBlob* create(
   481     CodeBuffer* cb,
   482     OopMapSet*  oop_maps,
   483     int         frame_size
   484   );
   486   // GC for args
   487   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
   489   // Typing
   490   bool is_safepoint_stub() const                 { return true; }
   491 };

mercurial