1 /*
 2  * Copyright (c) 2016, 2021, 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/ciFlatArrayKlass.hpp"
26 #include "ci/ciInlineKlass.hpp"
27 #include "ci/ciInstanceKlass.hpp"
28 #include "ci/ciObjArrayKlass.hpp"
29 #include "ci/ciSymbol.hpp"
30 #include "ci/ciUtilities.hpp"
31 #include "ci/ciUtilities.inline.hpp"
32 #include "oops/flatArrayKlass.hpp"
33 #include "oops/inlineKlass.inline.hpp"
34 
35 // ciFlatArrayKlass
36 //
37 // This class represents a Klass* in the HotSpot virtual machine
38 // whose Klass part is a FlatArrayKlass.
39 
40 // ------------------------------------------------------------------
41 // ciFlatArrayKlass::ciFlatArrayKlass
42 //
43 // Constructor for loaded inline type array klasses.
44 ciFlatArrayKlass::ciFlatArrayKlass(Klass* h_k) : ciArrayKlass(h_k) {
45   assert(get_Klass()->is_flatArray_klass(), "wrong type");
46   InlineKlass* element_Klass = get_FlatArrayKlass()->element_klass();
47   _base_element_klass = CURRENT_ENV->get_klass(element_Klass);
48   assert(_base_element_klass->is_inlinetype(), "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 // ciFlatArrayKlass::element_klass
61 //
62 // What is the one-level element type of this array?
63 ciKlass* ciFlatArrayKlass::element_klass() {
64   if (_element_klass == nullptr) {
65     assert(dimension() > 1, "_element_klass should not be nullptr");
66     assert(is_loaded(), "FlatArrayKlass must be loaded");
67     // Produce the element klass.
68     VM_ENTRY_MARK;
69     Klass* element_Klass = get_FlatArrayKlass()->element_klass();
70     _element_klass = CURRENT_THREAD_ENV->get_klass(element_Klass);
71   }
72   return _element_klass;
73 }
74 
75 ciKlass* ciFlatArrayKlass::exact_klass() {
76   assert(element_klass()->is_loaded() && element_klass()->as_inline_klass()->exact_klass() != nullptr, "must have exact klass");
77   return this;
78 }