Mercurial > hg > truffle
annotate src/share/vm/ci/ciObject.cpp @ 3659:b711e226cfaf
Fixed another possible oop/handle issue.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 17 Nov 2011 17:10:52 +0100 |
parents | 47edfca346ab |
children | 46f211fe010c |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
989
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
989
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
989
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciObject.hpp" | |
27 #include "ci/ciUtilities.hpp" | |
28 #include "gc_interface/collectedHeap.inline.hpp" | |
29 #include "oops/oop.inline2.hpp" | |
0 | 30 |
31 // ciObject | |
32 // | |
33 // This class represents an oop in the HotSpot virtual machine. | |
34 // Its subclasses are structured in a hierarchy which mirrors | |
35 // an aggregate of the VM's oop and klass hierarchies (see | |
36 // oopHierarchy.hpp). Each instance of ciObject holds a handle | |
37 // to a corresponding oop on the VM side and provides routines | |
38 // for accessing the information in its oop. By using the ciObject | |
39 // hierarchy for accessing oops in the VM, the compiler ensures | |
40 // that it is safe with respect to garbage collection; that is, | |
41 // GC and compilation can proceed independently without | |
42 // interference. | |
43 // | |
44 // Within the VM, the oop and klass hierarchies are separate. | |
45 // The compiler interface does not preserve this separation -- | |
46 // the distinction between `klassOop' and `Klass' are not | |
47 // reflected in the interface and instead the Klass hierarchy | |
48 // is directly modeled as the subclasses of ciKlass. | |
49 | |
50 // ------------------------------------------------------------------ | |
51 // ciObject::ciObject | |
52 ciObject::ciObject(oop o) { | |
53 ASSERT_IN_VM; | |
54 if (ciObjectFactory::is_initialized()) { | |
2891
75a99b4f1c98
Rebranded C++ part from C1X to Graal.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2044
diff
changeset
|
55 if (UseGraal) { |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
56 _handle = JNIHandles::make_global(o); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
57 _temp_global = true; |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
58 } else { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
59 _handle = JNIHandles::make_local(o); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
60 } |
0 | 61 } else { |
62 _handle = JNIHandles::make_global(o); | |
63 } | |
64 _klass = NULL; | |
65 _ident = 0; | |
989 | 66 init_flags_from(o); |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
67 _temp_global = false; |
0 | 68 } |
69 | |
70 // ------------------------------------------------------------------ | |
71 // ciObject::ciObject | |
72 // | |
73 ciObject::ciObject(Handle h) { | |
74 ASSERT_IN_VM; | |
75 if (ciObjectFactory::is_initialized()) { | |
3657
47edfca346ab
Fix a safepoint bug in code installer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3464
diff
changeset
|
76 _handle = JNIHandles::make_local(h()); |
0 | 77 } else { |
78 _handle = JNIHandles::make_global(h); | |
79 } | |
80 _klass = NULL; | |
81 _ident = 0; | |
989 | 82 init_flags_from(h()); |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
83 _temp_global = false; |
0 | 84 } |
85 | |
86 // ------------------------------------------------------------------ | |
87 // ciObject::ciObject | |
88 // | |
89 // Unloaded klass/method variant. `klass' is the klass of the unloaded | |
90 // klass/method, if that makes sense. | |
91 ciObject::ciObject(ciKlass* klass) { | |
92 ASSERT_IN_VM; | |
93 assert(klass != NULL, "must supply klass"); | |
94 _handle = NULL; | |
95 _klass = klass; | |
96 _ident = 0; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
97 _temp_global = false; |
0 | 98 } |
99 | |
100 // ------------------------------------------------------------------ | |
101 // ciObject::ciObject | |
102 // | |
103 // NULL variant. Used only by ciNullObject. | |
104 ciObject::ciObject() { | |
105 ASSERT_IN_VM; | |
106 _handle = NULL; | |
107 _klass = NULL; | |
108 _ident = 0; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
109 _temp_global = false; |
0 | 110 } |
111 | |
112 // ------------------------------------------------------------------ | |
113 // ciObject::klass | |
114 // | |
115 // Get the ciKlass of this ciObject. | |
116 ciKlass* ciObject::klass() { | |
117 if (_klass == NULL) { | |
118 if (_handle == NULL) { | |
119 // When both _klass and _handle are NULL, we are dealing | |
120 // with the distinguished instance of ciNullObject. | |
121 // No one should ask it for its klass. | |
122 assert(is_null_object(), "must be null object"); | |
123 ShouldNotReachHere(); | |
124 return NULL; | |
125 } | |
126 | |
127 GUARDED_VM_ENTRY( | |
128 oop o = get_oop(); | |
129 _klass = CURRENT_ENV->get_object(o->klass())->as_klass(); | |
130 ); | |
131 } | |
132 return _klass; | |
133 } | |
134 | |
135 // ------------------------------------------------------------------ | |
136 // ciObject::set_ident | |
137 // | |
138 // Set the unique identity number of a ciObject. | |
139 void ciObject::set_ident(uint id) { | |
140 assert((_ident >> FLAG_BITS) == 0, "must only initialize once"); | |
141 assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big"); | |
142 _ident = _ident + (id << FLAG_BITS); | |
143 } | |
144 | |
145 // ------------------------------------------------------------------ | |
146 // ciObject::ident | |
147 // | |
148 // Report the unique identity number of a ciObject. | |
149 uint ciObject::ident() { | |
150 uint id = _ident >> FLAG_BITS; | |
151 assert(id != 0, "must be initialized"); | |
152 return id; | |
153 } | |
154 | |
155 // ------------------------------------------------------------------ | |
156 // ciObject::equals | |
157 // | |
158 // Are two ciObjects equal? | |
159 bool ciObject::equals(ciObject* obj) { | |
160 return (this == obj); | |
161 } | |
162 | |
163 // ------------------------------------------------------------------ | |
164 // ciObject::hash | |
165 // | |
166 // A hash value for the convenience of compilers. | |
167 // | |
168 // Implementation note: we use the address of the ciObject as the | |
169 // basis for the hash. Use the _ident field, which is well-behaved. | |
170 int ciObject::hash() { | |
171 return ident() * 31; | |
172 } | |
173 | |
174 // ------------------------------------------------------------------ | |
989 | 175 // ciObject::constant_encoding |
0 | 176 // |
177 // The address which the compiler should embed into the | |
178 // generated code to represent this oop. This address | |
179 // is not the true address of the oop -- it will get patched | |
180 // during nmethod creation. | |
181 // | |
182 // | |
183 // | |
184 // Implementation note: we use the handle as the encoding. The | |
185 // nmethod constructor resolves the handle and patches in the oop. | |
186 // | |
187 // This method should be changed to return an generified address | |
188 // to discourage use of the JNI handle. | |
989 | 189 jobject ciObject::constant_encoding() { |
0 | 190 assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
989 | 191 assert(can_be_constant(), "oop must be NULL or perm"); |
0 | 192 return handle(); |
193 } | |
194 | |
195 // ------------------------------------------------------------------ | |
989 | 196 // ciObject::can_be_constant |
197 bool ciObject::can_be_constant() { | |
198 if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant | |
3402
28a9fe9534ea
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
3283
diff
changeset
|
199 return handle() == NULL || is_perm(); |
989 | 200 } |
201 | |
202 // ------------------------------------------------------------------ | |
203 // ciObject::should_be_constant() | |
204 bool ciObject::should_be_constant() { | |
205 if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant | |
3283
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
206 if (!JavaObjectsInPerm && !is_null_object()) { |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
207 // We want Strings and Classes to be embeddable by default since |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
208 // they used to be in the perm world. Not all Strings used to be |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
209 // embeddable but there's no easy way to distinguish the interned |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
210 // from the regulars ones so just treat them all that way. |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
211 ciEnv* env = CURRENT_ENV; |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
212 if (klass() == env->String_klass() || klass() == env->Class_klass()) { |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
213 return true; |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
214 } |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
215 } |
3402
28a9fe9534ea
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
3283
diff
changeset
|
216 return handle() == NULL || is_perm(); |
0 | 217 } |
218 | |
219 | |
220 // ------------------------------------------------------------------ | |
221 // ciObject::print | |
222 // | |
223 // Print debugging output about this ciObject. | |
224 // | |
225 // Implementation note: dispatch to the virtual print_impl behavior | |
226 // for this ciObject. | |
227 void ciObject::print(outputStream* st) { | |
228 st->print("<%s", type_string()); | |
229 GUARDED_VM_ENTRY(print_impl(st);) | |
989 | 230 st->print(" ident=%d %s%s address=0x%x>", ident(), |
0 | 231 is_perm() ? "PERM" : "", |
989 | 232 is_scavengable() ? "SCAVENGABLE" : "", |
0 | 233 (address)this); |
234 } | |
235 | |
236 // ------------------------------------------------------------------ | |
237 // ciObject::print_oop | |
238 // | |
239 // Print debugging output about the oop this ciObject represents. | |
240 void ciObject::print_oop(outputStream* st) { | |
241 if (is_null_object()) { | |
242 st->print_cr("NULL"); | |
243 } else if (!is_loaded()) { | |
244 st->print_cr("UNLOADED"); | |
245 } else { | |
246 GUARDED_VM_ENTRY(get_oop()->print_on(st);) | |
247 } | |
248 } |