00001 /* Copyright 1994, LongView Technologies L.L.C. $Revision: 1.13 $ */ 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 #ifdef DELTA_COMPILER 00025 00026 // The code table is used to find nmethods in the zone. 00027 // It is a hash table, where each bucket contains a list of nmethods. 00028 00029 //%note 00030 // Should implement free list like symbolTable (Lars 2/10-95) 00031 00032 const int codeTableSize = 2048; 00033 const int debugTableSize = 256; 00034 00035 struct codeTableEntry; 00036 00037 struct codeTableLink : public CHeapObj { 00038 // instance variable 00039 nmethod* nm; 00040 codeTableLink* next; 00041 00042 // memory operations 00043 bool verify(int i); 00044 }; 00045 00046 struct codeTableEntry : ValueObj { 00047 // methods are tagged, links are not. 00048 void* nmethod_or_link; 00049 bool is_empty() { return nmethod_or_link == NULL; } 00050 bool is_nmethod() { return (int) nmethod_or_link & 1; } 00051 void clear() { nmethod_or_link = NULL; } 00052 00053 nmethod* get_nmethod() { 00054 return (nmethod*) ((int) nmethod_or_link - 1); 00055 } 00056 void set_nmethod(nmethod* nm) { 00057 assert_oop_aligned(nm); 00058 nmethod_or_link = (void*) ((int) nm + 1); } 00059 00060 codeTableLink* get_link() { return (codeTableLink*) nmethod_or_link; } 00061 void set_link(codeTableLink* l) { 00062 assert_oop_aligned(l); 00063 nmethod_or_link = (void*) l; 00064 } 00065 00066 // memory operations 00067 void deallocate(); 00068 00069 int length(); // returns the number of nmethod in this bucket. 00070 00071 bool verify(int i); 00072 }; 00073 00074 class codeTable : public PrintableCHeapObj{ 00075 protected: 00076 int tableSize; 00077 codeTableEntry* buckets; 00078 00079 codeTableEntry* at(int index) { return &buckets[index]; } 00080 codeTableEntry* bucketFor(int hash) { return at(hash & (tableSize - 1)); } 00081 codeTableLink* new_link(nmethod* nm, codeTableLink* n = NULL); 00082 00083 public: 00084 codeTable(int size); 00085 void clear(); 00086 nmethod* lookup(LookupKey* L); 00087 bool verify(); 00088 00089 void print(); 00090 00091 void print_stats(); 00092 00093 // Tells whether a nmethod is present 00094 bool is_present(nmethod* nm); 00095 00096 // Removes a nmethod from the table 00097 void remove(nmethod* nm); 00098 00099 protected: 00100 // should always add through zone->addToCodeTable() 00101 void add(nmethod* nm); 00102 void addIfAbsent(nmethod* nm); // add only if not there yet 00103 00104 friend class zone; 00105 }; 00106 00107 #endif