objArrayOop.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.18 $ */
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/_objArrayOop.cpp.incl"
00026 
00027 bool objArrayOopDesc::verify() {
00028   bool flag = memOopDesc::verify();
00029   if (flag) {
00030     int l = length();
00031     if (l < 0) {
00032       error("objArrayOop %#lx has negative length", this);
00033       flag = false;
00034     }
00035   }
00036   return flag;
00037 }
00038 
00039 void objArrayOopDesc::bootstrap_object(bootstrap* st) {
00040   memOopDesc::bootstrap_object(st);
00041   st->read_oop(length_addr());
00042   for (int index = 1; index <= length(); index++)
00043     st->read_oop(objs(index));
00044 }
00045 
00046 objArrayOop objArrayOopDesc::copy_remove(int index, int number) {
00047   objArrayOop new_array = oopFactory::new_objArray(length() - number);
00048   // copy [1..index-1]
00049   for (int i = 1; i < index ; i++)
00050     new_array->obj_at_put(i, obj_at(i));
00051 
00052   // copy  [index+number..length]
00053   for (i = index; i <= length() - number; i++)
00054     new_array->obj_at_put(i, obj_at(i+number));
00055 
00056   return new_array;
00057 }
00058 
00059 objArrayOop objArrayOopDesc::copy() {
00060   objArrayOop new_array = oopFactory::new_objArray(length());
00061   for (int i = 1; i <= length(); i++)
00062     new_array->obj_at_put(i, obj_at(i));
00063   return new_array;
00064 }
00065 
00066 objArrayOop objArrayOopDesc::copy_add(oop a) {
00067   objArrayOop new_array = oopFactory::new_objArray(length() + 1);
00068   for (int i = 1; i <= length(); i++)
00069     new_array->obj_at_put(i, obj_at(i));
00070   new_array->obj_at_put(i, a);
00071   return new_array;
00072 }
00073 
00074 objArrayOop objArrayOopDesc::copy_add_two(oop a, oop b) {
00075   objArrayOop new_array = oopFactory::new_objArray(length() + 2);
00076   for (int i = 1; i < length(); i++)
00077     new_array->obj_at_put(i, obj_at(i));
00078   new_array->obj_at_put(i++, a);
00079   new_array->obj_at_put(i,   b);
00080   return new_array;
00081 }
00082 
00083 // Old Smalltalk code:
00084 //  replaceFrom: start <Int> to: stop <Int> with: other <SeqCltn[E]> startingAt: repStart <Int>
00085 //      "replace the elements of the receiver from start to stop with elements from other,
00086 //        starting with the element of other with index repStart."
00087 //
00088 //      | otheri <Int> |
00089 //      repStart < start
00090 //              ifFalse: [ otheri := repStart.
00091 //                                start to: stop do:
00092 //                                      [ :i <Int> |
00093 //                                              self at: i put: (other at: otheri).
00094 //                                              otheri := otheri + 1.   ]]
00095 //              ifTrue: [ otheri := repStart + (stop - start).
00096 //                              stop to: start by: -1 do:
00097 //                                      [ :i <Int> |
00098 //                                              self at: i put: (other at: otheri).
00099 //                                              otheri := otheri - 1.   ]]
00100 
00101 void objArrayOopDesc::replace_from_to(int from, int to, objArrayOop source, int start) {
00102   int other_index = start;
00103   if (start < to) {
00104     // copy up
00105     for (int index = from; index <= to; index++) {
00106       source->obj_at_put(other_index++, obj_at(index));
00107     }
00108   } else {
00109     // copy down
00110     for (int index = to; index >= from; index--) {
00111       source->obj_at_put(other_index--, obj_at(index));
00112     }
00113   }
00114 }
00115 
00116 void objArrayOopDesc::replace_and_fill(int from, int start, objArrayOop source) {
00117   // Fill the first part
00118   for (int index = 1; index < from; index++) {
00119     obj_at_put(index, nilObj);
00120   }
00121 
00122   // Fill the middle part
00123   int to = min(source->length() - start + 1, length());
00124 
00125   for (index = from; index <= to; index++) {
00126     obj_at_put(index, source->obj_at(start + index - from));
00127   }
00128 
00129   // Fill the last part
00130   for (index = to + 1; index <= length(); index++) {
00131     obj_at_put(index, nilObj);
00132   }
00133 }
00134 
00135 void weakArrayOopDesc::scavenge_contents_after_registration() {
00136   oop* p   = objs(1);
00137   int  len = length();
00138   for (int index = 1; index <= len; index++)
00139     scavenge_tenured_oop(p++);
00140 }
00141 
00142 void weakArrayOopDesc::follow_contents_after_registration() {
00143   oop* p   = objs(1);
00144   int  len = length();
00145   for (int index = 1; index <= len; index++)
00146     scavenge_tenured_oop(p++);
00147 }

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