author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 54120 | 677cede5608e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3908
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3908
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3908
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "ci/ciObject.hpp" |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49192
diff
changeset
|
27 |
#include "ci/ciUtilities.inline.hpp" |
30764 | 28 |
#include "gc/shared/collectedHeap.inline.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
24424
diff
changeset
|
29 |
#include "oops/oop.inline.hpp" |
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
30 |
#include "runtime/jniHandles.inline.hpp" |
1 | 31 |
|
32 |
// ciObject |
|
33 |
// |
|
34 |
// This class represents an oop in the HotSpot virtual machine. |
|
35 |
// Its subclasses are structured in a hierarchy which mirrors |
|
36 |
// an aggregate of the VM's oop and klass hierarchies (see |
|
37 |
// oopHierarchy.hpp). Each instance of ciObject holds a handle |
|
38 |
// to a corresponding oop on the VM side and provides routines |
|
39 |
// for accessing the information in its oop. By using the ciObject |
|
40 |
// hierarchy for accessing oops in the VM, the compiler ensures |
|
41 |
// that it is safe with respect to garbage collection; that is, |
|
42 |
// GC and compilation can proceed independently without |
|
43 |
// interference. |
|
44 |
// |
|
45 |
// Within the VM, the oop and klass hierarchies are separate. |
|
46 |
// The compiler interface does not preserve this separation -- |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10514
diff
changeset
|
47 |
// the distinction between `Klass*' and `Klass' are not |
1 | 48 |
// reflected in the interface and instead the Klass hierarchy |
49 |
// is directly modeled as the subclasses of ciKlass. |
|
50 |
||
51 |
// ------------------------------------------------------------------ |
|
52 |
// ciObject::ciObject |
|
53 |
ciObject::ciObject(oop o) { |
|
54 |
ASSERT_IN_VM; |
|
55 |
if (ciObjectFactory::is_initialized()) { |
|
56 |
_handle = JNIHandles::make_local(o); |
|
57 |
} else { |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
30764
diff
changeset
|
58 |
Handle obj(Thread::current(), o); |
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
30764
diff
changeset
|
59 |
_handle = JNIHandles::make_global(obj); |
1 | 60 |
} |
61 |
_klass = NULL; |
|
54120 | 62 |
assert(oopDesc::is_oop_or_null(o), "Checking"); |
1 | 63 |
} |
64 |
||
65 |
// ------------------------------------------------------------------ |
|
66 |
// ciObject::ciObject |
|
67 |
// |
|
68 |
ciObject::ciObject(Handle h) { |
|
69 |
ASSERT_IN_VM; |
|
70 |
if (ciObjectFactory::is_initialized()) { |
|
71 |
_handle = JNIHandles::make_local(h()); |
|
72 |
} else { |
|
73 |
_handle = JNIHandles::make_global(h); |
|
74 |
} |
|
75 |
_klass = NULL; |
|
54120 | 76 |
assert(oopDesc::is_oop_or_null(h()), "Checking"); |
1 | 77 |
} |
78 |
||
79 |
// ------------------------------------------------------------------ |
|
80 |
// ciObject::ciObject |
|
81 |
// |
|
82 |
// Unloaded klass/method variant. `klass' is the klass of the unloaded |
|
83 |
// klass/method, if that makes sense. |
|
84 |
ciObject::ciObject(ciKlass* klass) { |
|
85 |
ASSERT_IN_VM; |
|
86 |
assert(klass != NULL, "must supply klass"); |
|
87 |
_handle = NULL; |
|
88 |
_klass = klass; |
|
89 |
} |
|
90 |
||
91 |
// ------------------------------------------------------------------ |
|
92 |
// ciObject::ciObject |
|
93 |
// |
|
94 |
// NULL variant. Used only by ciNullObject. |
|
95 |
ciObject::ciObject() { |
|
96 |
ASSERT_IN_VM; |
|
97 |
_handle = NULL; |
|
98 |
_klass = NULL; |
|
99 |
} |
|
100 |
||
101 |
// ------------------------------------------------------------------ |
|
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
102 |
// ciObject::get_oop |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
103 |
// |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
104 |
// Get the oop of this ciObject. |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
105 |
oop ciObject::get_oop() const { |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
106 |
return JNIHandles::resolve_non_null(_handle); |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
107 |
} |
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
108 |
|
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
47216
diff
changeset
|
109 |
// ------------------------------------------------------------------ |
1 | 110 |
// ciObject::klass |
111 |
// |
|
112 |
// Get the ciKlass of this ciObject. |
|
113 |
ciKlass* ciObject::klass() { |
|
114 |
if (_klass == NULL) { |
|
115 |
if (_handle == NULL) { |
|
116 |
// When both _klass and _handle are NULL, we are dealing |
|
117 |
// with the distinguished instance of ciNullObject. |
|
118 |
// No one should ask it for its klass. |
|
119 |
assert(is_null_object(), "must be null object"); |
|
120 |
ShouldNotReachHere(); |
|
121 |
return NULL; |
|
122 |
} |
|
123 |
||
124 |
GUARDED_VM_ENTRY( |
|
125 |
oop o = get_oop(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10514
diff
changeset
|
126 |
_klass = CURRENT_ENV->get_klass(o->klass()); |
1 | 127 |
); |
128 |
} |
|
129 |
return _klass; |
|
130 |
} |
|
131 |
||
132 |
// ------------------------------------------------------------------ |
|
133 |
// ciObject::equals |
|
134 |
// |
|
135 |
// Are two ciObjects equal? |
|
136 |
bool ciObject::equals(ciObject* obj) { |
|
137 |
return (this == obj); |
|
138 |
} |
|
139 |
||
140 |
// ------------------------------------------------------------------ |
|
141 |
// ciObject::hash |
|
142 |
// |
|
143 |
// A hash value for the convenience of compilers. |
|
144 |
// |
|
145 |
// Implementation note: we use the address of the ciObject as the |
|
146 |
// basis for the hash. Use the _ident field, which is well-behaved. |
|
147 |
int ciObject::hash() { |
|
148 |
return ident() * 31; |
|
149 |
} |
|
150 |
||
151 |
// ------------------------------------------------------------------ |
|
3908 | 152 |
// ciObject::constant_encoding |
1 | 153 |
// |
154 |
// The address which the compiler should embed into the |
|
155 |
// generated code to represent this oop. This address |
|
156 |
// is not the true address of the oop -- it will get patched |
|
157 |
// during nmethod creation. |
|
158 |
// |
|
159 |
// |
|
160 |
// |
|
161 |
// Implementation note: we use the handle as the encoding. The |
|
162 |
// nmethod constructor resolves the handle and patches in the oop. |
|
163 |
// |
|
164 |
// This method should be changed to return an generified address |
|
165 |
// to discourage use of the JNI handle. |
|
3908 | 166 |
jobject ciObject::constant_encoding() { |
1 | 167 |
assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
168 |
return handle(); |
|
169 |
} |
|
170 |
||
171 |
// ------------------------------------------------------------------ |
|
3908 | 172 |
// ciObject::should_be_constant() |
173 |
bool ciObject::should_be_constant() { |
|
174 |
if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant |
|
10514
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
175 |
if (is_null_object()) return true; |
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
176 |
|
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
177 |
ciEnv* env = CURRENT_ENV; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10514
diff
changeset
|
178 |
|
9332
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
179 |
// We want Strings and Classes to be embeddable by default since |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
180 |
// they used to be in the perm world. Not all Strings used to be |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
181 |
// embeddable but there's no easy way to distinguish the interned |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
182 |
// from the regulars ones so just treat them all that way. |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
183 |
if (klass() == env->String_klass() || klass() == env->Class_klass()) { |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
184 |
return true; |
2c0eaca39eb4
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
7397
diff
changeset
|
185 |
} |
24322 | 186 |
if (klass()->is_subclass_of(env->MethodHandle_klass()) || |
187 |
klass()->is_subclass_of(env->CallSite_klass())) { |
|
10514
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
188 |
// We want to treat these aggressively. |
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
189 |
return true; |
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
190 |
} |
e229a19078cf
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
9959
diff
changeset
|
191 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10514
diff
changeset
|
192 |
return handle() == NULL; |
1 | 193 |
} |
194 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10514
diff
changeset
|
195 |
// ------------------------------------------------------------------ |
1 | 196 |
// ciObject::print |
197 |
// |
|
198 |
// Print debugging output about this ciObject. |
|
199 |
// |
|
200 |
// Implementation note: dispatch to the virtual print_impl behavior |
|
201 |
// for this ciObject. |
|
202 |
void ciObject::print(outputStream* st) { |
|
203 |
st->print("<%s", type_string()); |
|
204 |
GUARDED_VM_ENTRY(print_impl(st);) |
|
54120 | 205 |
st->print(" ident=%d address=" INTPTR_FORMAT ">", ident(), p2i(this)); |
1 | 206 |
} |
207 |
||
208 |
// ------------------------------------------------------------------ |
|
209 |
// ciObject::print_oop |
|
210 |
// |
|
211 |
// Print debugging output about the oop this ciObject represents. |
|
212 |
void ciObject::print_oop(outputStream* st) { |
|
213 |
if (is_null_object()) { |
|
214 |
st->print_cr("NULL"); |
|
215 |
} else if (!is_loaded()) { |
|
216 |
st->print_cr("UNLOADED"); |
|
217 |
} else { |
|
218 |
GUARDED_VM_ENTRY(get_oop()->print_on(st);) |
|
219 |
} |
|
220 |
} |