lookupCache.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.38 $ */
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 lookup cache is a 2-way associative cache mapping LookupKeys into LookupResult.
00025 // Called when the inline cache fails or when a compile takes place.
00026 
00027 // %gc-note
00028 // When a garbage collect occurs the lookup cache has to be 
00029 // recomputed since the has value is dependent on the location
00030 // of symbols and klasses.
00031 
00032 class LookupResult: ValueObj {
00033  protected:
00034   oop _result; // methodOop or jumpTableEntry
00035 
00036  public:
00037   // Constructors
00038   LookupResult()                 { clear();     }
00039   LookupResult(methodOop method) { set(method); }
00040   LookupResult(nmethod*  nm)     { set(nm);     }
00041 
00042   // Clears the result
00043   void clear() { _result = NULL; }
00044 
00045   // Test operations
00046   bool is_empty()  const { return _result == NULL;   }
00047   bool is_method() const { return _result->is_mem(); }
00048   bool is_entry()  const { return !is_method();      }
00049 
00050 
00051   // Maching operations
00052   bool matches(methodOop m) const; // Checks whether the result is methodOop m.
00053   bool matches(nmethod* nm) const; // Checks whether the result is nmethod nm.
00054 
00055   // Fetch operations
00056   oop             value()       const { return _result; }
00057   methodOop       method()      const;
00058   methodOop       method_or_null() const;
00059   jumpTableEntry* entry()       const;
00060   nmethod*        get_nmethod() const;
00061   
00062   // Set operations
00063   void set(methodOop method) {
00064     assert(method->is_method(), "must be method");
00065     _result = oop(method);
00066   }
00067 
00068   void set(nmethod* nm) {
00069     assert(oop(nm)->is_smi(), "nmethod must be aligned");
00070     _result = oop(nm->jump_table_entry()->entry_point());
00071   }
00072 
00073   void print_on(outputStream* st) const;
00074   void print_short_on(outputStream* st) const;
00075 };
00076 
00077 
00078 const unsigned int primary_cache_size   = 16 * K;
00079 const unsigned int secondary_cache_size =  2 * K;
00080 
00081 class lookupCache : AllStatic {
00082  private:
00083   static int primary_cache_address();
00084   static int secondary_cache_address();
00085 
00086   static unsigned int hash_value(LookupKey* key);
00087   static int number_of_primary_hits;
00088   static int number_of_secondary_hits;
00089   static int number_of_misses;
00090 
00091   static inline LookupResult ic_lookup(klassOop receiver_klass, oop selector_or_method);
00092 
00093   static LookupResult lookup(LookupKey* key, bool compile);
00094   static LookupResult cache_miss_lookup(LookupKey* key, bool compile);
00095   static nmethod* compile_method(LookupKey* key, methodOop method);
00096 
00097  public:
00098   // Lookup probe into the lookup cache
00099   static LookupResult lookup_probe(LookupKey* key);
00100 
00101   // Lookup support for inline cache (returns methodOop or jump_table_entry).
00102   static LookupResult ic_normal_lookup(klassOop receiver_klass, symbolOop selector);
00103   static LookupResult ic_super_lookup(klassOop receiver_klass, klassOop sending_method_holder, symbolOop selector);
00104 
00105   // Lookup support for interpreter  (returns methodOop or jump_table_entry).
00106   friend LookupResult interpreter_normal_lookup(klassOop receiver_klass, symbolOop selector);
00107   friend LookupResult interpreter_super_lookup(symbolOop selector);
00108 
00109   // Lookup support for compiler
00110   static methodOop method_lookup(klassOop receiver_klass, symbolOop selector);
00111   static methodOop compile_time_normal_lookup(klassOop receiver_klass, symbolOop selector);     // returns NULL if not found
00112   static methodOop compile_time_super_lookup (klassOop receiver_klass, symbolOop selector);     // returns NULL if not found
00113 
00114   // Lookup support for LookupKey
00115   static LookupResult lookup(LookupKey* key);
00116 
00117   // Lookup support for megamorphic sends (no super sends)
00118   static oop normal_lookup(klassOop receiver_klass, symbolOop selector);                        // returns {methodOop or jump table entry}
00119 
00120   // Flushing
00121   static void flush(LookupKey* key);
00122   static void flush();
00123 
00124   // Clear all entries in the cache.
00125   static void verify();
00126 
00127   static void clear_statistics();
00128   static void print_statistics();
00129 
00130   friend class InterpreterGenerator;
00131   friend class StubRoutines;
00132   friend class debugPrimitives;
00133 };

Generated on Mon Oct 9 13:37:13 2006 for Strongtalk VM by  doxygen 1.4.7