00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.17 $ */ 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 // The following classes are C++ `closures` for iterating over 00025 // Objects, Roots, and Frames. 00026 00027 // A Closure is used for iterating over data structures; use it instead 00028 // of function pointers. 00029 template <class T> class Closure : StackObj { 00030 public: 00031 virtual void do_it(T t) = 0; 00032 }; 00033 00034 00035 // ObjectClosure is used for iterating through object space 00036 // (see universe::object_iterate). 00037 class ObjectClosure : StackObj { 00038 public: 00039 // Called when entering a space. 00040 virtual void begin_space(space* s) {} 00041 // Called when exiting a space. 00042 virtual void end_space(space* s) {} 00043 // Called for each object. 00044 virtual void do_object(memOop obj) {} 00045 }; 00046 00047 // ObjectFilterClosure is an ObjectClosure with filtering. 00048 class ObjectFilterClosure : public ObjectClosure { 00049 void do_object(memOop obj); 00050 public: 00051 // Called for each object and returns whether 00052 // do_filteres_objects should be called. 00053 virtual bool include_object(memOop obj) { return true; } 00054 // Called for each object where include_object returns true. 00055 virtual void do_filtered_object(memOop obj) {} 00056 }; 00057 00058 // ObjectLayoutClosure is a closure for iterating through the 00059 // layout of a memOop (see memOop::layout_iterate). 00060 class ObjectLayoutClosure : StackObj { 00061 public: 00062 // NON INDEXABLE PART 00063 // Called for the markOop 00064 virtual void do_mark(markOop *m) {} 00065 // Called for each oop 00066 virtual void do_oop(char* title, oop* o) {} 00067 // Called for each byte 00068 virtual void do_byte(char* title, u_char* b) {} 00069 // Called for each long 00070 virtual void do_long(char* title, void** p) {} 00071 // Called for each double 00072 virtual void do_double(char* title, double* d) {} 00073 00074 // INDEXABLE PART 00075 // Called before iterating through the indexable part. 00076 // ONLY called if the object has an indexable part. 00077 virtual void begin_indexables() {} 00078 // Called after iterating through the indexable part. 00079 // ONLY called if the object has an indexable part. 00080 virtual void end_indexables() {} 00081 // Called for each indexable oop 00082 virtual void do_indexable_oop(int index, oop* o) {} 00083 // Called for each indexable byte 00084 virtual void do_indexable_byte(int index, u_char* b) {} 00085 // Called for each indexable double byte 00086 virtual void do_indexable_doubleByte(int index, doubleByte* b) {} 00087 // Called for each indexable long 00088 virtual void do_indexable_long(int index, long* l) {} 00089 }; 00090 00091 // A FrameClosure is used for iterating though frames 00092 class FrameClosure : StackObj { 00093 public: 00094 // Called before iterating through a process. 00095 virtual void begin_process(Process* p) {} 00096 // Called after iterating through a process. 00097 virtual void end_process(Process* p) {} 00098 // Called for each frame 00099 virtual void do_frame(frame* f) {} 00100 }; 00101 00102 // A FrameLayoutClosure is used for iterating though the layout of frame 00103 class FrameLayoutClosure : StackObj { 00104 public: 00105 // Called for each oop 00106 virtual void do_stack(int index, oop* o) {} 00107 // Called for the hcode pointer 00108 virtual void do_hp(u_char** hp) {} 00109 // Called for the receiver 00110 virtual void do_receiver(oop* o) {} 00111 // Called for the link 00112 virtual void do_link(int** fp) {} 00113 // Called for the return address 00114 virtual void do_return_addr(char** pc) {} 00115 }; 00116 00117 // A ProcessClosure is used for iterating over Delta processes 00118 class ProcessClosure : StackObj { 00119 public: 00120 // Called for each process 00121 virtual void do_process(DeltaProcess* p) {} 00122 }; 00123 00124 // A OopClosure is used for iterating through oops 00125 // (see memOop::oop_iterate, universe::root_iterate). 00126 class OopClosure : StackObj { 00127 public: 00128 // Called for each oop 00129 virtual void do_oop(oop* o) {} 00130 }; 00131 00132 // A klassOopClosure is used for iterating through klassOops 00133 // (see memOop::oop_iterate, universe::root_iterate). 00134 class klassOopClosure : StackObj { 00135 public: 00136 // Called for each oop 00137 virtual void do_klass(klassOop klass) {} 00138 }; 00139