00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.14 $ */ 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 00025 // remembered set for GC, implemented as a card marking byte array with one byte / card 00026 // Card size is 512 bytes 00027 // NB: Card size must be >= 512 because of the offset_array in oldspace 00028 00029 const int card_shift = 9; // wired in to scavenge_contents 00030 const int card_size = 1 << card_shift; 00031 const int card_size_in_oops = card_size / oopSize; 00032 00033 class rSet: public CHeapObj { 00034 friend class oldSpace; 00035 friend class oldGeneration; 00036 friend class SetOopClosure; 00037 00038 private: 00039 char* low_boundary; // duplicate of old_gen var so byte_for can be inlined 00040 char* high_boundary; 00041 char byte_map[1]; // size is a lie 00042 00043 // friend void oldSpace::switch_pointers_by_card(oop, oop); 00044 char* byte_for(void *p) const { return (char*)&byte_map[int((char*)p - low_boundary) >> card_shift]; } 00045 oop* oop_for(char* p) const { return (oop*)(low_boundary + ((p - byte_map) << card_shift)); } 00046 00047 friend oop* card_for(oop* p) { return (oop*)(int(p) & ~(card_size - 1)); } 00048 00049 inline char* byte_map_end() const; 00050 00051 public: 00052 int byte_map_size() const { return (high_boundary - low_boundary) / card_size; } 00053 rSet(); 00054 void* operator new(size_t size); 00055 00056 inline void clear(); 00057 char* byte_map_base() const { return byte_for(NULL); } 00058 void record_store(void* p) { *byte_for(p) = 0; } 00059 bool is_dirty(void* p) const { return *byte_for(p) == 0; } 00060 00061 // Tells is any card for obj is dirty 00062 bool is_object_dirty(memOop obj); 00063 00064 void scavenge_contents(oldSpace* s); 00065 char* scavenge_contents(oldSpace* s, char* begin, char* limit); 00066 bool verify(bool postScavenge); 00067 00068 void print_set_for_space(oldSpace* sp); 00069 void print_set_for_object(memOop obj); 00070 00071 // Returns the number of dirty pages in an old segment 00072 int number_of_dirty_pages_in(oldSpace* sp); 00073 00074 // Return the number of pages with dirty objects. 00075 int number_of_pages_with_dirty_objects_in(oldSpace* sp); 00076 00077 // Operations used during garbage collection 00078 void set_size(memOop obj, int size); 00079 int get_size(memOop obj); 00080 00081 private: 00082 void fixup(char *start, char *end); 00083 void clear(char *start, char *end); 00084 rSet(rSet *old, char *start, char *end); 00085 bool has_page_dirty_objects(oldSpace* sp, char* page); 00086 };