00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.7 $ */ 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 class weakArrayKlass: public objArrayKlass { 00025 public: 00026 friend void set_weakArrayKlass_vtbl(Klass* k); 00027 00028 char* name() const { return "weakArray"; } 00029 00030 // creates invocation 00031 klassOop create_subclass(mixinOop mixin, Format format); 00032 00033 static klassOop create_class(klassOop super_class, mixinOop mixin); 00034 00035 // Format 00036 Format format() { return weakArray_klass; } 00037 00038 // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP 00039 00040 // memory operations 00041 int oop_scavenge_contents(oop obj); 00042 int oop_scavenge_tenured_contents(oop obj); 00043 void oop_follow_contents(oop obj); 00044 00045 // testers 00046 bool oop_is_weakArray() const { return true; } 00047 00048 // iterators 00049 void oop_oop_iterate(oop obj, OopClosure* blk); 00050 void oop_layout_iterate(oop obj, ObjectLayoutClosure* blk); 00051 00052 // Sizing 00053 int oop_header_size() const { return weakArrayOopDesc::header_size(); } 00054 }; 00055 00056 // The weak array register is used during memory management to 00057 // split the object scanning into two parts: 00058 // 1. Transively traverse all object except the indexable part 00059 // of weakArrays. Then a weakArray is encountered it is registered 00060 // 2. Using the registered weakArrays continue the transitive traverse. 00061 // Inbetween we can easily compute the set of object with a 00062 // near death experience. 00063 // 00064 // Scavenge and Mark Sweep use to disjunct parts of the interface. 00065 00066 // Implementation note: 00067 // During phase1 of Mark Sweep pointers are reversed and a objects 00068 // structure cannot be used (the klass pointer is gone). This makes 00069 // it necessary to register weakArrays along with their non indexable sizes. 00070 // 'nis' contains the non indexable sizes. 00071 00072 // Interface for weak array support 00073 class WeakArrayRegister : AllStatic { 00074 public: 00075 // Scavenge interface 00076 static void begin_scavenge(); 00077 static bool scavenge_register(weakArrayOop obj); 00078 static void check_and_scavenge_contents(); 00079 00080 // Mark sweep interface 00081 static void begin_mark_sweep(); 00082 static bool mark_sweep_register(weakArrayOop obj, int non_indexable_size); 00083 static void check_and_follow_contents(); 00084 00085 private: 00086 // Variables 00087 static bool during_registration; 00088 static GrowableArray<weakArrayOop>* weakArrays; 00089 static GrowableArray<int>* nis; 00090 00091 // Scavenge operations 00092 static void scavenge_contents(); 00093 static inline bool scavenge_is_near_death(oop obj); 00094 static void scavenge_check_for_dying_objects(); 00095 00096 // Mark sweep operations 00097 static void follow_contents(); 00098 static inline bool mark_sweep_is_near_death(oop obj); 00099 static void mark_sweep_check_for_dying_objects(); 00100 }; 00101 00102 // The NotificationQueue holds references to weakArrays 00103 // containing object with a near death experience. 00104 class NotificationQueue : AllStatic { 00105 public: 00106 // Queue operations 00107 static void mark_elements(); // Marks all elements as queued (by using the sentinel bit) 00108 static void clear_elements(); // Reset the sentinel bit 00109 00110 static bool is_empty(); 00111 static oop get(); 00112 static void put(oop obj); 00113 static void put_if_absent(oop obj); 00114 00115 // Memory management 00116 static void oops_do(void f(oop*)); 00117 private: 00118 static oop* array; 00119 static int size; 00120 static int first; 00121 static int last; 00122 static int succ(int index); 00123 };