made a copy
[strongtalk-kjk.git] / vm / oops / objArrayOop.hpp
blob4dba9f7f5a821029d656c2f41233ea0f97c94eaf
1 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.18 $ */
2 /* Copyright (c) 2006, Sun Microsystems, Inc.
3 All rights reserved.
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 // objArrays are arrays containing oops
26 // memory layout:
27 // [header ]
28 // [klass_field ]
29 // [instVars ]*
30 // [length ]
31 // [elements ]* = objs(1) .. objs(length)
33 class objArrayOopDesc: public memOopDesc {
34 public:
35 // constructor
36 friend objArrayOop as_objArrayOop(void* p) {
37 return objArrayOop(as_memOop(p)); }
39 void bootstrap_object(bootstrap* st);
41 // accessors
42 objArrayOopDesc* addr() const {
43 return (objArrayOopDesc*) memOopDesc::addr(); }
45 bool is_within_bounds(int index) const { return 1 <= index && index <= length(); }
47 oop* addr_as_oops() const { return (oop*) addr(); }
49 oop* objs(int which) const {
50 return &length_addr()[which];
53 oop* length_addr() const {
54 return &addr_as_oops()[blueprint()->non_indexable_size()];
57 smi length() const {
58 oop len = *length_addr();
59 assert(len->is_smi(), "length of indexable should be smi");
60 return smiOop(len)->value();
63 void set_length(smi len) {
64 *length_addr() = as_smiOop(len);
67 oop obj_at(int which) const {
68 assert(which > 0 && which <= length(), "index out of bounds");
69 return *objs(which);
72 void obj_at_put(int which, oop contents, bool cs = true) {
73 assert(which > 0 && which <= length(), "index out of bounds");
74 assert(!is_symbol(), "shouldn't be modifying a canonical string");
75 assert(contents->verify(), "check contents");
76 if (cs) {
77 STORE_OOP(objs(which), contents);
78 } else {
79 *objs(which) = contents;
83 objArrayOop growBy(int increment);
85 // memory operations
86 bool verify();
88 objArrayOop copy_remove(int from, int number = 1);
90 objArrayOop copy();
91 objArrayOop copy_add(oop a);
92 objArrayOop copy_add_two(oop a, oop b);
94 // primtiive operations
95 void replace_from_to(int from, int to, objArrayOop source, int start);
96 void replace_and_fill(int from, int start, objArrayOop source);
98 friend objArrayKlass;
99 private:
100 // define the interval [begin .. end[ where the indexables are.
101 oop* begin_indexables() const { return objs(1); }
102 oop* end_indexables() const { return begin_indexables() + length(); }
106 class weakArrayOopDesc: public objArrayOopDesc {
107 public:
108 friend weakArrayOop as_weakArrayOop(void* p) {
109 return weakArrayOop(as_memOop(p)); }
111 // accessors
112 weakArrayOopDesc* addr() const {
113 return (weakArrayOopDesc*) memOopDesc::addr(); }
115 void scavenge_contents_after_registration();
116 void follow_contents_after_registration();