objArrayKlass.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.35 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_objArrayKlass.cpp.incl"
00026 
00027 oop objArrayKlass::allocateObjectSize(int size) {
00028   klassOop k        = as_klassOop();
00029   int      ni_size  = non_indexable_size();
00030   int      obj_size = ni_size + 1 + size;
00031   // allocate
00032   objArrayOop obj = as_objArrayOop(Universe::allocate(obj_size, (memOop*)&k));
00033   // header
00034   memOop(obj)->initialize_header(has_untagged_contents(), k);
00035   // instance variables
00036   memOop(obj)->initialize_body(memOopDesc::header_size(), ni_size);
00037   // indexables
00038   oop* base = (oop*) obj->addr();
00039   oop* end  = base + obj_size;
00040   // %optimized 'obj->set_length(size)'
00041   base[ni_size] = as_smiOop(size);
00042   memOop(obj)->initialize_body(ni_size+1, obj_size);
00043   return obj;
00044 }
00045 
00046 klassOop objArrayKlass::create_subclass(mixinOop mixin, Format format) {
00047   if (format == weakArray_klass) return weakArrayKlass::create_class(as_klassOop(), mixin);
00048   if (format == mem_klass || format == objArray_klass) {
00049     return objArrayKlass::create_class(as_klassOop(), mixin);
00050   }
00051   return NULL;
00052 }
00053 
00054 klassOop objArrayKlass::create_class(klassOop super_class, mixinOop mixin) {
00055   objArrayKlass o;
00056   return create_generic_class(super_class, mixin, o.vtbl_value());
00057 }
00058 
00059 objArrayOop objArrayKlass::allocate_tenured_pic(int size) {
00060   klassOop k        = Universe::objArrayKlassObj();
00061   int      ni_size  = k->klass_part()->non_indexable_size();
00062   int      obj_size = ni_size + 1 + size;
00063   // allocate
00064   objArrayOop obj = as_objArrayOop(Universe::allocate_tenured(obj_size));
00065   // header
00066   memOop(obj)->initialize_header(k->klass_part()->has_untagged_contents(), k);
00067   // instance variables
00068   memOop(obj)->initialize_body(memOopDesc::header_size(), ni_size);
00069     // indexables
00070   oop* base = (oop*) obj->addr();
00071   oop* end  = base + obj_size;
00072   // %optimized 'obj->set_length(size)'
00073   base[ni_size] = as_smiOop(size);
00074   memOop(obj)->initialize_body(ni_size+1, obj_size);
00075   return obj;
00076 }
00077 
00078 void set_objArrayKlass_vtbl(Klass* k) {
00079   objArrayKlass o;
00080   k->set_vtbl_value(o.vtbl_value());
00081 }
00082 
00083 void objArrayKlass::oop_layout_iterate(oop obj, ObjectLayoutClosure* blk) {
00084   // Retrieve length information in case the iterator mutates the object
00085   oop* p   = objArrayOop(obj)->objs(0);
00086   int  len = objArrayOop(obj)->length();
00087   // header + instance variables
00088   memOopKlass::oop_layout_iterate(obj, blk);
00089   // indexables
00090   blk->do_oop("length", p++);
00091   blk->begin_indexables();
00092   for (int index = 1; index <= len; index++) {
00093     blk->do_indexable_oop(index, p++);
00094   }
00095   blk->end_indexables();
00096 }
00097 
00098 void objArrayKlass::oop_short_print_on(oop obj, outputStream* st) {
00099   const int MaxPrintLen = 255;  // to prevent excessive output -Urs
00100   assert_objArray(obj,"Argument must be objArray");
00101   objArrayOop array = objArrayOop(obj);
00102   int len = array->length();
00103   int n   = min(MaxElementPrintSize, len);
00104   st->print("'");
00105   for(int index = 1; index <= n && st->position() < MaxPrintLen; index++) {
00106     array->obj_at(index)->print_value_on(st);
00107     st->print(", ");
00108   }
00109   if (n < len) st->print("... ");
00110   else         st->print("' ");
00111   oop_print_value_on(obj, st);
00112 }
00113 
00114 void objArrayKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
00115   // Retrieve length information in case the iterator mutates the object
00116   oop* p   = objArrayOop(obj)->objs(0);
00117   int  len = objArrayOop(obj)->length();
00118   // header + instance variables
00119   memOopKlass::oop_oop_iterate(obj, blk);
00120   // indexables
00121   blk->do_oop(p++);
00122   for (int index = 1; index <= len; index++) {
00123     blk->do_oop(p++);
00124   }
00125 }
00126 
00127 int objArrayKlass::oop_scavenge_contents(oop obj) {
00128   // header + instance variables
00129   memOopKlass::oop_scavenge_contents(obj);
00130   // indexables
00131   objArrayOop o = objArrayOop(obj);
00132   oop* base = o->objs(1);
00133   oop* end  = base + o->length();
00134   while (base < end) { scavenge_oop(base++); }
00135   return object_size(o->length());  
00136 }
00137 
00138 int objArrayKlass::oop_scavenge_tenured_contents(oop obj) {
00139   // header + instance variables
00140   memOopKlass::oop_scavenge_tenured_contents(obj);
00141   // indexables
00142   objArrayOop o = objArrayOop(obj);
00143   oop* base = o->objs(1);
00144   oop* end  = base + o->length();
00145   while (base < end) scavenge_tenured_oop(base++);
00146   return object_size(o->length());  
00147 }
00148 
00149 void objArrayKlass::oop_follow_contents(oop obj) {
00150   // Retrieve length information since header information  mutates the object
00151   oop* base = objArrayOop(obj)->objs(1);
00152   oop* end  = base + objArrayOop(obj)->length();
00153 
00154   // header + instance variables
00155   memOopKlass::oop_follow_contents(obj);
00156   // indexables
00157   while (base < end) MarkSweep::reverse_and_push(base++);
00158 }

Generated on Mon Oct 9 13:37:19 2006 for Strongtalk VM by  doxygen 1.4.7