1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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 }