src/share/vm/ci/ciValueKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File valhalla-experimental Sdiff src/share/vm/ci

src/share/vm/ci/ciValueKlass.cpp

Print this page




  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 }


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


  87 }
  88 
  89 // Returns the field type of the field with the given index
  90 ciType* ciValueKlass::get_field_type_by_index(int index) {
  91   VM_ENTRY_MARK
  92   int offset = get_field_offset_by_index(index);

  93   return get_field_type_by_offset(offset);
  94 }
  95 
  96 // Offset of the first field in the value type
  97 int ciValueKlass::get_first_field_offset() const {
  98   GUARDED_VM_ENTRY(
  99       valueKlassHandle vklass_h(ValueKlass::cast(get_Klass()));
 100       return vklass_h()->first_field_offset();
 101   )
 102 }
src/share/vm/ci/ciValueKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File