1 | /* |
2 | * Copyright (c) 2000, 2017, 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/ciEnv.hpp" |
27 | #include "ci/ciType.hpp" |
28 | #include "ci/ciUtilities.inline.hpp" |
29 | #include "classfile/systemDictionary.hpp" |
30 | #include "memory/resourceArea.hpp" |
31 | #include "memory/universe.hpp" |
32 | #include "oops/oop.inline.hpp" |
33 | |
34 | ciType* ciType::_basic_types[T_CONFLICT+1]; |
35 | |
36 | // ciType |
37 | // |
38 | // This class represents either a class (T_OBJECT), array (T_ARRAY), |
39 | // or one of the primitive types such as T_INT. |
40 | |
41 | // ------------------------------------------------------------------ |
42 | // ciType::ciType |
43 | // |
44 | ciType::ciType(BasicType basic_type) : ciMetadata() { |
45 | assert(basic_type >= T_BOOLEAN && basic_type <= T_CONFLICT, "range check" ); |
46 | _basic_type = basic_type; |
47 | } |
48 | |
49 | ciType::ciType(Klass* k) : ciMetadata(k) { |
50 | _basic_type = k->is_array_klass() ? T_ARRAY : T_OBJECT; |
51 | } |
52 | |
53 | |
54 | // ------------------------------------------------------------------ |
55 | // ciType::is_subtype_of |
56 | // |
57 | bool ciType::is_subtype_of(ciType* type) { |
58 | if (this == type) return true; |
59 | if (is_klass() && type->is_klass()) |
60 | return this->as_klass()->is_subtype_of(type->as_klass()); |
61 | return false; |
62 | } |
63 | |
64 | // ------------------------------------------------------------------ |
65 | // ciType::name |
66 | // |
67 | // Return the name of this type |
68 | const char* ciType::name() { |
69 | if (is_primitive_type()) { |
70 | return type2name(basic_type()); |
71 | } else { |
72 | assert(is_klass(), "must be" ); |
73 | return as_klass()->name()->as_utf8(); |
74 | } |
75 | } |
76 | |
77 | // ------------------------------------------------------------------ |
78 | // ciType::print_impl |
79 | // |
80 | // Implementation of the print method. |
81 | void ciType::print_impl(outputStream* st) { |
82 | st->print(" type=" ); |
83 | print_name_on(st); |
84 | } |
85 | |
86 | // ------------------------------------------------------------------ |
87 | // ciType::print_name |
88 | // |
89 | // Print the name of this type |
90 | void ciType::print_name_on(outputStream* st) { |
91 | ResourceMark rm; |
92 | st->print("%s" , name()); |
93 | } |
94 | |
95 | |
96 | |
97 | // ------------------------------------------------------------------ |
98 | // ciType::java_mirror |
99 | // |
100 | ciInstance* ciType::java_mirror() { |
101 | VM_ENTRY_MARK; |
102 | return CURRENT_THREAD_ENV->get_instance(Universe::java_mirror(basic_type())); |
103 | } |
104 | |
105 | // ------------------------------------------------------------------ |
106 | // ciType::box_klass |
107 | // |
108 | ciKlass* ciType::box_klass() { |
109 | if (!is_primitive_type()) return this->as_klass(); // reference types are "self boxing" |
110 | |
111 | // Void is "boxed" with a null. |
112 | if (basic_type() == T_VOID) return NULL; |
113 | |
114 | VM_ENTRY_MARK; |
115 | return CURRENT_THREAD_ENV->get_instance_klass(SystemDictionary::box_klass(basic_type())); |
116 | } |
117 | |
118 | |
119 | // ------------------------------------------------------------------ |
120 | // ciType::make |
121 | // |
122 | // Produce the ciType for a given primitive BasicType. |
123 | // As a bonus, produce the right reference type for T_OBJECT. |
124 | // Does not work on T_ARRAY. |
125 | ciType* ciType::make(BasicType t) { |
126 | // short, etc. |
127 | // Note: Bare T_ADDRESS means a raw pointer type, not a return_address. |
128 | assert((uint)t < T_CONFLICT+1, "range check" ); |
129 | if (t == T_OBJECT) return ciEnv::_Object_klass; // java/lang/Object |
130 | assert(_basic_types[t] != NULL, "domain check" ); |
131 | return _basic_types[t]; |
132 | } |
133 | |
134 | // ciReturnAddress |
135 | // |
136 | // This class represents the type of a specific return address in the |
137 | // bytecodes. |
138 | |
139 | // ------------------------------------------------------------------ |
140 | // ciReturnAddress::ciReturnAddress |
141 | // |
142 | ciReturnAddress::ciReturnAddress(int bci) : ciType(T_ADDRESS) { |
143 | assert(0 <= bci, "bci cannot be negative" ); |
144 | _bci = bci; |
145 | } |
146 | |
147 | // ------------------------------------------------------------------ |
148 | // ciReturnAddress::print_impl |
149 | // |
150 | // Implementation of the print method. |
151 | void ciReturnAddress::print_impl(outputStream* st) { |
152 | st->print(" bci=%d" , _bci); |
153 | } |
154 | |
155 | // ------------------------------------------------------------------ |
156 | // ciReturnAddress::make |
157 | ciReturnAddress* ciReturnAddress::make(int bci) { |
158 | GUARDED_VM_ENTRY(return CURRENT_ENV->get_return_address(bci);) |
159 | } |
160 | |