Mercurial > hg > graal-jvmci-8
annotate src/share/vm/ci/ciObject.cpp @ 1478:5571b97fc1ec
More JNI global handle clean ups.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Fri, 26 Nov 2010 19:45:05 +0100 |
parents | 3483ec571caf |
children | 2d26b0046e0d |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1999-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_ciObject.cpp.incl" | |
27 | |
28 // ciObject | |
29 // | |
30 // This class represents an oop in the HotSpot virtual machine. | |
31 // Its subclasses are structured in a hierarchy which mirrors | |
32 // an aggregate of the VM's oop and klass hierarchies (see | |
33 // oopHierarchy.hpp). Each instance of ciObject holds a handle | |
34 // to a corresponding oop on the VM side and provides routines | |
35 // for accessing the information in its oop. By using the ciObject | |
36 // hierarchy for accessing oops in the VM, the compiler ensures | |
37 // that it is safe with respect to garbage collection; that is, | |
38 // GC and compilation can proceed independently without | |
39 // interference. | |
40 // | |
41 // Within the VM, the oop and klass hierarchies are separate. | |
42 // The compiler interface does not preserve this separation -- | |
43 // the distinction between `klassOop' and `Klass' are not | |
44 // reflected in the interface and instead the Klass hierarchy | |
45 // is directly modeled as the subclasses of ciKlass. | |
46 | |
47 // ------------------------------------------------------------------ | |
48 // ciObject::ciObject | |
49 ciObject::ciObject(oop o) { | |
50 ASSERT_IN_VM; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
51 if (ciObjectFactory::is_initialized()) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
52 if (UseC1X) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
53 _handle = JNIHandles::make_global(o); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
54 _temp_global = true; |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
55 } else { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
56 _handle = JNIHandles::make_local(o); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
57 } |
0 | 58 } else { |
59 _handle = JNIHandles::make_global(o); | |
60 } | |
61 _klass = NULL; | |
62 _ident = 0; | |
989 | 63 init_flags_from(o); |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
64 _temp_global = false; |
0 | 65 } |
66 | |
67 // ------------------------------------------------------------------ | |
68 // ciObject::ciObject | |
69 // | |
70 ciObject::ciObject(Handle h) { | |
71 ASSERT_IN_VM; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
72 if (ciObjectFactory::is_initialized()) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
73 if (UseC1X) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
74 _handle = JNIHandles::make_global(h); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
75 _temp_global = true; |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
76 } else { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
77 _handle = JNIHandles::make_local(h()); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
78 } |
0 | 79 } else { |
80 _handle = JNIHandles::make_global(h); | |
81 } | |
82 _klass = NULL; | |
83 _ident = 0; | |
989 | 84 init_flags_from(h()); |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
85 _temp_global = false; |
0 | 86 } |
87 | |
88 // ------------------------------------------------------------------ | |
89 // ciObject::ciObject | |
90 // | |
91 // Unloaded klass/method variant. `klass' is the klass of the unloaded | |
92 // klass/method, if that makes sense. | |
93 ciObject::ciObject(ciKlass* klass) { | |
94 ASSERT_IN_VM; | |
95 assert(klass != NULL, "must supply klass"); | |
96 _handle = NULL; | |
97 _klass = klass; | |
98 _ident = 0; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
99 _temp_global = false; |
0 | 100 } |
101 | |
102 // ------------------------------------------------------------------ | |
103 // ciObject::ciObject | |
104 // | |
105 // NULL variant. Used only by ciNullObject. | |
106 ciObject::ciObject() { | |
107 ASSERT_IN_VM; | |
108 _handle = NULL; | |
109 _klass = NULL; | |
110 _ident = 0; | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
111 _temp_global = false; |
0 | 112 } |
113 | |
114 // ------------------------------------------------------------------ | |
115 // ciObject::klass | |
116 // | |
117 // Get the ciKlass of this ciObject. | |
118 ciKlass* ciObject::klass() { | |
119 if (_klass == NULL) { | |
120 if (_handle == NULL) { | |
121 // When both _klass and _handle are NULL, we are dealing | |
122 // with the distinguished instance of ciNullObject. | |
123 // No one should ask it for its klass. | |
124 assert(is_null_object(), "must be null object"); | |
125 ShouldNotReachHere(); | |
126 return NULL; | |
127 } | |
128 | |
129 GUARDED_VM_ENTRY( | |
130 oop o = get_oop(); | |
131 _klass = CURRENT_ENV->get_object(o->klass())->as_klass(); | |
132 ); | |
133 } | |
134 return _klass; | |
135 } | |
136 | |
137 // ------------------------------------------------------------------ | |
138 // ciObject::set_ident | |
139 // | |
140 // Set the unique identity number of a ciObject. | |
141 void ciObject::set_ident(uint id) { | |
142 assert((_ident >> FLAG_BITS) == 0, "must only initialize once"); | |
143 assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big"); | |
144 _ident = _ident + (id << FLAG_BITS); | |
145 } | |
146 | |
147 // ------------------------------------------------------------------ | |
148 // ciObject::ident | |
149 // | |
150 // Report the unique identity number of a ciObject. | |
151 uint ciObject::ident() { | |
152 uint id = _ident >> FLAG_BITS; | |
153 assert(id != 0, "must be initialized"); | |
154 return id; | |
155 } | |
156 | |
157 // ------------------------------------------------------------------ | |
158 // ciObject::equals | |
159 // | |
160 // Are two ciObjects equal? | |
161 bool ciObject::equals(ciObject* obj) { | |
162 return (this == obj); | |
163 } | |
164 | |
165 // ------------------------------------------------------------------ | |
166 // ciObject::hash | |
167 // | |
168 // A hash value for the convenience of compilers. | |
169 // | |
170 // Implementation note: we use the address of the ciObject as the | |
171 // basis for the hash. Use the _ident field, which is well-behaved. | |
172 int ciObject::hash() { | |
173 return ident() * 31; | |
174 } | |
175 | |
176 // ------------------------------------------------------------------ | |
989 | 177 // ciObject::constant_encoding |
0 | 178 // |
179 // The address which the compiler should embed into the | |
180 // generated code to represent this oop. This address | |
181 // is not the true address of the oop -- it will get patched | |
182 // during nmethod creation. | |
183 // | |
184 // | |
185 // | |
186 // Implementation note: we use the handle as the encoding. The | |
187 // nmethod constructor resolves the handle and patches in the oop. | |
188 // | |
189 // This method should be changed to return an generified address | |
190 // to discourage use of the JNI handle. | |
989 | 191 jobject ciObject::constant_encoding() { |
0 | 192 assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
989 | 193 assert(can_be_constant(), "oop must be NULL or perm"); |
0 | 194 return handle(); |
195 } | |
196 | |
197 // ------------------------------------------------------------------ | |
989 | 198 // ciObject::can_be_constant |
199 bool ciObject::can_be_constant() { | |
200 if (ScavengeRootsInCode >= 1) return true; // now everybody can encode as a constant | |
201 return handle() == NULL || !is_scavengable(); | |
202 } | |
203 | |
204 // ------------------------------------------------------------------ | |
205 // ciObject::should_be_constant() | |
206 bool ciObject::should_be_constant() { | |
207 if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant | |
208 return handle() == NULL || !is_scavengable(); | |
0 | 209 } |
210 | |
211 | |
212 // ------------------------------------------------------------------ | |
213 // ciObject::print | |
214 // | |
215 // Print debugging output about this ciObject. | |
216 // | |
217 // Implementation note: dispatch to the virtual print_impl behavior | |
218 // for this ciObject. | |
219 void ciObject::print(outputStream* st) { | |
220 st->print("<%s", type_string()); | |
221 GUARDED_VM_ENTRY(print_impl(st);) | |
989 | 222 st->print(" ident=%d %s%s address=0x%x>", ident(), |
0 | 223 is_perm() ? "PERM" : "", |
989 | 224 is_scavengable() ? "SCAVENGABLE" : "", |
0 | 225 (address)this); |
226 } | |
227 | |
228 // ------------------------------------------------------------------ | |
229 // ciObject::print_oop | |
230 // | |
231 // Print debugging output about the oop this ciObject represents. | |
232 void ciObject::print_oop(outputStream* st) { | |
233 if (is_null_object()) { | |
234 st->print_cr("NULL"); | |
235 } else if (!is_loaded()) { | |
236 st->print_cr("UNLOADED"); | |
237 } else { | |
238 GUARDED_VM_ENTRY(get_oop()->print_on(st);) | |
239 } | |
240 } |