|
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; |
|
51 if (ciObjectFactory::is_initialized()) { |
|
52 _handle = JNIHandles::make_local(o); |
|
53 } else { |
|
54 _handle = JNIHandles::make_global(o); |
|
55 } |
|
56 _klass = NULL; |
|
57 _ident = 0; |
|
58 } |
|
59 |
|
60 // ------------------------------------------------------------------ |
|
61 // ciObject::ciObject |
|
62 // |
|
63 ciObject::ciObject(Handle h) { |
|
64 ASSERT_IN_VM; |
|
65 if (ciObjectFactory::is_initialized()) { |
|
66 _handle = JNIHandles::make_local(h()); |
|
67 } else { |
|
68 _handle = JNIHandles::make_global(h); |
|
69 } |
|
70 _klass = NULL; |
|
71 _ident = 0; |
|
72 } |
|
73 |
|
74 // ------------------------------------------------------------------ |
|
75 // ciObject::ciObject |
|
76 // |
|
77 // Unloaded klass/method variant. `klass' is the klass of the unloaded |
|
78 // klass/method, if that makes sense. |
|
79 ciObject::ciObject(ciKlass* klass) { |
|
80 ASSERT_IN_VM; |
|
81 assert(klass != NULL, "must supply klass"); |
|
82 _handle = NULL; |
|
83 _klass = klass; |
|
84 _ident = 0; |
|
85 } |
|
86 |
|
87 // ------------------------------------------------------------------ |
|
88 // ciObject::ciObject |
|
89 // |
|
90 // NULL variant. Used only by ciNullObject. |
|
91 ciObject::ciObject() { |
|
92 ASSERT_IN_VM; |
|
93 _handle = NULL; |
|
94 _klass = NULL; |
|
95 _ident = 0; |
|
96 } |
|
97 |
|
98 // ------------------------------------------------------------------ |
|
99 // ciObject::klass |
|
100 // |
|
101 // Get the ciKlass of this ciObject. |
|
102 ciKlass* ciObject::klass() { |
|
103 if (_klass == NULL) { |
|
104 if (_handle == NULL) { |
|
105 // When both _klass and _handle are NULL, we are dealing |
|
106 // with the distinguished instance of ciNullObject. |
|
107 // No one should ask it for its klass. |
|
108 assert(is_null_object(), "must be null object"); |
|
109 ShouldNotReachHere(); |
|
110 return NULL; |
|
111 } |
|
112 |
|
113 GUARDED_VM_ENTRY( |
|
114 oop o = get_oop(); |
|
115 _klass = CURRENT_ENV->get_object(o->klass())->as_klass(); |
|
116 ); |
|
117 } |
|
118 return _klass; |
|
119 } |
|
120 |
|
121 // ------------------------------------------------------------------ |
|
122 // ciObject::set_ident |
|
123 // |
|
124 // Set the unique identity number of a ciObject. |
|
125 void ciObject::set_ident(uint id) { |
|
126 assert((_ident >> FLAG_BITS) == 0, "must only initialize once"); |
|
127 assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big"); |
|
128 _ident = _ident + (id << FLAG_BITS); |
|
129 } |
|
130 |
|
131 // ------------------------------------------------------------------ |
|
132 // ciObject::ident |
|
133 // |
|
134 // Report the unique identity number of a ciObject. |
|
135 uint ciObject::ident() { |
|
136 uint id = _ident >> FLAG_BITS; |
|
137 assert(id != 0, "must be initialized"); |
|
138 return id; |
|
139 } |
|
140 |
|
141 // ------------------------------------------------------------------ |
|
142 // ciObject::equals |
|
143 // |
|
144 // Are two ciObjects equal? |
|
145 bool ciObject::equals(ciObject* obj) { |
|
146 return (this == obj); |
|
147 } |
|
148 |
|
149 // ------------------------------------------------------------------ |
|
150 // ciObject::hash |
|
151 // |
|
152 // A hash value for the convenience of compilers. |
|
153 // |
|
154 // Implementation note: we use the address of the ciObject as the |
|
155 // basis for the hash. Use the _ident field, which is well-behaved. |
|
156 int ciObject::hash() { |
|
157 return ident() * 31; |
|
158 } |
|
159 |
|
160 // ------------------------------------------------------------------ |
|
161 // ciObject::encoding |
|
162 // |
|
163 // The address which the compiler should embed into the |
|
164 // generated code to represent this oop. This address |
|
165 // is not the true address of the oop -- it will get patched |
|
166 // during nmethod creation. |
|
167 // |
|
168 // |
|
169 // |
|
170 // Implementation note: we use the handle as the encoding. The |
|
171 // nmethod constructor resolves the handle and patches in the oop. |
|
172 // |
|
173 // This method should be changed to return an generified address |
|
174 // to discourage use of the JNI handle. |
|
175 jobject ciObject::encoding() { |
|
176 assert(is_null_object() || handle() != NULL, "cannot embed null pointer"); |
|
177 assert(has_encoding(), "oop must be NULL or perm"); |
|
178 return handle(); |
|
179 } |
|
180 |
|
181 // ------------------------------------------------------------------ |
|
182 // ciObject::has_encoding |
|
183 bool ciObject::has_encoding() { |
|
184 return handle() == NULL || is_perm(); |
|
185 } |
|
186 |
|
187 |
|
188 // ------------------------------------------------------------------ |
|
189 // ciObject::print |
|
190 // |
|
191 // Print debugging output about this ciObject. |
|
192 // |
|
193 // Implementation note: dispatch to the virtual print_impl behavior |
|
194 // for this ciObject. |
|
195 void ciObject::print(outputStream* st) { |
|
196 st->print("<%s", type_string()); |
|
197 GUARDED_VM_ENTRY(print_impl(st);) |
|
198 st->print(" ident=%d %s address=0x%x>", ident(), |
|
199 is_perm() ? "PERM" : "", |
|
200 (address)this); |
|
201 } |
|
202 |
|
203 // ------------------------------------------------------------------ |
|
204 // ciObject::print_oop |
|
205 // |
|
206 // Print debugging output about the oop this ciObject represents. |
|
207 void ciObject::print_oop(outputStream* st) { |
|
208 if (is_null_object()) { |
|
209 st->print_cr("NULL"); |
|
210 } else if (!is_loaded()) { |
|
211 st->print_cr("UNLOADED"); |
|
212 } else { |
|
213 GUARDED_VM_ENTRY(get_oop()->print_on(st);) |
|
214 } |
|
215 } |