Mercurial > hg > truffle
annotate src/share/vm/ci/ciObject.cpp @ 4128:f1391adc6681
7112034: Parallel CMS fails to properly mark reference objects
Summary: Enabled reference processing when work stealing during concurrent marking
Reviewed-by: jmasa, brutisso
author | stefank |
---|---|
date | Mon, 28 Nov 2011 10:19:26 +0100 |
parents | c26de9aef2ed |
children | 04b9a2566eec da91efe96a93 |
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()) { | |
55 _handle = JNIHandles::make_local(o); | |
56 } else { | |
57 _handle = JNIHandles::make_global(o); | |
58 } | |
59 _klass = NULL; | |
60 _ident = 0; | |
989 | 61 init_flags_from(o); |
0 | 62 } |
63 | |
64 // ------------------------------------------------------------------ | |
65 // ciObject::ciObject | |
66 // | |
67 ciObject::ciObject(Handle h) { | |
68 ASSERT_IN_VM; | |
69 if (ciObjectFactory::is_initialized()) { | |
70 _handle = JNIHandles::make_local(h()); | |
71 } else { | |
72 _handle = JNIHandles::make_global(h); | |
73 } | |
74 _klass = NULL; | |
75 _ident = 0; | |
989 | 76 init_flags_from(h()); |
0 | 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 _ident = 0; | |
90 } | |
91 | |
92 // ------------------------------------------------------------------ | |
93 // ciObject::ciObject | |
94 // | |
95 // NULL variant. Used only by ciNullObject. | |
96 ciObject::ciObject() { | |
97 ASSERT_IN_VM; | |
98 _handle = NULL; | |
99 _klass = NULL; | |
100 _ident = 0; | |
101 } | |
102 | |
103 // ------------------------------------------------------------------ | |
104 // ciObject::klass | |
105 // | |
106 // Get the ciKlass of this ciObject. | |
107 ciKlass* ciObject::klass() { | |
108 if (_klass == NULL) { | |
109 if (_handle == NULL) { | |
110 // When both _klass and _handle are NULL, we are dealing | |
111 // with the distinguished instance of ciNullObject. | |
112 // No one should ask it for its klass. | |
113 assert(is_null_object(), "must be null object"); | |
114 ShouldNotReachHere(); | |
115 return NULL; | |
116 } | |
117 | |
118 GUARDED_VM_ENTRY( | |
119 oop o = get_oop(); | |
120 _klass = CURRENT_ENV->get_object(o->klass())->as_klass(); | |
121 ); | |
122 } | |
123 return _klass; | |
124 } | |
125 | |
126 // ------------------------------------------------------------------ | |
127 // ciObject::set_ident | |
128 // | |
129 // Set the unique identity number of a ciObject. | |
130 void ciObject::set_ident(uint id) { | |
131 assert((_ident >> FLAG_BITS) == 0, "must only initialize once"); | |
132 assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big"); | |
133 _ident = _ident + (id << FLAG_BITS); | |
134 } | |
135 | |
136 // ------------------------------------------------------------------ | |
137 // ciObject::ident | |
138 // | |
139 // Report the unique identity number of a ciObject. | |
140 uint ciObject::ident() { | |
141 uint id = _ident >> FLAG_BITS; | |
142 assert(id != 0, "must be initialized"); | |
143 return id; | |
144 } | |
145 | |
146 // ------------------------------------------------------------------ | |
147 // ciObject::equals | |
148 // | |
149 // Are two ciObjects equal? | |
150 bool ciObject::equals(ciObject* obj) { | |
151 return (this == obj); | |
152 } | |
153 | |
154 // ------------------------------------------------------------------ | |
155 // ciObject::hash | |
156 // | |
157 // A hash value for the convenience of compilers. | |
158 // | |
159 // Implementation note: we use the address of the ciObject as the | |
160 // basis for the hash. Use the _ident field, which is well-behaved. | |
161 int ciObject::hash() { | |
162 return ident() * 31; | |
163 } | |
164 | |
165 // ------------------------------------------------------------------ | |
989 | 166 // ciObject::constant_encoding |
0 | 167 // |
168 // The address which the compiler should embed into the | |
169 // generated code to represent this oop. This address | |
170 // is not the true address of the oop -- it will get patched | |
171 // during nmethod creation. | |
172 // | |
173 // | |
174 // | |
175 // Implementation note: we use the handle as the encoding. The | |
176 // nmethod constructor resolves the handle and patches in the oop. | |
177 // | |
178 // This method should be changed to return an generified address | |
179 // to discourage use of the JNI handle. | |
989 | 180 jobject ciObject::constant_encoding() { |
0 | 181 assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
989 | 182 assert(can_be_constant(), "oop must be NULL or perm"); |
0 | 183 return handle(); |
184 } | |
185 | |
186 // ------------------------------------------------------------------ | |
989 | 187 // ciObject::can_be_constant |
188 bool ciObject::can_be_constant() { | |
189 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
|
190 return handle() == NULL || is_perm(); |
989 | 191 } |
192 | |
193 // ------------------------------------------------------------------ | |
194 // ciObject::should_be_constant() | |
195 bool ciObject::should_be_constant() { | |
196 if (ScavengeRootsInCode >= 2) return true; // force everybody to be a constant | |
3905
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
197 if (is_null_object()) return true; |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
198 |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
199 ciEnv* env = CURRENT_ENV; |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
200 if (!JavaObjectsInPerm) { |
3283
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
201 // 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
|
202 // 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
|
203 // 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
|
204 // 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
|
205 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
|
206 return true; |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
207 } |
01fd6090fdd8
7032162: assert(flat != TypePtr::BOTTOM) failed: cannot alias-analyze an untyped ptr
never
parents:
1972
diff
changeset
|
208 } |
3905
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
209 if (EnableInvokeDynamic && |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
210 (klass()->is_subclass_of(env->MethodHandle_klass()) || |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
211 klass()->is_subclass_of(env->CallSite_klass()))) { |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
212 assert(ScavengeRootsInCode >= 1, "must be"); |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
213 // We want to treat these aggressively. |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
214 return true; |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
215 } |
c26de9aef2ed
7071307: MethodHandle bimorphic inlining should consider the frequency
never
parents:
3402
diff
changeset
|
216 |
3402
28a9fe9534ea
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
3283
diff
changeset
|
217 return handle() == NULL || is_perm(); |
0 | 218 } |
219 | |
220 | |
221 // ------------------------------------------------------------------ | |
222 // ciObject::print | |
223 // | |
224 // Print debugging output about this ciObject. | |
225 // | |
226 // Implementation note: dispatch to the virtual print_impl behavior | |
227 // for this ciObject. | |
228 void ciObject::print(outputStream* st) { | |
229 st->print("<%s", type_string()); | |
230 GUARDED_VM_ENTRY(print_impl(st);) | |
989 | 231 st->print(" ident=%d %s%s address=0x%x>", ident(), |
0 | 232 is_perm() ? "PERM" : "", |
989 | 233 is_scavengable() ? "SCAVENGABLE" : "", |
0 | 234 (address)this); |
235 } | |
236 | |
237 // ------------------------------------------------------------------ | |
238 // ciObject::print_oop | |
239 // | |
240 // Print debugging output about the oop this ciObject represents. | |
241 void ciObject::print_oop(outputStream* st) { | |
242 if (is_null_object()) { | |
243 st->print_cr("NULL"); | |
244 } else if (!is_loaded()) { | |
245 st->print_cr("UNLOADED"); | |
246 } else { | |
247 GUARDED_VM_ENTRY(get_oop()->print_on(st);) | |
248 } | |
249 } |