Print this page
rev 1839 : 6961690: load oops from constant table on SPARC
Summary: oops should be loaded from the constant table of an nmethod instead of materializing them with a long code sequence.
Reviewed-by:

Split Close
Expand all
Collapse all
          --- old/src/share/vm/opto/compile.hpp
          +++ new/src/share/vm/opto/compile.hpp
↓ open down ↓ 22 lines elided ↑ open up ↑
  23   23   */
  24   24  
  25   25  class Block;
  26   26  class Bundle;
  27   27  class C2Compiler;
  28   28  class CallGenerator;
  29   29  class ConnectionGraph;
  30   30  class InlineTree;
  31   31  class Int_Array;
  32   32  class Matcher;
       33 +class MachConstantNode;
       34 +class MachConstantBaseNode;
  33   35  class MachNode;
       36 +class MachOper;
  34   37  class MachSafePointNode;
  35   38  class Node;
  36   39  class Node_Array;
  37   40  class Node_Notes;
  38   41  class OptoReg;
  39   42  class PhaseCFG;
  40   43  class PhaseGVN;
  41   44  class PhaseIterGVN;
  42   45  class PhaseRegAlloc;
  43   46  class PhaseCCP;
↓ open down ↓ 70 lines elided ↑ open up ↑
 114  117  
 115  118    enum {
 116  119      logAliasCacheSize = 6,
 117  120      AliasCacheSize = (1<<logAliasCacheSize)
 118  121    };
 119  122    struct AliasCacheEntry { const TypePtr* _adr_type; int _index; };  // simple duple type
 120  123    enum {
 121  124      trapHistLength = methodDataOopDesc::_trap_hist_limit
 122  125    };
 123  126  
      127 +  // Constant entry of the constant table.
      128 +  class Constant {
      129 +  private:
      130 +    BasicType _type;
      131 +    jvalue    _value;
      132 +    int       _offset;         // offset of this constant (in bytes) relative to the constant table base.
      133 +    bool      _can_be_reused;  // true (default) if the value can be shared with other users.
      134 +
      135 +  public:
      136 +    Constant() : _type(T_ILLEGAL), _offset(-1), _can_be_reused(true) { _value.l = 0; }
      137 +    Constant(BasicType type, jvalue value, bool can_be_reused = true) :
      138 +      _type(type),
      139 +      _value(value),
      140 +      _offset(-1),
      141 +      _can_be_reused(can_be_reused)
      142 +    {}
      143 +
      144 +    bool operator==(const Constant& other);
      145 +
      146 +    BasicType type()      const    { return _type; }
      147 +
      148 +    jlong   get_jlong()   const    { return _value.j; }
      149 +    jfloat  get_jfloat()  const    { return _value.f; }
      150 +    jdouble get_jdouble() const    { return _value.d; }
      151 +    jobject get_jobject() const    { return _value.l; }
      152 +
      153 +    int         offset()  const    { return _offset; }
      154 +    void    set_offset(int offset) {        _offset = offset; }
      155 +
      156 +    bool    can_be_reused() const  { return _can_be_reused; }
      157 +  };
      158 +
      159 +  // Constant table.
      160 +  class ConstantTable {
      161 +  private:
      162 +    GrowableArray<Constant> _constants;          // Constants of this table.
      163 +    int                     _size;               // Size in bytes the emitted constant table takes (including padding).
      164 +    int                     _table_base_offset;  // Offset of the table base that gets added to the constant offsets.
      165 +
      166 +  public:
      167 +    ConstantTable() :
      168 +      _size(-1),
      169 +      _table_base_offset(-1)  // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit).
      170 +    {}
      171 +
      172 +    int  size() const { assert(_size != -1, "size not yet calculated"); return _size; }
      173 +
      174 +    void set_table_base_offset(int x)  { assert(_table_base_offset == -1, "set only once");                        _table_base_offset = x; }
      175 +    int      table_base_offset() const { assert(_table_base_offset != -1, "table base offset not yet set"); return _table_base_offset; }
      176 +
      177 +    void emit(CodeBuffer& cb);
      178 +
      179 +    // Returns the offset of the last entry (the top) of the constant table.
      180 +    int  top_offset() const { assert(_constants.top().offset() != -1, "constant not yet bound"); return _constants.top().offset(); }
      181 +
      182 +    void calculate_offsets_and_size();
      183 +    int  find_offset(Constant& con) const;
      184 +
      185 +    void     add(Constant& con);
      186 +    Constant add(BasicType type, jvalue value);
      187 +    Constant add(MachOper* oper);
      188 +    Constant add(jfloat f) {
      189 +      jvalue value; value.f = f;
      190 +      return add(T_FLOAT, value);
      191 +    }
      192 +    Constant add(jdouble d) {
      193 +      jvalue value; value.d = d;
      194 +      return add(T_DOUBLE, value);
      195 +    }
      196 +
      197 +    // Jump table
      198 +    Constant allocate_jump_table(MachConstantNode* n);
      199 +    void         fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const;
      200 +  };
      201 +
 124  202   private:
 125  203    // Fixed parameters to this compilation.
 126  204    const int             _compile_id;
 127  205    const bool            _save_argument_registers; // save/restore arg regs for trampolines
 128  206    const bool            _subsume_loads;         // Load can be matched as part of a larger op.
 129  207    const bool            _do_escape_analysis;    // Do escape analysis.
 130  208    ciMethod*             _method;                // The method being compiled.
 131  209    int                   _entry_bci;             // entry bci for osr methods.
 132  210    const TypeFunc*       _tf;                    // My kind of signature
 133  211    InlineTree*           _ilt;                   // Ditto (temporary).
