< prev index next >

src/hotspot/share/ci/ciObjArrayKlass.cpp

Print this page

 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/ciInstanceKlass.hpp"
 27 #include "ci/ciObjArrayKlass.hpp"
 28 #include "ci/ciSymbol.hpp"
 29 #include "ci/ciUtilities.inline.hpp"

 30 #include "oops/objArrayKlass.hpp"
 31 #include "runtime/signature.hpp"
 32 
 33 // ciObjArrayKlass
 34 //
 35 // This class represents a Klass* in the HotSpot virtual machine
 36 // whose Klass part is an ObjArrayKlass.
 37 
 38 // ------------------------------------------------------------------
 39 // ciObjArrayKlass::ciObjArrayKlass
 40 //
 41 // Constructor for loaded object array klasses.
 42 ciObjArrayKlass::ciObjArrayKlass(Klass* k) : ciArrayKlass(k) {
 43   assert(get_Klass()->is_objArray_klass(), "wrong type");
 44   Klass* element_Klass = get_ObjArrayKlass()->bottom_klass();
 45   _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
 46   assert(_base_element_klass->is_instance_klass() ||
 47          _base_element_klass->is_type_array_klass(), "bad base klass");
 48   if (dimension() == 1) {
 49     _element_klass = _base_element_klass;
 50   } else {
 51     _element_klass = nullptr;
 52   }
 53   if (!ciObjectFactory::is_initialized()) {
 54     assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
 55   }
 56 }
 57 
 58 // ------------------------------------------------------------------
 59 // ciObjArrayKlass::ciObjArrayKlass
 60 //
 61 // Constructor for unloaded object array klasses.
 62 ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
 63                                  ciKlass* base_element_klass,
 64                                  int dimension)
 65   : ciArrayKlass(array_name,
 66                  dimension, T_OBJECT) {
 67     _base_element_klass = base_element_klass;
 68     assert(_base_element_klass->is_instance_klass() ||
 69            _base_element_klass->is_type_array_klass(), "bad base klass");
 70     if (dimension == 1) {
 71       _element_klass = base_element_klass;
 72     } else {
 73       _element_klass = nullptr;
 74     }

 75 }
 76 
 77 // ------------------------------------------------------------------
 78 // ciObjArrayKlass::element_klass
 79 //
 80 // What is the one-level element type of this array?
 81 ciKlass* ciObjArrayKlass::element_klass() {
 82   if (_element_klass == nullptr) {
 83     assert(dimension() > 1, "_element_klass should not be null");
 84     // Produce the element klass.
 85     if (is_loaded()) {
 86       VM_ENTRY_MARK;
 87       Klass* element_Klass = get_ObjArrayKlass()->element_klass();
 88       _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
 89     } else {
 90       VM_ENTRY_MARK;
 91       // We are an unloaded array klass.  Attempt to fetch our
 92       // element klass by name.
 93       _element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl(
 94                           this,

 99     }
100   }
101   return _element_klass;
102 }
103 
104 // ------------------------------------------------------------------
105 // ciObjArrayKlass::construct_array_name
106 //
107 // Build an array name from an element name and a dimension.
108 ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
109                                                 int dimension) {
110   EXCEPTION_CONTEXT;
111   int element_len = element_name->utf8_length();
112   int buflen = dimension + element_len + 3;  // '['+ + 'L'? + (element) + ';'? + '\0'
113   char* name = CURRENT_THREAD_ENV->name_buffer(buflen);
114   int pos = 0;
115   for ( ; pos < dimension; pos++) {
116     name[pos] = JVM_SIGNATURE_ARRAY;
117   }
118   Symbol* base_name_sym = element_name->get_symbol();
119 
120   if (Signature::is_array(base_name_sym) ||
121       Signature::has_envelope(base_name_sym)) {
122     strncpy(&name[pos], (char*)element_name->base(), element_len);
123     name[pos + element_len] = '\0';
124   } else {
125     name[pos++] = JVM_SIGNATURE_CLASS;
126     strncpy(&name[pos], (char*)element_name->base(), element_len);
127     name[pos + element_len] = JVM_SIGNATURE_ENDCLASS;
128     name[pos + element_len + 1] = '\0';
129   }
130   return ciSymbol::make(name);
131 }
132 
133 // ------------------------------------------------------------------
134 // ciObjArrayKlass::make_impl
135 //
136 // Implementation of make.
137 ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {
138 
139   if (element_klass->is_loaded()) {
140     EXCEPTION_CONTEXT;
141     // The element klass is loaded
142     Klass* array = element_klass->get_Klass()->array_klass(THREAD);
143     if (HAS_PENDING_EXCEPTION) {
144       CLEAR_PENDING_EXCEPTION;
145       CURRENT_THREAD_ENV->record_out_of_memory_failure();
146       return ciEnv::unloaded_ciobjarrayklass();
147     }
148     return CURRENT_THREAD_ENV->get_obj_array_klass(array);
149   }
150 
151   // The array klass was unable to be made or the element klass was
152   // not loaded.
153   ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
154   if (array_name == ciEnv::unloaded_cisymbol()) {
155     return ciEnv::unloaded_ciobjarrayklass();
156   }
157   return
158     CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
159                         ->as_obj_array_klass();
160 }
161 
162 // ------------------------------------------------------------------
163 // ciObjArrayKlass::make
164 //
165 // Make an array klass corresponding to the specified primitive type.
166 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
167   GUARDED_VM_ENTRY(return make_impl(element_klass);)
168 }
169 
170 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass, int dims) {
171   ciKlass* klass = element_klass;
172   for (int i = 0; i < dims; i++) {
173     klass = ciObjArrayKlass::make(klass);
174   }
175   return klass->as_obj_array_klass();
176 }
177 
178 ciKlass* ciObjArrayKlass::exact_klass() {



179   ciType* base = base_element_type();
180   if (base->is_instance_klass()) {
181     ciInstanceKlass* ik = base->as_instance_klass();





182     if (ik->exact_klass() != nullptr) {
183       return this;
184     }
185   } else if (base->is_primitive_type()) {
186     return this;
187   }
188   return nullptr;
189 }





 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/ciInstanceKlass.hpp"
 27 #include "ci/ciObjArrayKlass.hpp"
 28 #include "ci/ciSymbol.hpp"
 29 #include "ci/ciUtilities.inline.hpp"
 30 #include "oops/inlineKlass.inline.hpp"
 31 #include "oops/objArrayKlass.hpp"
 32 #include "runtime/signature.hpp"
 33 
 34 // ciObjArrayKlass
 35 //
 36 // This class represents a Klass* in the HotSpot virtual machine
 37 // whose Klass part is an ObjArrayKlass.
 38 
 39 // ------------------------------------------------------------------
 40 // ciObjArrayKlass::ciObjArrayKlass
 41 //
 42 // Constructor for loaded object array klasses.
 43 ciObjArrayKlass::ciObjArrayKlass(Klass* k) : ciArrayKlass(k) {
 44   assert(get_Klass()->is_objArray_klass(), "wrong type");
 45   Klass* element_Klass = get_ObjArrayKlass()->bottom_klass();
 46   _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
 47   assert(_base_element_klass->is_instance_klass() ||
 48          _base_element_klass->is_type_array_klass(), "bad base klass");
 49   if (dimension() == 1) {
 50     _element_klass = _base_element_klass;
 51   } else {
 52     _element_klass = nullptr;
 53   }
 54   if (!ciObjectFactory::is_initialized()) {
 55     assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared");
 56   }
 57 }
 58 
 59 // ------------------------------------------------------------------
 60 // ciObjArrayKlass::ciObjArrayKlass
 61 //
 62 // Constructor for unloaded object array klasses.
 63 ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name,
 64                                  ciKlass* base_element_klass,
 65                                  int dimension)
 66   : ciArrayKlass(array_name,
 67                  dimension, T_OBJECT) {
 68   _base_element_klass = base_element_klass;
 69   assert(_base_element_klass->is_instance_klass() ||
 70          _base_element_klass->is_type_array_klass() ||
 71          _base_element_klass->is_flat_array_klass(), "bad base klass");
 72   if (dimension == 1) {
 73     _element_klass = base_element_klass;
 74   } else {
 75     _element_klass = nullptr;
 76   }
 77 }
 78 
 79 // ------------------------------------------------------------------
 80 // ciObjArrayKlass::element_klass
 81 //
 82 // What is the one-level element type of this array?
 83 ciKlass* ciObjArrayKlass::element_klass() {
 84   if (_element_klass == nullptr) {
 85     assert(dimension() > 1, "_element_klass should not be null");
 86     // Produce the element klass.
 87     if (is_loaded()) {
 88       VM_ENTRY_MARK;
 89       Klass* element_Klass = get_ObjArrayKlass()->element_klass();
 90       _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
 91     } else {
 92       VM_ENTRY_MARK;
 93       // We are an unloaded array klass.  Attempt to fetch our
 94       // element klass by name.
 95       _element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl(
 96                           this,

101     }
102   }
103   return _element_klass;
104 }
105 
106 // ------------------------------------------------------------------
107 // ciObjArrayKlass::construct_array_name
108 //
109 // Build an array name from an element name and a dimension.
110 ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name,
111                                                 int dimension) {
112   EXCEPTION_CONTEXT;
113   int element_len = element_name->utf8_length();
114   int buflen = dimension + element_len + 3;  // '['+ + 'L'? + (element) + ';'? + '\0'
115   char* name = CURRENT_THREAD_ENV->name_buffer(buflen);
116   int pos = 0;
117   for ( ; pos < dimension; pos++) {
118     name[pos] = JVM_SIGNATURE_ARRAY;
119   }
120   Symbol* base_name_sym = element_name->get_symbol();

121   if (Signature::is_array(base_name_sym) ||
122       Signature::has_envelope(base_name_sym)) {
123     strncpy(&name[pos], (char*)element_name->base(), element_len);
124     name[pos + element_len] = '\0';
125   } else {
126     name[pos++] = JVM_SIGNATURE_CLASS;
127     strncpy(&name[pos], (char*)element_name->base(), element_len);
128     name[pos + element_len] = JVM_SIGNATURE_ENDCLASS;
129     name[pos + element_len + 1] = '\0';
130   }
131   return ciSymbol::make(name);
132 }
133 
134 // ------------------------------------------------------------------
135 // ciObjArrayKlass::make_impl
136 //
137 // Implementation of make.
138 ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) {

139   if (element_klass->is_loaded()) {
140     EXCEPTION_CONTEXT;
141     // The element klass is loaded
142     Klass* array = element_klass->get_Klass()->array_klass(THREAD);
143     if (HAS_PENDING_EXCEPTION) {
144       CLEAR_PENDING_EXCEPTION;
145       CURRENT_THREAD_ENV->record_out_of_memory_failure();
146       return ciEnv::unloaded_ciobjarrayklass();
147     }
148     return CURRENT_THREAD_ENV->get_obj_array_klass(array);
149   }
150 
151   // The array klass was unable to be made or the element klass was not loaded.

152   ciSymbol* array_name = construct_array_name(element_klass->name(), 1);
153   if (array_name == ciEnv::unloaded_cisymbol()) {
154     return ciEnv::unloaded_ciobjarrayklass();
155   }
156   return
157     CURRENT_ENV->get_unloaded_klass(element_klass, array_name)
158                         ->as_obj_array_klass();
159 }
160 
161 // ------------------------------------------------------------------
162 // ciObjArrayKlass::make
163 //
164 // Make an array klass corresponding to the specified primitive type.
165 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) {
166   GUARDED_VM_ENTRY(return make_impl(element_klass);)
167 }
168 
169 ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass, int dims) {
170   ciKlass* klass = element_klass;
171   for (int i = 0; i < dims; i++) {
172     klass = ciObjArrayKlass::make(klass);
173   }
174   return klass->as_obj_array_klass();
175 }
176 
177 ciKlass* ciObjArrayKlass::exact_klass() {
178   if (!is_loaded()) {
179     return nullptr;
180   }
181   ciType* base = base_element_type();
182   if (base->is_instance_klass()) {
183     ciInstanceKlass* ik = base->as_instance_klass();
184     // Even though MyValue is final, [LMyValue is only exact if the array
185     // is null-free due to null-free [LMyValue <: null-able [LMyValue.
186     if (ik->is_inlinetype() && !is_elem_null_free()) {
187       return nullptr;
188     }
189     if (ik->exact_klass() != nullptr) {
190       return this;
191     }
192   } else if (base->is_primitive_type()) {
193     return this;
194   }
195   return nullptr;
196 }
197 
198 bool ciObjArrayKlass::is_elem_null_free() const {
199   GUARDED_VM_ENTRY(return get_Klass()->is_null_free_array_klass();)
200 }
< prev index next >