1 /*
   2  * Copyright (c) 2018, 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 #ifndef SHARE_VM_OOPS_RECORDPARAMINFO_HPP
  26 #define SHARE_VM_OOPS_RECORDPARAMINFO_HPP
  27 
  28 #include "oops/constantPool.hpp"
  29 #include "oops/typeArrayOop.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 
  32 // This class represents the parameter information contained in the recordParams
  33 // array of an InstanceKlass.  Currently it's laid on top an array of
  34 // Java shorts but in the future it could simply be used as a real
  35 // array type.  RecordParamInfo generally shouldn't be used directly.
  36 // Record parameters should be queried through InstanceKlass.
  37 
  38 class RecordParamInfo {
  39   friend class ClassFileParser;
  40   friend class RecordParameterStreamBase;
  41   friend class JavaRecordParameterStream;
  42   enum ParamOffset {
  43     accessor_index_offset    = 0,
  44     param_slots              = 1
  45   };
  46 
  47 private:
  48   u2 _shorts[param_slots];
  49 
  50   void set_accessor_index(u2 val)                          { _shorts[accessor_index_offset] = val;    }
  51 
  52 public:
  53   static RecordParamInfo* from_record_params_array(Array<u2>* record_params, int index) {
  54     return ((RecordParamInfo*)record_params->adr_at(index * param_slots));
  55   }
  56   static RecordParamInfo* from_record_params_array(u2* record_params, int index) {
  57     return ((RecordParamInfo*)(record_params + index * param_slots));
  58   }
  59 
  60   void initialize(u2 accessor_index) {
  61     _shorts[accessor_index_offset] = accessor_index;
  62   }
  63 
  64   u2 accessor_index() const                                { return _shorts[accessor_index_offset];   }
  65 
  66   Symbol* name(const constantPoolHandle& cp) const {
  67     int accessor_index = _shorts[accessor_index_offset];
  68     int method_ref_info = cp->int_at(accessor_index);
  69     int name_and_type_index = extract_high_short_from_int(method_ref_info);
  70     int name_and_type_info = cp->int_at(name_and_type_index);
  71     int name_index = extract_low_short_from_int(name_and_type_info);
  72     return cp->symbol_at(name_index);
  73   }
  74 };
  75 
  76 #endif // SHARE_VM_OOPS_RECORDPARAMINFO_HPP