00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.7 $ */ 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 // mixin objects holds the description of a class 00025 // All classes are results of mixin invocations. 00026 00027 // memory layout: 00028 // [header ] 00029 // [klass_field ]- (Class) 00030 // [methods ]- (Array[Method]) 00031 // [instVarDict ]- (Array[Symbol]) 00032 // [class variables ]- (Array[Symbol]) 00033 // [primary invocation]- (Class) 00034 // [class mixin ]- (Mixin) 00035 // [instance variables]* 00036 00037 class mixinOopDesc: public memOopDesc { 00038 private: 00039 objArrayOop _methods; 00040 objArrayOop _inst_vars; // Description of instance variables 00041 objArrayOop _class_vars; // Description of class variables 00042 klassOop _primary_invocation; // Points to the primary invocation 00043 mixinOop _class_mixin; // Mixin for the class part 00044 oop _installed; // Tells whether the mixin has been installed 00045 00046 protected: 00047 mixinOopDesc* addr() const { return (mixinOopDesc*)memOopDesc::addr(); } 00048 00049 public: 00050 friend mixinOop as_mixinOop(void* p) { return mixinOop(as_memOop(p)); } 00051 00052 // sizing 00053 static int header_size() { return sizeof(mixinOopDesc)/oopSize; } 00054 00055 // accessors 00056 objArrayOop methods() const { return addr()->_methods; } 00057 void set_methods(objArrayOop m) { STORE_OOP(&addr()->_methods, m); } 00058 00059 objArrayOop instVars() const { return addr()->_inst_vars; } 00060 void set_instVars(objArrayOop i) { STORE_OOP(&addr()->_inst_vars, i); } 00061 00062 objArrayOop classVars() const { return addr()->_class_vars; } 00063 void set_classVars(objArrayOop c) { STORE_OOP(&addr()->_class_vars, c); } 00064 00065 klassOop primary_invocation() const { return addr()->_primary_invocation; } 00066 void set_primary_invocation(klassOop k) { STORE_OOP(&addr()->_primary_invocation, k); } 00067 00068 mixinOop class_mixin() const { return addr()->_class_mixin; } 00069 void set_class_mixin(mixinOop m) { STORE_OOP(&addr()->_class_mixin, m); } 00070 00071 oop installed() const { return addr()->_installed; } 00072 void set_installed(oop b) { STORE_OOP(&addr()->_installed, b); } 00073 00074 // primitive operations 00075 int number_of_methods() const; // Return the number of methods. 00076 methodOop method_at(int index) const; // Return the method at index. 00077 void add_method(methodOop method); // Add/overwrite method. 00078 methodOop remove_method_at(int index); // Remove and return the method at index. 00079 bool includes_method(methodOop method); // Remove and return the class variable at index. 00080 00081 int number_of_instVars() const; // Return the number of instance variables. 00082 symbolOop instVar_at(int index) const; // Return the instance variable at index. 00083 void add_instVar(symbolOop name); // Add instance variable. 00084 symbolOop remove_instVar_at(int index); // Remove and return the instance variable at index. 00085 bool includes_instVar(symbolOop name); // Tells whether the name is present as an instance variable name. 00086 00087 int number_of_classVars() const; // Return the number of class variables. 00088 symbolOop classVar_at(int index) const; // Return the class variable at index. 00089 void add_classVar(symbolOop name); // Add class variable. 00090 symbolOop remove_classVar_at(int index); // Remove and return the class variable at index. 00091 bool includes_classVar(symbolOop name); // Tells whether the name is present 00092 00093 // Returns the offset of an instance variable. 00094 // -1 is returned if inst var is not present in mixin. 00095 int inst_var_offset(symbolOop name, int non_indexable_size) const; 00096 00097 // Reflective operation 00098 void apply_mixin(mixinOop m); 00099 00100 void customize_for(klassOop klass); 00101 void uncustomize_methods(); 00102 00103 // Tells whether the mixin has been installed 00104 bool is_installed() const; 00105 00106 // Tells whether the mixin has been installed 00107 bool has_primary_invocation() const; 00108 00109 // bootstrapping 00110 void bootstrap_object(bootstrap* st); 00111 00112 friend mixinKlass; 00113 };