hotspot/src/share/vm/opto/compile.hpp
changeset 11190 d561d41f241a
parent 10547 ea4a2ec31ae2
child 12107 0d67c9f2abf2
equal deleted inserted replaced
11189:c1ad8528ae68 11190:d561d41f241a
   148   class Constant {
   148   class Constant {
   149   private:
   149   private:
   150     BasicType _type;
   150     BasicType _type;
   151     jvalue    _value;
   151     jvalue    _value;
   152     int       _offset;         // offset of this constant (in bytes) relative to the constant table base.
   152     int       _offset;         // offset of this constant (in bytes) relative to the constant table base.
       
   153     float     _freq;
   153     bool      _can_be_reused;  // true (default) if the value can be shared with other users.
   154     bool      _can_be_reused;  // true (default) if the value can be shared with other users.
   154 
   155 
   155   public:
   156   public:
   156     Constant() : _type(T_ILLEGAL), _offset(-1), _can_be_reused(true) { _value.l = 0; }
   157     Constant() : _type(T_ILLEGAL), _offset(-1), _freq(0.0f), _can_be_reused(true) { _value.l = 0; }
   157     Constant(BasicType type, jvalue value, bool can_be_reused = true) :
   158     Constant(BasicType type, jvalue value, float freq = 0.0f, bool can_be_reused = true) :
   158       _type(type),
   159       _type(type),
   159       _value(value),
   160       _value(value),
   160       _offset(-1),
   161       _offset(-1),
       
   162       _freq(freq),
   161       _can_be_reused(can_be_reused)
   163       _can_be_reused(can_be_reused)
   162     {}
   164     {}
   163 
   165 
   164     bool operator==(const Constant& other);
   166     bool operator==(const Constant& other);
   165 
   167 
   170     jdouble get_jdouble() const    { return _value.d; }
   172     jdouble get_jdouble() const    { return _value.d; }
   171     jobject get_jobject() const    { return _value.l; }
   173     jobject get_jobject() const    { return _value.l; }
   172 
   174 
   173     int         offset()  const    { return _offset; }
   175     int         offset()  const    { return _offset; }
   174     void    set_offset(int offset) {        _offset = offset; }
   176     void    set_offset(int offset) {        _offset = offset; }
       
   177 
       
   178     float       freq()    const    { return _freq;         }
       
   179     void    inc_freq(float freq)   {        _freq += freq; }
   175 
   180 
   176     bool    can_be_reused() const  { return _can_be_reused; }
   181     bool    can_be_reused() const  { return _can_be_reused; }
   177   };
   182   };
   178 
   183 
   179   // Constant table.
   184   // Constant table.
   180   class ConstantTable {
   185   class ConstantTable {
   181   private:
   186   private:
   182     GrowableArray<Constant> _constants;          // Constants of this table.
   187     GrowableArray<Constant> _constants;          // Constants of this table.
   183     int                     _size;               // Size in bytes the emitted constant table takes (including padding).
   188     int                     _size;               // Size in bytes the emitted constant table takes (including padding).
   184     int                     _table_base_offset;  // Offset of the table base that gets added to the constant offsets.
   189     int                     _table_base_offset;  // Offset of the table base that gets added to the constant offsets.
       
   190     int                     _nof_jump_tables;    // Number of jump-tables in this constant table.
       
   191 
       
   192     static int qsort_comparator(Constant* a, Constant* b);
       
   193 
       
   194     // We use negative frequencies to keep the order of the
       
   195     // jump-tables in which they were added.  Otherwise we get into
       
   196     // trouble with relocation.
       
   197     float next_jump_table_freq() { return -1.0f * (++_nof_jump_tables); }
   185 
   198 
   186   public:
   199   public:
   187     ConstantTable() :
   200     ConstantTable() :
   188       _size(-1),
   201       _size(-1),
   189       _table_base_offset(-1)  // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit).
   202       _table_base_offset(-1),  // We can use -1 here since the constant table is always bigger than 2 bytes (-(size / 2), see MachConstantBaseNode::emit).
       
   203       _nof_jump_tables(0)
   190     {}
   204     {}
   191 
   205 
   192     int size() const { assert(_size != -1, "size not yet calculated"); return _size; }
   206     int size() const { assert(_size != -1, "not calculated yet"); return _size; }
   193 
   207 
   194     void set_table_base_offset(int x)  { assert(_table_base_offset == -1, "set only once");                        _table_base_offset = x; }
   208     int calculate_table_base_offset() const;  // AD specific
   195     int      table_base_offset() const { assert(_table_base_offset != -1, "table base offset not yet set"); return _table_base_offset; }
   209     void set_table_base_offset(int x)  { assert(_table_base_offset == -1 || x == _table_base_offset, "can't change"); _table_base_offset = x; }
       
   210     int      table_base_offset() const { assert(_table_base_offset != -1, "not set yet");                      return _table_base_offset; }
   196 
   211 
   197     void emit(CodeBuffer& cb);
   212     void emit(CodeBuffer& cb);
   198 
   213 
   199     // Returns the offset of the last entry (the top) of the constant table.
   214     // Returns the offset of the last entry (the top) of the constant table.
   200     int  top_offset() const { assert(_constants.top().offset() != -1, "constant not yet bound"); return _constants.top().offset(); }
   215     int  top_offset() const { assert(_constants.top().offset() != -1, "not bound yet"); return _constants.top().offset(); }
   201 
   216 
   202     void calculate_offsets_and_size();
   217     void calculate_offsets_and_size();
   203     int  find_offset(Constant& con) const;
   218     int  find_offset(Constant& con) const;
   204 
   219 
   205     void     add(Constant& con);
   220     void     add(Constant& con);
   206     Constant add(BasicType type, jvalue value);
   221     Constant add(MachConstantNode* n, BasicType type, jvalue value);
   207     Constant add(MachOper* oper);
   222     Constant add(MachConstantNode* n, MachOper* oper);
   208     Constant add(jfloat f) {
   223     Constant add(MachConstantNode* n, jfloat f) {
   209       jvalue value; value.f = f;
   224       jvalue value; value.f = f;
   210       return add(T_FLOAT, value);
   225       return add(n, T_FLOAT, value);
   211     }
   226     }
   212     Constant add(jdouble d) {
   227     Constant add(MachConstantNode* n, jdouble d) {
   213       jvalue value; value.d = d;
   228       jvalue value; value.d = d;
   214       return add(T_DOUBLE, value);
   229       return add(n, T_DOUBLE, value);
   215     }
   230     }
   216 
   231 
   217     // Jump table
   232     // Jump-table
   218     Constant allocate_jump_table(MachConstantNode* n);
   233     Constant  add_jump_table(MachConstantNode* n);
   219     void         fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const;
   234     void     fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const;
   220   };
   235   };
   221 
   236 
   222  private:
   237  private:
   223   // Fixed parameters to this compilation.
   238   // Fixed parameters to this compilation.
   224   const int             _compile_id;
   239   const int             _compile_id;