src/share/vm/opto/compile.hpp

changeset 2350
2f644f85485d
parent 2314
f95d63e2154a
child 2658
c7f3d0b4570f
     1.1 --- a/src/share/vm/opto/compile.hpp	Thu Dec 02 17:21:12 2010 -0800
     1.2 +++ b/src/share/vm/opto/compile.hpp	Fri Dec 03 01:34:31 2010 -0800
     1.3 @@ -48,7 +48,10 @@
     1.4  class InlineTree;
     1.5  class Int_Array;
     1.6  class Matcher;
     1.7 +class MachConstantNode;
     1.8 +class MachConstantBaseNode;
     1.9  class MachNode;
    1.10 +class MachOper;
    1.11  class MachSafePointNode;
    1.12  class Node;
    1.13  class Node_Array;
    1.14 @@ -139,6 +142,81 @@
    1.15      trapHistLength = methodDataOopDesc::_trap_hist_limit
    1.16    };
    1.17  
    1.18 +  // Constant entry of the constant table.
    1.19 +  class Constant {
    1.20 +  private:
    1.21 +    BasicType _type;
    1.22 +    jvalue    _value;
    1.23 +    int       _offset;         // offset of this constant (in bytes) relative to the constant table base.
    1.24 +    bool      _can_be_reused;  // true (default) if the value can be shared with other users.
    1.25 +
    1.26 +  public:
    1.27 +    Constant() : _type(T_ILLEGAL), _offset(-1), _can_be_reused(true) { _value.l = 0; }
    1.28 +    Constant(BasicType type, jvalue value, bool can_be_reused = true) :
    1.29 +      _type(type),
    1.30 +      _value(value),
    1.31 +      _offset(-1),
    1.32 +      _can_be_reused(can_be_reused)
    1.33 +    {}
    1.34 +
    1.35 +    bool operator==(const Constant& other);
    1.36 +
    1.37 +    BasicType type()      const    { return _type; }
    1.38 +
    1.39 +    jlong   get_jlong()   const    { return _value.j; }
    1.40 +    jfloat  get_jfloat()  const    { return _value.f; }
    1.41 +    jdouble get_jdouble() const    { return _value.d; }
    1.42 +    jobject get_jobject() const    { return _value.l; }
    1.43 +
    1.44 +    int         offset()  const    { return _offset; }
    1.45 +    void    set_offset(int offset) {        _offset = offset; }
    1.46 +
    1.47 +    bool    can_be_reused() const  { return _can_be_reused; }
    1.48 +  };
    1.49 +
    1.50 +  // Constant table.
    1.51 +  class ConstantTable {
    1.52 +  private:
    1.53 +    GrowableArray<Constant> _constants;          // Constants of this table.
    1.54 +    int                     _size;               // Size in bytes the emitted constant table takes (including padding).
    1.55 +    int                     _table_base_offset;  // Offset of the table base that gets added to the constant offsets.
    1.56 +
    1.57 +  public:
    1.58 +    ConstantTable() :
    1.59 +      _size(-1),
    1.60 +      _table_base_offset(-1)  // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit).
    1.61 +    {}
    1.62 +
    1.63 +    int size() const { assert(_size != -1, "size not yet calculated"); return _size; }
    1.64 +
    1.65 +    void set_table_base_offset(int x)  { assert(_table_base_offset == -1, "set only once");                        _table_base_offset = x; }
    1.66 +    int      table_base_offset() const { assert(_table_base_offset != -1, "table base offset not yet set"); return _table_base_offset; }
    1.67 +
    1.68 +    void emit(CodeBuffer& cb);
    1.69 +
    1.70 +    // Returns the offset of the last entry (the top) of the constant table.
    1.71 +    int  top_offset() const { assert(_constants.top().offset() != -1, "constant not yet bound"); return _constants.top().offset(); }
    1.72 +
    1.73 +    void calculate_offsets_and_size();
    1.74 +    int  find_offset(Constant& con) const;
    1.75 +
    1.76 +    void     add(Constant& con);
    1.77 +    Constant add(BasicType type, jvalue value);
    1.78 +    Constant add(MachOper* oper);
    1.79 +    Constant add(jfloat f) {
    1.80 +      jvalue value; value.f = f;
    1.81 +      return add(T_FLOAT, value);
    1.82 +    }
    1.83 +    Constant add(jdouble d) {
    1.84 +      jvalue value; value.d = d;
    1.85 +      return add(T_DOUBLE, value);
    1.86 +    }
    1.87 +
    1.88 +    // Jump table
    1.89 +    Constant allocate_jump_table(MachConstantNode* n);
    1.90 +    void         fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const;
    1.91 +  };
    1.92 +
    1.93   private:
    1.94    // Fixed parameters to this compilation.
    1.95    const int             _compile_id;
    1.96 @@ -212,6 +290,11 @@
    1.97    Node*                 _recent_alloc_obj;
    1.98    Node*                 _recent_alloc_ctl;
    1.99  
   1.100 +  // Constant table
   1.101 +  ConstantTable         _constant_table;        // The constant table for this compile.
   1.102 +  MachConstantBaseNode* _mach_constant_base_node;  // Constant table base node singleton.
   1.103 +
   1.104 +
   1.105    // Blocked array of debugging and profiling information,
   1.106    // tracked per node.
   1.107    enum { _log2_node_notes_block_size = 8,
   1.108 @@ -272,6 +355,8 @@
   1.109    static int            _CompiledZap_count;     // counter compared against CompileZap[First/Last]
   1.110    BufferBlob*           _scratch_buffer_blob;   // For temporary code buffers.
   1.111    relocInfo*            _scratch_locs_memory;   // For temporary code buffers.
   1.112 +  int                   _scratch_const_size;    // For temporary code buffers.
   1.113 +  bool                  _in_scratch_emit_size;  // true when in scratch_emit_size.
   1.114  
   1.115   public:
   1.116    // Accessors
   1.117 @@ -454,6 +539,12 @@
   1.118                                                    _recent_alloc_obj = obj;
   1.119                                                  }
   1.120  
   1.121 +  // Constant table
   1.122 +  ConstantTable&   constant_table() { return _constant_table; }
   1.123 +
   1.124 +  MachConstantBaseNode*     mach_constant_base_node();
   1.125 +  bool                  has_mach_constant_base_node() const { return _mach_constant_base_node != NULL; }
   1.126 +
   1.127    // Handy undefined Node
   1.128    Node*             top() const                 { return _top; }
   1.129  
   1.130 @@ -605,13 +696,16 @@
   1.131    Dependencies*     dependencies()              { return env()->dependencies(); }
   1.132    static int        CompiledZap_count()         { return _CompiledZap_count; }
   1.133    BufferBlob*       scratch_buffer_blob()       { return _scratch_buffer_blob; }
   1.134 -  void         init_scratch_buffer_blob();
   1.135 +  void         init_scratch_buffer_blob(int const_size);
   1.136 +  void        clear_scratch_buffer_blob();
   1.137    void          set_scratch_buffer_blob(BufferBlob* b) { _scratch_buffer_blob = b; }
   1.138    relocInfo*        scratch_locs_memory()       { return _scratch_locs_memory; }
   1.139    void          set_scratch_locs_memory(relocInfo* b)  { _scratch_locs_memory = b; }
   1.140  
   1.141    // emit to scratch blob, report resulting size
   1.142    uint              scratch_emit_size(const Node* n);
   1.143 +  void       set_in_scratch_emit_size(bool x)   {        _in_scratch_emit_size = x; }
   1.144 +  bool           in_scratch_emit_size() const   { return _in_scratch_emit_size;     }
   1.145  
   1.146    enum ScratchBufferBlob {
   1.147      MAX_inst_size       = 1024,
   1.148 @@ -692,7 +786,7 @@
   1.149    void Fill_buffer();
   1.150  
   1.151    // Determine which variable sized branches can be shortened
   1.152 -  void Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size, int& const_size);
   1.153 +  void Shorten_branches(Label *labels, int& code_size, int& reloc_size, int& stub_size);
   1.154  
   1.155    // Compute the size of first NumberOfLoopInstrToAlign instructions
   1.156    // at the head of a loop.

mercurial