1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)constantPoolKlass.cpp 1.105 07/05/29 09:44:18 JVM"
3 #endif
4 /*
5 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
26 */
27
28 # include "incls/_precompiled.incl"
29 # include "incls/_constantPoolKlass.cpp.incl"
30
31 constantPoolOop constantPoolKlass::allocate(int length, TRAPS) {
32 int size = constantPoolOopDesc::object_size(length);
33 KlassHandle klass (THREAD, as_klassOop());
34 constantPoolOop c =
35 (constantPoolOop)CollectedHeap::permanent_array_allocate(klass, size, length, CHECK_NULL);
36
37 c->set_tags(NULL);
38 c->set_cache(NULL);
39 c->set_pool_holder(NULL);
40 // only set to non-zero if constant pool is merged by RedefineClasses
41 c->set_orig_length(0);
42 // all fields are initialized; needed for GC
43
44 // initialize tag array
45 // Note: cannot introduce constant pool handle before since it is not
46 // completely initialized (no class) -> would cause assertion failure
47 constantPoolHandle pool (THREAD, c);
48 typeArrayOop t_oop = oopFactory::new_permanent_byteArray(length, CHECK_NULL);
49 typeArrayHandle tags (THREAD, t_oop);
50 for (int index = 0; index < length; index++) {
51 tags()->byte_at_put(index, JVM_CONSTANT_Invalid);
52 }
53 pool->set_tags(tags());
54
55 return pool();
56 }
57
58 klassOop constantPoolKlass::create_klass(TRAPS) {
59 constantPoolKlass o;
60 KlassHandle klassklass(THREAD, Universe::arrayKlassKlassObj());
61 arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL);
62 arrayKlassHandle super (THREAD, k->super());
63 complete_create_array_klass(k, super, CHECK_NULL);
64 return k();
65 }
66
67
68 int constantPoolKlass::oop_size(oop obj) const {
69 assert(obj->is_constantPool(), "must be constantPool");
70 return constantPoolOop(obj)->object_size();
71 }
72
73
74 void constantPoolKlass::oop_follow_contents(oop obj) {
75 assert (obj->is_constantPool(), "obj must be constant pool");
76 constantPoolOop cp = (constantPoolOop) obj;
77 // Performance tweak: We skip iterating over the klass pointer since we
78 // know that Universe::constantPoolKlassObj never moves.
79
80 // If the tags array is null we are in the middle of allocating this constant pool
81 if (cp->tags() != NULL) {
82 // gc of constant pool contents
83 oop* base = (oop*)cp->base();
84 for (int i = 0; i < cp->length(); i++) {
85 if (cp->is_pointer_entry(i)) {
86 if (*base != NULL) MarkSweep::mark_and_push(base);
87 }
246 for (size_t cur_idx = beg_idx; cur_idx < end_idx; ++cur_idx, ++base) {
247 if (cp->is_pointer_entry(int(cur_idx))) {
248 PSParallelCompact::adjust_pointer(base);
249 }
250 }
251 }
252
253 oop* p;
254 p = cp->tags_addr();
255 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
256 p = cp->cache_addr();
257 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
258 p = cp->pool_holder_addr();
259 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
260
261 return cp->object_size();
262 }
263
264 void constantPoolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
265 assert(obj->is_constantPool(), "should be constant pool");
266 }
267
268 void constantPoolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
269 assert(obj->is_constantPool(), "should be constant pool");
270 }
271 #endif // SERIALGC
272
273 #ifndef PRODUCT
274
275 // Printing
276
277 void constantPoolKlass::oop_print_on(oop obj, outputStream* st) {
278 EXCEPTION_MARK;
279 oop anObj;
280 assert(obj->is_constantPool(), "must be constantPool");
281 arrayKlass::oop_print_on(obj, st);
282 constantPoolOop cp = constantPoolOop(obj);
283
284 // Temp. remove cache so we can do lookups with original indicies.
285 constantPoolCacheHandle cache (THREAD, cp->cache());
286 cp->set_cache(NULL);
287
288 for (int index = 1; index < cp->length(); index++) { // Index 0 is unused
289 st->print(" - %3d : ", index);
290 cp->tag_at(index).print_on(st);
291 st->print(" : ");
292 switch (cp->tag_at(index).value()) {
293 case JVM_CONSTANT_Class :
294 { anObj = cp->klass_at(index, CATCH);
295 anObj->print_value_on(st);
296 st->print(" {0x%lx}", (address)anObj);
297 }
298 break;
299 case JVM_CONSTANT_Fieldref :
300 case JVM_CONSTANT_Methodref :
301 case JVM_CONSTANT_InterfaceMethodref :
302 st->print("klass_index=%d", cp->klass_ref_index_at(index));
303 st->print(" name_and_type_index=%d", cp->name_and_type_ref_index_at(index));
304 break;
305 case JVM_CONSTANT_UnresolvedString :
306 case JVM_CONSTANT_String :
307 anObj = cp->string_at(index, CATCH);
308 anObj->print_value_on(st);
309 st->print(" {0x%lx}", (address)anObj);
310 break;
311 case JVM_CONSTANT_Integer :
312 st->print("%d", cp->int_at(index));
313 break;
314 case JVM_CONSTANT_Float :
315 st->print("%f", cp->float_at(index));
316 break;
317 case JVM_CONSTANT_Long :
318 st->print_jlong(cp->long_at(index));
319 index++; // Skip entry following eigth-byte constant
320 break;
321 case JVM_CONSTANT_Double :
322 st->print("%lf", cp->double_at(index));
323 index++; // Skip entry following eigth-byte constant
324 break;
325 case JVM_CONSTANT_NameAndType :
326 st->print("name_index=%d", cp->name_ref_index_at(index));
327 st->print(" signature_index=%d", cp->signature_ref_index_at(index));
367 for (int i = 0; i< cp->length(); i++) {
368 if (cp->tag_at(i).is_klass()) {
369 guarantee((*base)->is_perm(), "should be in permspace");
370 guarantee((*base)->is_klass(), "should be klass");
371 }
372 if (cp->tag_at(i).is_unresolved_klass()) {
373 guarantee((*base)->is_perm(), "should be in permspace");
374 guarantee((*base)->is_symbol() || (*base)->is_klass(),
375 "should be symbol or klass");
376 }
377 if (cp->tag_at(i).is_symbol()) {
378 guarantee((*base)->is_perm(), "should be in permspace");
379 guarantee((*base)->is_symbol(), "should be symbol");
380 }
381 if (cp->tag_at(i).is_unresolved_string()) {
382 guarantee((*base)->is_perm(), "should be in permspace");
383 guarantee((*base)->is_symbol() || (*base)->is_instance(),
384 "should be symbol or instance");
385 }
386 if (cp->tag_at(i).is_string()) {
387 guarantee((*base)->is_perm(), "should be in permspace");
388 guarantee((*base)->is_instance(), "should be instance");
389 }
390 base++;
391 }
392 guarantee(cp->tags()->is_perm(), "should be in permspace");
393 guarantee(cp->tags()->is_typeArray(), "should be type array");
394 if (cp->cache() != NULL) {
395 // Note: cache() can be NULL before a class is completely setup or
396 // in temporary constant pools used during constant pool merging
397 guarantee(cp->cache()->is_perm(), "should be in permspace");
398 guarantee(cp->cache()->is_constantPoolCache(), "should be constant pool cache");
399 }
400 if (cp->pool_holder() != NULL) {
401 // Note: pool_holder() can be NULL in temporary constant pools
402 // used during constant pool merging
403 guarantee(cp->pool_holder()->is_perm(), "should be in permspace");
404 guarantee(cp->pool_holder()->is_klass(), "should be klass");
405 }
406 }
407 }
408
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)constantPoolKlass.cpp 1.105 07/05/29 09:44:18 JVM"
3 #endif
4 /*
5 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
26 */
27
28 # include "incls/_precompiled.incl"
29 # include "incls/_constantPoolKlass.cpp.incl"
30
31 constantPoolOop constantPoolKlass::allocate(int length, TRAPS) {
32 int size = constantPoolOopDesc::object_size(length);
33 KlassHandle klass (THREAD, as_klassOop());
34 constantPoolOop c =
35 (constantPoolOop)CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL);
36
37 c->set_length(length);
38 c->set_tags(NULL);
39 c->set_cache(NULL);
40 c->set_pool_holder(NULL);
41 c->set_flags(0);
42 // only set to non-zero if constant pool is merged by RedefineClasses
43 c->set_orig_length(0);
44 // all fields are initialized; needed for GC
45
46 // initialize tag array
47 // Note: cannot introduce constant pool handle before since it is not
48 // completely initialized (no class) -> would cause assertion failure
49 constantPoolHandle pool (THREAD, c);
50 typeArrayOop t_oop = oopFactory::new_permanent_byteArray(length, CHECK_NULL);
51 typeArrayHandle tags (THREAD, t_oop);
52 for (int index = 0; index < length; index++) {
53 tags()->byte_at_put(index, JVM_CONSTANT_Invalid);
54 }
55 pool->set_tags(tags());
56
57 return pool();
58 }
59
60 klassOop constantPoolKlass::create_klass(TRAPS) {
61 constantPoolKlass o;
62 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
63 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
64 // Make sure size calculation is right
65 assert(k()->size() == align_object_size(header_size()), "wrong size for object");
66 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
67 return k();
68 }
69
70 int constantPoolKlass::oop_size(oop obj) const {
71 assert(obj->is_constantPool(), "must be constantPool");
72 return constantPoolOop(obj)->object_size();
73 }
74
75
76 void constantPoolKlass::oop_follow_contents(oop obj) {
77 assert (obj->is_constantPool(), "obj must be constant pool");
78 constantPoolOop cp = (constantPoolOop) obj;
79 // Performance tweak: We skip iterating over the klass pointer since we
80 // know that Universe::constantPoolKlassObj never moves.
81
82 // If the tags array is null we are in the middle of allocating this constant pool
83 if (cp->tags() != NULL) {
84 // gc of constant pool contents
85 oop* base = (oop*)cp->base();
86 for (int i = 0; i < cp->length(); i++) {
87 if (cp->is_pointer_entry(i)) {
88 if (*base != NULL) MarkSweep::mark_and_push(base);
89 }
248 for (size_t cur_idx = beg_idx; cur_idx < end_idx; ++cur_idx, ++base) {
249 if (cp->is_pointer_entry(int(cur_idx))) {
250 PSParallelCompact::adjust_pointer(base);
251 }
252 }
253 }
254
255 oop* p;
256 p = cp->tags_addr();
257 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
258 p = cp->cache_addr();
259 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
260 p = cp->pool_holder_addr();
261 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
262
263 return cp->object_size();
264 }
265
266 void constantPoolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
267 assert(obj->is_constantPool(), "should be constant pool");
268 constantPoolOop cp = (constantPoolOop) obj;
269 if (AnonymousClasses && cp->has_pseudo_string() && cp->tags() != NULL) {
270 oop* base = (oop*)cp->base();
271 for (int i = 0; i < cp->length(); ++i, ++base) {
272 if (cp->tag_at(i).is_string()) {
273 if (PSScavenge::should_scavenge(base)) {
274 pm->claim_or_forward_breadth(base);
275 }
276 }
277 }
278 }
279 }
280
281 void constantPoolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
282 assert(obj->is_constantPool(), "should be constant pool");
283 constantPoolOop cp = (constantPoolOop) obj;
284 if (AnonymousClasses && cp->has_pseudo_string() && cp->tags() != NULL) {
285 oop* base = (oop*)cp->base();
286 for (int i = 0; i < cp->length(); ++i, ++base) {
287 if (cp->tag_at(i).is_string()) {
288 if (PSScavenge::should_scavenge(base)) {
289 pm->claim_or_forward_depth(base);
290 }
291 }
292 }
293 }
294 }
295 #endif // SERIALGC
296
297 #ifndef PRODUCT
298
299 // Printing
300
301 void constantPoolKlass::oop_print_on(oop obj, outputStream* st) {
302 EXCEPTION_MARK;
303 oop anObj;
304 assert(obj->is_constantPool(), "must be constantPool");
305 Klass::oop_print_on(obj, st);
306 constantPoolOop cp = constantPoolOop(obj);
307 if (cp->flags() != 0) {
308 st->print(" - flags : 0x%x", cp->flags());
309 if (cp->has_pseudo_string()) st->print(" has_pseudo_string");
310 st->cr();
311 }
312
313 // Temp. remove cache so we can do lookups with original indicies.
314 constantPoolCacheHandle cache (THREAD, cp->cache());
315 cp->set_cache(NULL);
316
317 for (int index = 1; index < cp->length(); index++) { // Index 0 is unused
318 st->print(" - %3d : ", index);
319 cp->tag_at(index).print_on(st);
320 st->print(" : ");
321 switch (cp->tag_at(index).value()) {
322 case JVM_CONSTANT_Class :
323 { anObj = cp->klass_at(index, CATCH);
324 anObj->print_value_on(st);
325 st->print(" {0x%lx}", (address)anObj);
326 }
327 break;
328 case JVM_CONSTANT_Fieldref :
329 case JVM_CONSTANT_Methodref :
330 case JVM_CONSTANT_InterfaceMethodref :
331 st->print("klass_index=%d", cp->klass_ref_index_at(index));
332 st->print(" name_and_type_index=%d", cp->name_and_type_ref_index_at(index));
333 break;
334 case JVM_CONSTANT_UnresolvedString :
335 case JVM_CONSTANT_String :
336 if (cp->is_pseudo_string_at(index)) {
337 anObj = cp->pseudo_string_at(index);
338 } else {
339 anObj = cp->string_at(index, CATCH);
340 }
341 anObj->print_value_on(st);
342 st->print(" {0x%lx}", (address)anObj);
343 break;
344 case JVM_CONSTANT_Integer :
345 st->print("%d", cp->int_at(index));
346 break;
347 case JVM_CONSTANT_Float :
348 st->print("%f", cp->float_at(index));
349 break;
350 case JVM_CONSTANT_Long :
351 st->print_jlong(cp->long_at(index));
352 index++; // Skip entry following eigth-byte constant
353 break;
354 case JVM_CONSTANT_Double :
355 st->print("%lf", cp->double_at(index));
356 index++; // Skip entry following eigth-byte constant
357 break;
358 case JVM_CONSTANT_NameAndType :
359 st->print("name_index=%d", cp->name_ref_index_at(index));
360 st->print(" signature_index=%d", cp->signature_ref_index_at(index));
400 for (int i = 0; i< cp->length(); i++) {
401 if (cp->tag_at(i).is_klass()) {
402 guarantee((*base)->is_perm(), "should be in permspace");
403 guarantee((*base)->is_klass(), "should be klass");
404 }
405 if (cp->tag_at(i).is_unresolved_klass()) {
406 guarantee((*base)->is_perm(), "should be in permspace");
407 guarantee((*base)->is_symbol() || (*base)->is_klass(),
408 "should be symbol or klass");
409 }
410 if (cp->tag_at(i).is_symbol()) {
411 guarantee((*base)->is_perm(), "should be in permspace");
412 guarantee((*base)->is_symbol(), "should be symbol");
413 }
414 if (cp->tag_at(i).is_unresolved_string()) {
415 guarantee((*base)->is_perm(), "should be in permspace");
416 guarantee((*base)->is_symbol() || (*base)->is_instance(),
417 "should be symbol or instance");
418 }
419 if (cp->tag_at(i).is_string()) {
420 if (!cp->has_pseudo_string()) {
421 guarantee((*base)->is_perm(), "should be in permspace");
422 guarantee((*base)->is_instance(), "should be instance");
423 } else {
424 // can be non-perm, can be non-instance (array)
425 }
426 }
427 base++;
428 }
429 guarantee(cp->tags()->is_perm(), "should be in permspace");
430 guarantee(cp->tags()->is_typeArray(), "should be type array");
431 if (cp->cache() != NULL) {
432 // Note: cache() can be NULL before a class is completely setup or
433 // in temporary constant pools used during constant pool merging
434 guarantee(cp->cache()->is_perm(), "should be in permspace");
435 guarantee(cp->cache()->is_constantPoolCache(), "should be constant pool cache");
436 }
437 if (cp->pool_holder() != NULL) {
438 // Note: pool_holder() can be NULL in temporary constant pools
439 // used during constant pool merging
440 guarantee(cp->pool_holder()->is_perm(), "should be in permspace");
441 guarantee(cp->pool_holder()->is_klass(), "should be klass");
442 }
443 }
444 }
445
|