↓ open down ↓ 53 lines elided ↑ open up ↑
 187  265    Arena                 _node_arena;            // Arena for new-space Nodes
 188  266    Arena                 _old_arena;             // Arena for old-space Nodes, lifetime during xform
 189  267    RootNode*             _root;                  // Unique root of compilation, or NULL after bail-out.
 190  268    Node*                 _top;                   // Unique top node.  (Reset by various phases.)
 191  269  
 192  270    Node*                 _immutable_memory;      // Initial memory state
 193  271  
 194  272    Node*                 _recent_alloc_obj;
 195  273    Node*                 _recent_alloc_ctl;
 196  274  
      275 +  // Constant table
      276 +  ConstantTable         _constant_table;        // The constant table for this compile.
      277 +  MachConstantBaseNode* _mach_constant_base_node;  // Constant table base node singleton.
      278 +
      279 +
 197  280    // Blocked array of debugging and profiling information,
 198  281    // tracked per node.
 199  282    enum { _log2_node_notes_block_size = 8,
 200  283           _node_notes_block_size = (1<<_log2_node_notes_block_size)
 201  284    };
 202  285    GrowableArray<Node_Notes*>* _node_note_array;
 203  286    Node_Notes*           _default_node_notes;  // default notes for new nodes
 204  287  
 205  288    // After parsing and every bulk phase we hang onto the Root instruction.
 206  289    // The RootNode instruction is where the whole program begins.  It produces
↓ open down ↓ 40 lines elided ↑ open up ↑
 247  330    // Instruction bits passed off to the VM
 248  331    int                   _method_size;           // Size of nmethod code segment in bytes
 249  332    CodeBuffer            _code_buffer;           // Where the code is assembled
 250  333    int                   _first_block_size;      // Size of unvalidated entry point code / OSR poison code
 251  334    ExceptionHandlerTable _handler_table;         // Table of native-code exception handlers
 252  335    ImplicitExceptionTable _inc_table;            // Table of implicit null checks in native code
 253  336    OopMapSet*            _oop_map_set;           // Table of oop maps (one for each safepoint location)
 254  337    static int            _CompiledZap_count;     // counter compared against CompileZap[First/Last]
 255  338    BufferBlob*           _scratch_buffer_blob;   // For temporary code buffers.
 256  339    relocInfo*            _scratch_locs_memory;   // For temporary code buffers.
      340 +  int                   _scratch_const_size;    // For temporary code buffers.
      341 +  bool                  _in_scratch_emit_size;  // true when in scratch_emit_size.
 257  342  
 258  343   public:
 259  344    // Accessors
 260  345  
 261  346    // The Compile instance currently active in this (compiler) thread.
 262  347    static Compile* current() {
 263  348      return (Compile*) ciEnv::current()->compiler_data();
 264  349    }
 265  350  
 266  351    // ID for this compilation.  Useful for setting breakpoints in the debugger.
