1 /* 2 * Copyright (c) 1999, 2015, 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 "precompiled.hpp" 26 #include "ci/ciArrayKlass.hpp" 27 #include "ci/ciObjArrayKlass.hpp" 28 #include "ci/ciTypeArrayKlass.hpp" 29 #include "ci/ciUtilities.hpp" 30 #include "ci/ciValueArrayKlass.hpp" 31 #include "ci/ciValueKlass.hpp" 32 33 // ciArrayKlass 34 // 35 // This class represents a Klass* in the HotSpot virtual machine 36 // whose Klass part in an ArrayKlass. 37 38 // ------------------------------------------------------------------ 39 // ciArrayKlass::ciArrayKlass 40 // 41 // Loaded array klass. 42 ciArrayKlass::ciArrayKlass(KlassHandle h_k) : ciKlass(h_k) { 43 assert(get_Klass()->is_array_klass(), "wrong type"); 44 _dimension = get_ArrayKlass()->dimension(); 45 } 46 47 // ------------------------------------------------------------------ 48 // ciArrayKlass::ciArrayKlass 49 // 50 // Unloaded array klass. 51 ciArrayKlass::ciArrayKlass(ciSymbol* name, int dimension, BasicType bt) 52 : ciKlass(name, bt) { 53 _dimension = dimension; 54 } 55 56 // ------------------------------------------------------------------ 57 // ciArrayKlass::element_type 58 // 59 // What type is obtained when this array is indexed once? 60 ciType* ciArrayKlass::element_type() { 61 if (is_type_array_klass()) { 62 return ciType::make(as_type_array_klass()->element_type()); 63 } else { 64 return element_klass()->as_klass(); 65 } 66 } 67 68 69 // ------------------------------------------------------------------ 70 // ciArrayKlass::base_element_type 71 // 72 // What type is obtained when this array is indexed as many times as possible? 73 ciType* ciArrayKlass::base_element_type() { 74 if (is_type_array_klass()) { 75 return ciType::make(as_type_array_klass()->element_type()); 76 } else if (is_obj_array_klass()) { 77 ciKlass* ek = as_obj_array_klass()->base_element_klass(); 78 if (ek->is_type_array_klass()) { 79 return ciType::make(ek->as_type_array_klass()->element_type()); 80 } 81 return ek; 82 } else { 83 return as_value_array_klass()->base_element_klass(); 84 } 85 } 86 87 88 // ------------------------------------------------------------------ 89 // ciArrayKlass::is_leaf_type 90 bool ciArrayKlass::is_leaf_type() { 91 if (is_type_array_klass()) { 92 return true; 93 } else { 94 return as_obj_array_klass()->base_element_klass()->is_leaf_type(); 95 } 96 } 97 98 99 // ------------------------------------------------------------------ 100 // ciArrayKlass::base_element_type 101 // 102 // What type is obtained when this array is indexed as many times as possible? 103 ciArrayKlass* ciArrayKlass::make(ciType* element_type) { 104 if (element_type->is_primitive_type()) { 105 return ciTypeArrayKlass::make(element_type->basic_type()); 106 } else if (element_type->is_valuetype() && element_type->as_value_klass()->flatten_array()) { 107 return ciValueArrayKlass::make(element_type->as_klass()); 108 } else { 109 return ciObjArrayKlass::make(element_type->as_klass()); 110 } 111 }