objArrayOop.hpp

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 // objArrays are arrays containing oops
00025 
00026 // memory layout:
00027 //    [header      ]
00028 //    [klass_field ]
00029 //    [instVars    ]*
00030 //    [length      ]
00031 //    [elements    ]* = objs(1) .. objs(length)
00032 
00033 class objArrayOopDesc: public memOopDesc {
00034  public:
00035   // constructor
00036   friend objArrayOop as_objArrayOop(void* p) {
00037     return objArrayOop(as_memOop(p)); }
00038 
00039   void bootstrap_object(bootstrap* st);
00040 
00041   // accessors
00042   objArrayOopDesc* addr() const {
00043     return (objArrayOopDesc*) memOopDesc::addr(); }
00044 
00045   bool is_within_bounds(int index) const { return 1 <= index && index <= length(); }
00046 
00047   oop* addr_as_oops() const { return (oop*) addr(); }
00048  
00049   oop* objs(int which) const {
00050     return &length_addr()[which];
00051   }
00052 
00053   oop* length_addr() const  {
00054     return &addr_as_oops()[blueprint()->non_indexable_size()];
00055   }
00056 
00057   smi length() const {
00058     oop len = *length_addr();
00059     assert(len->is_smi(), "length of indexable should be smi");
00060     return smiOop(len)->value();
00061   }
00062 
00063   void set_length(smi len) {
00064     *length_addr() = as_smiOop(len);
00065   }
00066   
00067   oop obj_at(int which) const {
00068     assert(which > 0 && which <= length(), "index out of bounds");
00069     return *objs(which);
00070   }
00071 
00072   void obj_at_put(int which, oop contents, bool cs = true) {
00073     assert(which > 0 && which <= length(), "index out of bounds");
00074     assert(!is_symbol(), "shouldn't be modifying a canonical string");
00075     assert(contents->verify(), "check contents");
00076     if (cs) {
00077       STORE_OOP(objs(which), contents);
00078     } else {
00079       *objs(which) = contents;
00080     }
00081   }
00082 
00083   objArrayOop growBy(int increment);
00084   
00085   // memory operations
00086   bool verify();
00087 
00088   objArrayOop copy_remove(int from, int number = 1);
00089 
00090   objArrayOop copy();
00091   objArrayOop copy_add(oop a);
00092   objArrayOop copy_add_two(oop a, oop b);
00093 
00094   // primtiive operations
00095   void replace_from_to(int from, int to, objArrayOop source, int start);
00096   void replace_and_fill(int from, int start, objArrayOop source);
00097 
00098   friend objArrayKlass;
00099  private:
00100   // define the interval [begin .. end[ where the indexables are.
00101   oop* begin_indexables() const { return objs(1); }
00102   oop* end_indexables()   const { return begin_indexables() + length(); }
00103 };
00104 
00105 
00106 class weakArrayOopDesc: public objArrayOopDesc {
00107  public:
00108   friend weakArrayOop as_weakArrayOop(void* p) {
00109     return weakArrayOop(as_memOop(p)); }
00110 
00111   // accessors
00112   weakArrayOopDesc* addr() const {
00113     return (weakArrayOopDesc*) memOopDesc::addr(); }
00114 
00115   void scavenge_contents_after_registration();
00116   void follow_contents_after_registration();
00117 };

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