made a copy
[strongtalk-kjk.git] / vm / code / codeTable.hpp
blobadd4ccc14590a91924de8d5c456f75ddacca2df1
1 /* Copyright 1994, LongView Technologies L.L.C. $Revision: 1.13 $ */
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 #ifdef DELTA_COMPILER
26 // The code table is used to find nmethods in the zone.
27 // It is a hash table, where each bucket contains a list of nmethods.
29 //%note
30 // Should implement free list like symbolTable (Lars 2/10-95)
32 const int codeTableSize = 2048;
33 const int debugTableSize = 256;
35 struct codeTableEntry;
37 struct codeTableLink : public CHeapObj {
38 // instance variable
39 nmethod* nm;
40 codeTableLink* next;
42 // memory operations
43 bool verify(int i);
46 struct codeTableEntry : ValueObj {
47 // methods are tagged, links are not.
48 void* nmethod_or_link;
49 bool is_empty() { return nmethod_or_link == NULL; }
50 bool is_nmethod() { return (int) nmethod_or_link & 1; }
51 void clear() { nmethod_or_link = NULL; }
53 nmethod* get_nmethod() {
54 return (nmethod*) ((int) nmethod_or_link - 1);
56 void set_nmethod(nmethod* nm) {
57 assert_oop_aligned(nm);
58 nmethod_or_link = (void*) ((int) nm + 1); }
60 codeTableLink* get_link() { return (codeTableLink*) nmethod_or_link; }
61 void set_link(codeTableLink* l) {
62 assert_oop_aligned(l);
63 nmethod_or_link = (void*) l;
66 // memory operations
67 void deallocate();
69 int length(); // returns the number of nmethod in this bucket.
71 bool verify(int i);
74 class codeTable : public PrintableCHeapObj{
75 protected:
76 int tableSize;
77 codeTableEntry* buckets;
79 codeTableEntry* at(int index) { return &buckets[index]; }
80 codeTableEntry* bucketFor(int hash) { return at(hash & (tableSize - 1)); }
81 codeTableLink* new_link(nmethod* nm, codeTableLink* n = NULL);
83 public:
84 codeTable(int size);
85 void clear();
86 nmethod* lookup(LookupKey* L);
87 bool verify();
89 void print();
91 void print_stats();
93 // Tells whether a nmethod is present
94 bool is_present(nmethod* nm);
96 // Removes a nmethod from the table
97 void remove(nmethod* nm);
99 protected:
100 // should always add through zone->addToCodeTable()
101 void add(nmethod* nm);
102 void addIfAbsent(nmethod* nm); // add only if not there yet
104 friend class zone;
107 #endif