1 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.35 $ */
2 /* Copyright (c) 2006, Sun Microsystems, Inc.
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided with the distribution.
11 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived
12 from this software without specific prior written permission.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
15 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
16 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
18 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
19 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
24 # include "incls/_precompiled.incl"
25 # include "incls/_objArrayKlass.cpp.incl"
27 oop
objArrayKlass::allocateObjectSize(int size
) {
28 klassOop k
= as_klassOop();
29 int ni_size
= non_indexable_size();
30 int obj_size
= ni_size
+ 1 + size
;
32 objArrayOop obj
= as_objArrayOop(Universe::allocate(obj_size
, (memOop
*)&k
));
34 memOop(obj
)->initialize_header(has_untagged_contents(), k
);
36 memOop(obj
)->initialize_body(memOopDesc::header_size(), ni_size
);
38 oop
* base
= (oop
*) obj
->addr();
39 oop
* end
= base
+ obj_size
;
40 // %optimized 'obj->set_length(size)'
41 base
[ni_size
] = as_smiOop(size
);
42 memOop(obj
)->initialize_body(ni_size
+1, obj_size
);
46 klassOop
objArrayKlass::create_subclass(mixinOop mixin
, Format format
) {
47 if (format
== weakArray_klass
) return weakArrayKlass::create_class(as_klassOop(), mixin
);
48 if (format
== mem_klass
|| format
== objArray_klass
) {
49 return objArrayKlass::create_class(as_klassOop(), mixin
);
54 klassOop
objArrayKlass::create_class(klassOop super_class
, mixinOop mixin
) {
56 return create_generic_class(super_class
, mixin
, o
.vtbl_value());
59 objArrayOop
objArrayKlass::allocate_tenured_pic(int size
) {
60 klassOop k
= Universe::objArrayKlassObj();
61 int ni_size
= k
->klass_part()->non_indexable_size();
62 int obj_size
= ni_size
+ 1 + size
;
64 objArrayOop obj
= as_objArrayOop(Universe::allocate_tenured(obj_size
));
66 memOop(obj
)->initialize_header(k
->klass_part()->has_untagged_contents(), k
);
68 memOop(obj
)->initialize_body(memOopDesc::header_size(), ni_size
);
70 oop
* base
= (oop
*) obj
->addr();
71 oop
* end
= base
+ obj_size
;
72 // %optimized 'obj->set_length(size)'
73 base
[ni_size
] = as_smiOop(size
);
74 memOop(obj
)->initialize_body(ni_size
+1, obj_size
);
78 void set_objArrayKlass_vtbl(Klass
* k
) {
80 k
->set_vtbl_value(o
.vtbl_value());
83 void objArrayKlass::oop_layout_iterate(oop obj
, ObjectLayoutClosure
* blk
) {
84 // Retrieve length information in case the iterator mutates the object
85 oop
* p
= objArrayOop(obj
)->objs(0);
86 int len
= objArrayOop(obj
)->length();
87 // header + instance variables
88 memOopKlass::oop_layout_iterate(obj
, blk
);
90 blk
->do_oop("length", p
++);
91 blk
->begin_indexables();
92 for (int index
= 1; index
<= len
; index
++) {
93 blk
->do_indexable_oop(index
, p
++);
95 blk
->end_indexables();
98 void objArrayKlass::oop_short_print_on(oop obj
, outputStream
* st
) {
99 const int MaxPrintLen
= 255; // to prevent excessive output -Urs
100 assert_objArray(obj
,"Argument must be objArray");
101 objArrayOop array
= objArrayOop(obj
);
102 int len
= array
->length();
103 int n
= min(MaxElementPrintSize
, len
);
105 for(int index
= 1; index
<= n
&& st
->position() < MaxPrintLen
; index
++) {
106 array
->obj_at(index
)->print_value_on(st
);
109 if (n
< len
) st
->print("... ");
110 else st
->print("' ");
111 oop_print_value_on(obj
, st
);
114 void objArrayKlass::oop_oop_iterate(oop obj
, OopClosure
* blk
) {
115 // Retrieve length information in case the iterator mutates the object
116 oop
* p
= objArrayOop(obj
)->objs(0);
117 int len
= objArrayOop(obj
)->length();
118 // header + instance variables
119 memOopKlass::oop_oop_iterate(obj
, blk
);
122 for (int index
= 1; index
<= len
; index
++) {
127 int objArrayKlass::oop_scavenge_contents(oop obj
) {
128 // header + instance variables
129 memOopKlass::oop_scavenge_contents(obj
);
131 objArrayOop o
= objArrayOop(obj
);
132 oop
* base
= o
->objs(1);
133 oop
* end
= base
+ o
->length();
134 while (base
< end
) { scavenge_oop(base
++); }
135 return object_size(o
->length());
138 int objArrayKlass::oop_scavenge_tenured_contents(oop obj
) {
139 // header + instance variables
140 memOopKlass::oop_scavenge_tenured_contents(obj
);
142 objArrayOop o
= objArrayOop(obj
);
143 oop
* base
= o
->objs(1);
144 oop
* end
= base
+ o
->length();
145 while (base
< end
) scavenge_tenured_oop(base
++);
146 return object_size(o
->length());
149 void objArrayKlass::oop_follow_contents(oop obj
) {
150 // Retrieve length information since header information mutates the object
151 oop
* base
= objArrayOop(obj
)->objs(1);
152 oop
* end
= base
+ objArrayOop(obj
)->length();
154 // header + instance variables
155 memOopKlass::oop_follow_contents(obj
);
157 while (base
< end
) MarkSweep::reverse_and_push(base
++);