key.hpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.19 $ */
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 // LookupKeys are the keys into the code table.  
00025 // There should be at most one compiled method for a given LookupKey.
00026 // A LookupKey can take two forms:
00027 // 1) normal send lookup key (is_normal_type() == true).
00028 //    {receiver klass, selector}
00029 // 2) super  send lookup key (is_super_type()  == true).
00030 //    {receiver klass, method}
00031 // 2) fake lookup key for block methods
00032 //    {receiver klass, block method}
00033 
00034 // LookupKeys are allocated in different ways:
00035 //   as embedded objects: the lookupCache has LookupKeys as part of an array element.
00036 //   as dynamically allocated resource objects: used by the optimizing compiler.
00037 //      Use "LookupKey::allocate" for allocating a LookupKey in the resource area.
00038 
00039 class LookupKey : ValueObj {
00040  protected:
00041   klassOop  _klass;
00042   oop       _selector_or_method;
00043  public:
00044   LookupKey() {
00045     clear();
00046   }
00047   LookupKey(klassOop klass, oop selector_or_method) {
00048     _klass              = klass;
00049     _selector_or_method = selector_or_method;
00050   }
00051   LookupKey(LookupKey* key) {
00052     _klass              = key->klass();
00053     _selector_or_method = key->selector_or_method();
00054   }
00055 
00056   klassOop klass() const              { return _klass; }
00057   oop      selector_or_method() const { return _selector_or_method; }
00058 
00059   symbolOop selector() const;
00060 
00061   methodOop method() const {
00062      assert(selector_or_method()->is_method(), "Wrong lookup type");
00063      return methodOop(selector_or_method());
00064   }
00065 
00066   // Lookup type
00067   bool is_super_type()  const { return selector_or_method()->is_method() && !methodOop(selector_or_method())->is_blockMethod();}
00068   bool is_normal_type() const { return !selector_or_method()->is_method(); }
00069   bool is_block_type()  const { return selector_or_method()->is_method() && methodOop(selector_or_method())->is_blockMethod(); }
00070 
00071   bool equal(LookupKey* p) const {
00072     return klass()              == p->klass() &&
00073            selector_or_method() == p->selector_or_method();
00074   }
00075 
00076   void initialize(klassOop klass, oop selector_or_method) {
00077     _klass              = klass;
00078     _selector_or_method = selector_or_method;
00079   }
00080 
00081   void clear() {
00082     _klass              = NULL;
00083     _selector_or_method = NULL;
00084   }
00085 
00086   int hash() const;
00087   
00088   void switch_pointers(oop from, oop to);
00089   void relocate();
00090   bool verify() const;
00091   void oops_do(void f(oop*));
00092   
00093   // Printing support output format is:
00094   //   "class::selector" for normal sends and
00095   //   "class^^selector" for super sends.
00096   //   "class->selector {bci}+" for block keys
00097   void  print() const;
00098   char* print_string() const;
00099   void  print_on(outputStream* st) const;
00100   void  print_inlining_database_on(outputStream* st) const;
00101 
00102   // For resource allocation.
00103   static LookupKey* allocate(klassOop klass, oop selector_or_method);
00104 };
00105 

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