↓ open down ↓ 162 lines elided ↑ open up ↑
 429  514    void         init_start(StartNode* s);
 430  515    Node*             immutable_memory();
 431  516  
 432  517    Node*             recent_alloc_ctl() const    { return _recent_alloc_ctl; }
 433  518    Node*             recent_alloc_obj() const    { return _recent_alloc_obj; }
 434  519    void          set_recent_alloc(Node* ctl, Node* obj) {
 435  520                                                    _recent_alloc_ctl = ctl;
 436  521                                                    _recent_alloc_obj = obj;
 437  522                                                  }
 438  523  
      524 +  // Constant table
      525 +  ConstantTable&   constant_table() { return _constant_table; }
      526 +
      527 +  MachConstantBaseNode*     mach_constant_base_node();
      528 +  bool                  has_mach_constant_base_node() const { return _mach_constant_base_node != NULL; }
      529 +
 439  530    // Handy undefined Node
 440  531    Node*             top() const                 { return _top; }
 441  532  
 442  533    // these are used by guys who need to know about creation and transformation of top:
 443  534    Node*             cached_top_node()           { return _top; }
 444  535    void          set_cached_top_node(Node* tn);
 445  536  
 446  537    GrowableArray<Node_Notes*>* node_note_array() const { return _node_note_array; }
 447  538    void set_node_note_array(GrowableArray<Node_Notes*>* arr) { _node_note_array = arr; }
 448  539    Node_Notes* default_node_notes() const        { return _default_node_notes; }
↓ open down ↓ 131 lines elided ↑ open up ↑
 580  671    CodeBuffer*       code_buffer()               { return &_code_buffer; }
 581  672    int               first_block_size()          { return _first_block_size; }
 582  673    void              set_frame_complete(int off) { _code_offsets.set_value(CodeOffsets::Frame_Complete, off); }
 583  674    ExceptionHandlerTable*  handler_table()       { return &_handler_table; }
 584  675    ImplicitExceptionTable* inc_table()           { return &_inc_table; }
 585  676    OopMapSet*        oop_map_set()               { return _oop_map_set; }
 586  677    DebugInformationRecorder* debug_info()        { return env()->debug_info(); }
 587  678    Dependencies*     dependencies()              { return env()->dependencies(); }
 588  679    static int        CompiledZap_count()         { return _CompiledZap_count; }
 589  680    BufferBlob*       scratch_buffer_blob()       { return _scratch_buffer_blob; }
 590      -  void         init_scratch_buffer_blob();
      681 +  void         init_scratch_buffer_blob(int const_size);
      682 +  void        clear_scratch_buffer_blob();
 591  683    void          set_scratch_buffer_blob(BufferBlob* b) { _scratch_buffer_blob = b; }
 592  684    relocInfo*        scratch_locs_memory()       { return _scratch_locs_memory; }
 593  685    void          set_scratch_locs_memory(relocInfo* b)  { _scratch_locs_memory = b; }
 594  686  
 595  687    // emit to scratch blob, report resulting size
 596  688    uint              scratch_emit_size(const Node* n);
      689 +  void       set_in_scratch_emit_size(bool x)   {        _in_scratch_emit_size = x; }
      690 +  bool           in_scratch_emit_size() const   { return _in_scratch_emit_size;     }
 597  691  
 598  692    enum ScratchBufferBlob {
 599  693      MAX_inst_size       = 1024,
 600  694      MAX_locs_size       = 128, // number of relocInfo elements
 601  695      MAX_const_size      = 128,
 602  696      MAX_stubs_size      = 128
 603  697    };
 604  698  
 605  699    // Major entry point.  Given a Scope, compile the associated method.
 606  700    // For normal compilations, entry_bci is InvocationEntryBci.  For on stack
↓ open down ↓ 60 lines elided ↑ open up ↑
 667  761    static void set_sv_for_object_node(GrowableArray<ScopeValue*> *objs,
 668  762                                       ObjectValue* sv );
 669  763  
 670  764    // Process an OopMap Element while emitting nodes
 671  765    void Process_OopMap_Node(MachNode *mach, int code_offset);
 672  766  
 673  767    // Write out basic block data to code buffer
 674  768    void Fill_buffer();
 675  769  
 676  770    // Determine which variable sized branches can be shortened
 677      -  void Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size, int& const_size);
      771 +  void Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size);
 678  772  
 679  773    // Compute the size of first NumberOfLoopInstrToAlign instructions
 680  774    // at the head of a loop.
 681  775    void compute_loop_first_inst_sizes();
 682  776  
 683  777    // Compute the information for the exception tables
 684  778    void FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels);
 685  779  
 686  780    // Stack slots that may be unused by the calling convention but must
 687  781    // otherwise be preserved.  On Intel this includes the return address.
↓ open down ↓ 92 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX