< prev index next >

src/hotspot/share/ci/ciArrayKlass.cpp

Print this page

  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 "precompiled.hpp"
 26 #include "ci/ciArrayKlass.hpp"


 27 #include "ci/ciObjArrayKlass.hpp"
 28 #include "ci/ciTypeArrayKlass.hpp"
 29 #include "ci/ciUtilities.inline.hpp"

 30 #include "memory/universe.hpp"
 31 
 32 // ciArrayKlass
 33 //
 34 // This class represents a Klass* in the HotSpot virtual machine
 35 // whose Klass part in an ArrayKlass.
 36 
 37 // ------------------------------------------------------------------
 38 // ciArrayKlass::ciArrayKlass
 39 //
 40 // Loaded array klass.
 41 ciArrayKlass::ciArrayKlass(Klass* k) : ciKlass(k) {
 42   assert(get_Klass()->is_array_klass(), "wrong type");
 43   _dimension = get_ArrayKlass()->dimension();
 44 }
 45 
 46 // ------------------------------------------------------------------
 47 // ciArrayKlass::ciArrayKlass
 48 //
 49 // Unloaded array klass.
 50 ciArrayKlass::ciArrayKlass(ciSymbol* name, int dimension, BasicType bt)
 51   : ciKlass(name, bt) {
 52   _dimension = dimension;
 53 }
 54 
 55 // ------------------------------------------------------------------
 56 // ciArrayKlass::element_type
 57 //
 58 // What type is obtained when this array is indexed once?
 59 ciType* ciArrayKlass::element_type() {
 60   if (is_type_array_klass()) {
 61     return ciType::make(as_type_array_klass()->element_type());
 62   } else {
 63     return as_obj_array_klass()->element_klass()->as_klass();
 64   }
 65 }
 66 
 67 
 68 // ------------------------------------------------------------------
 69 // ciArrayKlass::base_element_type
 70 //
 71 // What type is obtained when this array is indexed as many times as possible?
 72 ciType* ciArrayKlass::base_element_type() {
 73   if (is_type_array_klass()) {
 74     return ciType::make(as_type_array_klass()->element_type());
 75   } else {
 76     ciKlass* ek = as_obj_array_klass()->base_element_klass();
 77     if (ek->is_type_array_klass()) {
 78       return ciType::make(ek->as_type_array_klass()->element_type());
 79     }
 80     return ek;


 81   }
 82 }
 83 
 84 
 85 // ------------------------------------------------------------------
 86 // ciArrayKlass::is_leaf_type
 87 bool ciArrayKlass::is_leaf_type() {
 88   if (is_type_array_klass()) {
 89     return true;
 90   } else {
 91     return as_obj_array_klass()->base_element_klass()->is_leaf_type();
 92   }
 93 }
 94 
 95 
 96 // ------------------------------------------------------------------
 97 // ciArrayKlass::make
 98 //
 99 // Make an array klass of the specified element type.
100 ciArrayKlass* ciArrayKlass::make(ciType* element_type) {
101   if (element_type->is_primitive_type()) {
102     return ciTypeArrayKlass::make(element_type->basic_type());
103   } else {
104     return ciObjArrayKlass::make(element_type->as_klass());














105   }
106 }
107 












  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 "precompiled.hpp"
 26 #include "ci/ciArrayKlass.hpp"
 27 #include "ci/ciFlatArrayKlass.hpp"
 28 #include "ci/ciInlineKlass.hpp"
 29 #include "ci/ciObjArrayKlass.hpp"
 30 #include "ci/ciTypeArrayKlass.hpp"
 31 #include "ci/ciUtilities.inline.hpp"
 32 #include "oops/inlineKlass.inline.hpp"
 33 #include "memory/universe.hpp"
 34 
 35 // ciArrayKlass
 36 //
 37 // This class represents a Klass* in the HotSpot virtual machine
 38 // whose Klass part in an ArrayKlass.
 39 
 40 // ------------------------------------------------------------------
 41 // ciArrayKlass::ciArrayKlass
 42 //
 43 // Loaded array klass.
 44 ciArrayKlass::ciArrayKlass(Klass* k) : ciKlass(k) {
 45   assert(get_Klass()->is_array_klass(), "wrong type");
 46   _dimension = get_ArrayKlass()->dimension();
 47 }
 48 
 49 // ------------------------------------------------------------------
 50 // ciArrayKlass::ciArrayKlass
 51 //
 52 // Unloaded array klass.
 53 ciArrayKlass::ciArrayKlass(ciSymbol* name, int dimension, BasicType bt)
 54   : ciKlass(name, bt) {
 55   _dimension = dimension;
 56 }
 57 
 58 // ------------------------------------------------------------------
 59 // ciArrayKlass::element_type
 60 //
 61 // What type is obtained when this array is indexed once?
 62 ciType* ciArrayKlass::element_type() {
 63   if (is_type_array_klass()) {
 64     return ciType::make(as_type_array_klass()->element_type());
 65   } else {
 66     return element_klass()->as_klass();
 67   }
 68 }
 69 
 70 
 71 // ------------------------------------------------------------------
 72 // ciArrayKlass::base_element_type
 73 //
 74 // What type is obtained when this array is indexed as many times as possible?
 75 ciType* ciArrayKlass::base_element_type() {
 76   if (is_type_array_klass()) {
 77     return ciType::make(as_type_array_klass()->element_type());
 78   } else if (is_obj_array_klass()) {
 79     ciKlass* ek = as_obj_array_klass()->base_element_klass();
 80     if (ek->is_type_array_klass()) {
 81       return ciType::make(ek->as_type_array_klass()->element_type());
 82     }
 83     return ek;
 84   } else {
 85     return as_flat_array_klass()->base_element_klass();
 86   }
 87 }
 88 
 89 
 90 // ------------------------------------------------------------------
 91 // ciArrayKlass::is_leaf_type
 92 bool ciArrayKlass::is_leaf_type() {
 93   if (is_type_array_klass()) {
 94     return true;
 95   } else {
 96     return as_obj_array_klass()->base_element_klass()->is_leaf_type();
 97   }
 98 }
 99 
100 
101 // ------------------------------------------------------------------
102 // ciArrayKlass::make
103 //
104 // Make an array klass of the specified element type.
105 ciArrayKlass* ciArrayKlass::make(ciType* element_type, bool null_free) {
106   if (element_type->is_primitive_type()) {
107     return ciTypeArrayKlass::make(element_type->basic_type());
108   } else {
109     ciKlass* klass = element_type->as_klass();
110     if (null_free && klass->is_loaded()) {
111       GUARDED_VM_ENTRY(
112         EXCEPTION_CONTEXT;
113         Klass* ak = InlineKlass::cast(klass->get_Klass())->value_array_klass(THREAD);
114         if (HAS_PENDING_EXCEPTION) {
115           CLEAR_PENDING_EXCEPTION;
116         } else if (ak->is_flatArray_klass()) {
117           return CURRENT_THREAD_ENV->get_flat_array_klass(ak);
118         } else if (ak->is_objArray_klass()) {
119           return CURRENT_THREAD_ENV->get_obj_array_klass(ak);
120         }
121       )
122     }
123     return ciObjArrayKlass::make(klass);
124   }
125 }
126 
127 int ciArrayKlass::array_header_in_bytes() {
128   return get_ArrayKlass()->array_header_in_bytes();
129 }
130 
131 ciInstance* ciArrayKlass::component_mirror_instance() const {
132   GUARDED_VM_ENTRY(
133     oop component_mirror = ArrayKlass::cast(get_Klass())->component_mirror();
134     return CURRENT_ENV->get_instance(component_mirror);
135   )
136 }
137 
< prev index next >