< prev index next >

src/share/vm/ci/ciValueKlass.cpp

Print this page




   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  */
  24 
  25 #include "ci/ciField.hpp"
  26 #include "ci/ciValueKlass.hpp"
  27 #include "oops/valueKlass.hpp"
  28 
  29 int ciValueKlass::get_field_index_by_offset(int offset) {
  30   // TODO do we need handles here?
  31   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  32   methodHandle factory_h(vklass_h->factory_method());
  33   // Search field with field_offset and return factory parameter index
  34   for (int index = 0; index < field_count(); ++index) {
  35     if (get_field_offset_by_index(index) == offset) {
  36       return index;



























  37     }
  38   }
  39   ShouldNotReachHere();
  40   return -1;

  41 }
  42 

  43 int ciValueKlass::get_field_offset_by_index(int index) const {
  44   // Compute the field index from the factory parameter index
  45   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  46   methodHandle factory_h(vklass_h->factory_method());
  47   int field_index = factory_h->constMethod()->valuefactory_parameter_mapping_start()[index].data.field_index;
  48   // Get the field offset
  49   return vklass_h->field_offset(field_index);
  50 }
  51 
  52 BasicType ciValueKlass::get_field_type_by_index(int index) const {
  53   // Compute the field index from the factory parameter index







  54   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  55   methodHandle factory_h(vklass_h->factory_method());
  56   int field_index = factory_h->constMethod()->valuefactory_parameter_mapping_start()[index].data.field_index;
  57   // Get the basic type of the field
  58   Symbol* signature = vklass_h->field_signature(field_index);
  59   return vmSymbols::signature_type(signature);
  60 }


   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  */
  24 
  25 #include "ci/ciField.hpp"
  26 #include "ci/ciValueKlass.hpp"
  27 #include "oops/valueKlass.hpp"
  28 
  29 // Number of value type factory parameters
  30 int ciValueKlass::param_count() const {
  31   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  32   methodHandle factory_h(vklass_h->factory_method());
  33   return factory_h->constMethod()->valuefactory_parameter_mapping_length();
  34 }
  35 
  36 // Size of value type factory parameters in words
  37 int ciValueKlass::param_size() {
  38   int size = 0;
  39   for (int i = 0; i < param_count(); ++i) {
  40     size += get_field_type_by_index(i)->size();
  41   }
  42   return size;
  43 }
  44 
  45 // Returns the value factory parameter index of the field with the given offset.
  46 // If the field at 'offset' belongs to a flattened value type field, return the
  47 // index of the ValueType parameter corresponding to this flattened value type.
  48 int ciValueKlass::get_field_index_by_offset(int offset) {
  49   assert(contains_field_offset(offset), "invalid field offset");
  50   int best_offset = 0;
  51   int best_index = -1;
  52   // Search the field with the given offset
  53   for (int i = 0; i < param_count(); ++i) {
  54     int field_offset = get_field_offset_by_index(i);
  55     if (field_offset == offset) {
  56       // Exact match
  57       return i;
  58     } else if (field_offset < offset && field_offset > best_offset) {
  59       // No exact match. Save the index of the field with the closest offset that
  60       // is smaller than the given field offset. This index corresponds to the
  61       // flattened value type field that holds the field we are looking for.
  62       best_offset = field_offset;
  63       best_index = i;
  64     }
  65   }
  66   assert(best_index >= 0, "field not found");
  67   assert(best_offset == offset || get_field_type_by_index(best_index)->is_valuetype(), "offset should match for non-VTs");
  68   return best_index;
  69 }
  70 
  71 // Returns the field offset of the value factory parameter with the given index
  72 int ciValueKlass::get_field_offset_by_index(int index) const {
  73   // Compute the field index from the factory parameter index
  74   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  75   methodHandle factory_h(vklass_h->factory_method());
  76   int field_index = factory_h->constMethod()->valuefactory_parameter_mapping_start()[index].data.field_index;
  77   // Get the field offset
  78   return vklass_h->field_offset(field_index);
  79 }
  80 
  81 // Returns the field type of the value factory parameter with the given index
  82 ciType* ciValueKlass::get_field_type_by_index(int index) {
  83   int offset = get_field_offset_by_index(index);
  84   VM_ENTRY_MARK;
  85   return get_field_type_by_offset(offset);
  86 }
  87 
  88 // Offset of the first field in the value type
  89 int ciValueKlass::get_first_field_offset() const {
  90   valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
  91   return vklass_h()->first_field_offset();




  92 }
< prev index next >