comparison src/share/vm/oops/constMethodKlass.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 0af8b0718fc9
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2003-2006 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/_constMethodKlass.cpp.incl"
27
28
29 klassOop constMethodKlass::create_klass(TRAPS) {
30 constMethodKlass o;
31 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
32 KlassHandle k = base_create_klass(h_this_klass, header_size(),
33 o.vtbl_value(), CHECK_NULL);
34 // Make sure size calculation is right
35 assert(k()->size() == align_object_size(header_size()),
36 "wrong size for object");
37 //java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
38 return k();
39 }
40
41
42 int constMethodKlass::oop_size(oop obj) const {
43 assert(obj->is_constMethod(), "must be constMethod oop");
44 return constMethodOop(obj)->object_size();
45 }
46
47 bool constMethodKlass::oop_is_parsable(oop obj) const {
48 assert(obj->is_constMethod(), "must be constMethod oop");
49 return constMethodOop(obj)->object_is_parsable();
50 }
51
52 constMethodOop constMethodKlass::allocate(int byte_code_size,
53 int compressed_line_number_size,
54 int localvariable_table_length,
55 int checked_exceptions_length,
56 TRAPS) {
57
58 int size = constMethodOopDesc::object_size(byte_code_size,
59 compressed_line_number_size,
60 localvariable_table_length,
61 checked_exceptions_length);
62 KlassHandle h_k(THREAD, as_klassOop());
63 constMethodOop cm = (constMethodOop)
64 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
65 assert(!cm->is_parsable(), "Not yet safely parsable");
66 No_Safepoint_Verifier no_safepoint;
67 cm->set_interpreter_kind(Interpreter::invalid);
68 cm->init_fingerprint();
69 cm->set_method(NULL);
70 cm->set_stackmap_data(NULL);
71 cm->set_exception_table(NULL);
72 cm->set_code_size(byte_code_size);
73 cm->set_constMethod_size(size);
74 cm->set_inlined_tables_length(checked_exceptions_length,
75 compressed_line_number_size,
76 localvariable_table_length);
77 assert(cm->size() == size, "wrong size for object");
78 cm->set_partially_loaded();
79 assert(cm->is_parsable(), "Is safely parsable by gc");
80 return cm;
81 }
82
83 void constMethodKlass::oop_follow_contents(oop obj) {
84 assert (obj->is_constMethod(), "object must be constMethod");
85 constMethodOop cm = constMethodOop(obj);
86 MarkSweep::mark_and_push(cm->adr_method());
87 MarkSweep::mark_and_push(cm->adr_stackmap_data());
88 MarkSweep::mark_and_push(cm->adr_exception_table());
89 // Performance tweak: We skip iterating over the klass pointer since we
90 // know that Universe::constMethodKlassObj never moves.
91 }
92
93 #ifndef SERIALGC
94 void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
95 oop obj) {
96 assert (obj->is_constMethod(), "object must be constMethod");
97 constMethodOop cm_oop = constMethodOop(obj);
98 PSParallelCompact::mark_and_push(cm, cm_oop->adr_method());
99 PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
100 PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table());
101 // Performance tweak: We skip iterating over the klass pointer since we
102 // know that Universe::constMethodKlassObj never moves.
103 }
104 #endif // SERIALGC
105
106 int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
107 assert (obj->is_constMethod(), "object must be constMethod");
108 constMethodOop cm = constMethodOop(obj);
109 blk->do_oop(cm->adr_method());
110 blk->do_oop(cm->adr_stackmap_data());
111 blk->do_oop(cm->adr_exception_table());
112 // Get size before changing pointers.
113 // Don't call size() or oop_size() since that is a virtual call.
114 int size = cm->object_size();
115 return size;
116 }
117
118
119 int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
120 assert (obj->is_constMethod(), "object must be constMethod");
121 constMethodOop cm = constMethodOop(obj);
122 oop* adr;
123 adr = cm->adr_method();
124 if (mr.contains(adr)) blk->do_oop(adr);
125 adr = cm->adr_stackmap_data();
126 if (mr.contains(adr)) blk->do_oop(adr);
127 adr = cm->adr_exception_table();
128 if (mr.contains(adr)) blk->do_oop(adr);
129 // Get size before changing pointers.
130 // Don't call size() or oop_size() since that is a virtual call.
131 int size = cm->object_size();
132 // Performance tweak: We skip iterating over the klass pointer since we
133 // know that Universe::constMethodKlassObj never moves.
134 return size;
135 }
136
137
138 int constMethodKlass::oop_adjust_pointers(oop obj) {
139 assert(obj->is_constMethod(), "should be constMethod");
140 constMethodOop cm = constMethodOop(obj);
141 MarkSweep::adjust_pointer(cm->adr_method());
142 MarkSweep::adjust_pointer(cm->adr_stackmap_data());
143 MarkSweep::adjust_pointer(cm->adr_exception_table());
144 // Get size before changing pointers.
145 // Don't call size() or oop_size() since that is a virtual call.
146 int size = cm->object_size();
147 // Performance tweak: We skip iterating over the klass pointer since we
148 // know that Universe::constMethodKlassObj never moves.
149 return size;
150 }
151
152 #ifndef SERIALGC
153 void constMethodKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
154 assert(obj->is_constMethod(), "should be constMethod");
155 }
156
157 void constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
158 assert(obj->is_constMethod(), "should be constMethod");
159 }
160
161 int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
162 assert(obj->is_constMethod(), "should be constMethod");
163 constMethodOop cm_oop = constMethodOop(obj);
164 #if 0
165 PSParallelCompact::adjust_pointer(cm_oop->adr_method());
166 PSParallelCompact::adjust_pointer(cm_oop->adr_exception_table());
167 PSParallelCompact::adjust_pointer(cm_oop->adr_stackmap_data());
168 #endif
169 oop* const beg_oop = cm_oop->oop_block_beg();
170 oop* const end_oop = cm_oop->oop_block_end();
171 for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
172 PSParallelCompact::adjust_pointer(cur_oop);
173 }
174 return cm_oop->object_size();
175 }
176
177 int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
178 HeapWord* beg_addr,
179 HeapWord* end_addr) {
180 assert(obj->is_constMethod(), "should be constMethod");
181 constMethodOop cm_oop = constMethodOop(obj);
182
183 oop* const beg_oop = MAX2((oop*)beg_addr, cm_oop->oop_block_beg());
184 oop* const end_oop = MIN2((oop*)end_addr, cm_oop->oop_block_end());
185 for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
186 PSParallelCompact::adjust_pointer(cur_oop);
187 }
188
189 return cm_oop->object_size();
190 }
191 #endif // SERIALGC
192
193 #ifndef PRODUCT
194
195 // Printing
196
197 void constMethodKlass::oop_print_on(oop obj, outputStream* st) {
198 ResourceMark rm;
199 assert(obj->is_constMethod(), "must be constMethod");
200 Klass::oop_print_on(obj, st);
201 constMethodOop m = constMethodOop(obj);
202 st->print(" - method: " INTPTR_FORMAT " ", (address)m->method());
203 m->method()->print_value_on(st); st->cr();
204 st->print(" - exceptions: " INTPTR_FORMAT "\n", (address)m->exception_table());
205 if (m->has_stackmap_table()) {
206 st->print(" - stackmap data: ");
207 m->stackmap_data()->print_value_on(st);
208 st->cr();
209 }
210 }
211
212
213 // Short version of printing constMethodOop - just print the name of the
214 // method it belongs to.
215 void constMethodKlass::oop_print_value_on(oop obj, outputStream* st) {
216 assert(obj->is_constMethod(), "must be constMethod");
217 constMethodOop m = constMethodOop(obj);
218 st->print(" const part of method " );
219 m->method()->print_value_on(st);
220 }
221
222 #endif // PRODUCT
223
224 const char* constMethodKlass::internal_name() const {
225 return "{constMethod}";
226 }
227
228
229 // Verification
230
231 void constMethodKlass::oop_verify_on(oop obj, outputStream* st) {
232 Klass::oop_verify_on(obj, st);
233 guarantee(obj->is_constMethod(), "object must be constMethod");
234 constMethodOop m = constMethodOop(obj);
235 guarantee(m->is_perm(), "should be in permspace");
236
237 // Verification can occur during oop construction before the method or
238 // other fields have been initialized.
239 if (!obj->partially_loaded()) {
240 guarantee(m->method()->is_perm(), "should be in permspace");
241 guarantee(m->method()->is_method(), "should be method");
242 typeArrayOop stackmap_data = m->stackmap_data();
243 guarantee(stackmap_data == NULL ||
244 stackmap_data->is_perm(), "should be in permspace");
245 guarantee(m->exception_table()->is_perm(), "should be in permspace");
246 guarantee(m->exception_table()->is_typeArray(), "should be type array");
247
248 address m_end = (address)((oop*) m + m->size());
249 address compressed_table_start = m->code_end();
250 guarantee(compressed_table_start <= m_end, "invalid method layout");
251 address compressed_table_end = compressed_table_start;
252 // Verify line number table
253 if (m->has_linenumber_table()) {
254 CompressedLineNumberReadStream stream(m->compressed_linenumber_table());
255 while (stream.read_pair()) {
256 guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table");
257 }
258 compressed_table_end += stream.position();
259 }
260 guarantee(compressed_table_end <= m_end, "invalid method layout");
261 // Verify checked exceptions and local variable tables
262 if (m->has_checked_exceptions()) {
263 u2* addr = m->checked_exceptions_length_addr();
264 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
265 }
266 if (m->has_localvariable_table()) {
267 u2* addr = m->localvariable_table_length_addr();
268 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
269 }
270 // Check compressed_table_end relative to uncompressed_table_start
271 u2* uncompressed_table_start;
272 if (m->has_localvariable_table()) {
273 uncompressed_table_start = (u2*) m->localvariable_table_start();
274 } else {
275 if (m->has_checked_exceptions()) {
276 uncompressed_table_start = (u2*) m->checked_exceptions_start();
277 } else {
278 uncompressed_table_start = (u2*) m_end;
279 }
280 }
281 int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
282 int max_gap = align_object_size(1)*BytesPerWord;
283 guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
284 }
285 }
286
287 bool constMethodKlass::oop_partially_loaded(oop obj) const {
288 assert(obj->is_constMethod(), "object must be klass");
289 constMethodOop m = constMethodOop(obj);
290 // check whether exception_table points to self (flag for partially loaded)
291 return m->exception_table() == (typeArrayOop)obj;
292 }
293
294
295 // The exception_table is the last field set when loading an object.
296 void constMethodKlass::oop_set_partially_loaded(oop obj) {
297 assert(obj->is_constMethod(), "object must be klass");
298 constMethodOop m = constMethodOop(obj);
299 // Temporarily set exception_table to point to self
300 m->set_exception_table((typeArrayOop)obj);
301 }